In my textbook, it says that the formula for finding covariance between two random variables is:
$Cov(X,Y)=E((X-EX)(Y-EY))$
With $EY$ and $EX$ being the mathematical expectation for the random variable Y and X respectively.
How does this formula translate into:
$Cov(X,Y) = \frac{\sum (x-\bar x)(y-\bar y)}{n-1}$
For when we are calculating with real data (sampled data)?
Let's say I want to calculate the covariance between two stock prices in a given month. Of course, I will resort to the 2nd formula to find the covariance. However, the fundamental question I want to ask is, for the first formula we are talking in the context of random variables, we assume that we know the underlying distributions of X and Y (as is with the examples in my textbook). However, in practical applications such as above, when I want to calculate covariance between two stock prices, I don't know the underlying distribution of the two stock prices data that I've sampled.
I understand how to apply the first formula, but only if I know the distribution of the random variable (be it $N(0,1)$ or any other common distributions shown in most textbooks). But what is the intuitive approach when dealing with real, sampled, data of which we don't know the distribution?