This section covers the formulas for calculating the expectation of a random variable, variance of a random variable, and the covariance between two random variables. The expectation of the random variable, if it exists, is the mean for that random variable. The formulas in this section are especially helpful to understand for people interested in courses concerning finance and investing.
Var(X)=E[(X−μx)2]=σ2x
Cov(X,Y)=E[(X−μx)(Y−μy)]=σxy
2. Continuous Case E(X)=∫∞−∞xf(x)dx=μ
Var(X)=∫∞−∞(x−μ)2f(x)dx=∫∞−∞x2f(x)dx−μ2=σ2
Cov(X,Y)=∫∞−∞∫∞−∞(x−μx)(y−μy)f(x,y)dxdy=σxy
3. Discrete case The following sections will cover only the discrete case for a deeper understanding of the latter formulas presented. For discrete random variables summation is required to solve for expectation, variance and covariance. For continuous random variables integration is required, which is beyond the scope of this text.
E(X)=∑πixi=μx
Var(X)=∑πi[(xi−μx)2]=∑πix2i−(∑πixi)2=σ2x
Cov(X,Y)=∑πi[(xi−μx)(yi−μy)]=∑πixiyi−(∑πixi∑πiyi)
Cov(X,Y)=σxy
where $\pi_i$ is the probability of outcome $i$ and $x_i$ is the outcome.
Example $i$, could refer to recession, stable economy, expanding economy. The $\pi_i$ could be the given probabilities of each and $x_i$ could be the profit/loss of a mutual fund given the situation. Note: $\sum_{i} \pi_i=1$.
Let $c$ be a constant, for example let $c=5$.
E[X]=∑πi(xi)=μx
E[cX]=∑πi(cxi)=c∑πi(xi)=cμx
E[5X]=∑πi(5(xi))=5∑πi(xi)=5μx
E[X+c]=∑πi(xi+c)=∑πi(xi)+∑πi(c)=μx+c∑πi=μx+c
E[X+5]=∑πi(xi+5)=∑πi(xi)+∑πi(5)=μx+5∑πi=μx+5
If you have a summation of something over $i$ that doesn't change for any of the $i$, for example a constant $c$, or $5$ it can be moved outside of the summation, as was done above.
Let $c$ be a constant, for example let $c=5$.
Var(X)=∑πi[(xi−μx)2]=σ2x
Var(cX)=∑πi[(c(xi)−cμx)2]=∑πi[c((xi)−μx)2]=c2∑πi[((xi)−μx)2]=c2σ2x
Var(5X)=∑πi[(5(xi)−5μx)2]=∑πi[5((xi)−μx)2]=52∑πi[((xi)−μx)2]=52σ2x=25σ2x
Var(X+c)=∑πi[((xi+c)−(μx+c))2]=∑πi[((xi)+c−μx−c)2]=∑πi[((xi)−μx)2]=σ2x
Var(X+5)=∑πi[((xi+5)−(μx+5))2]=∑πi[((xi)+5−μx−5)2]=∑πi[((xi)−μx)2]=σ2x
Let $c_1$ be a constant, for example let $c_1=5$ and $c_2$ be another constant, for example let $c_2=7$.
Cov(X,Y)=∑πi[(xi−μx)(yi−μy)]
Cov(c1X,c2Y)=∑πi[(c1xi−c1μx)(c2yi−c2μy)]=c1c2∑πi[(xi−μx)(yi−μy)]=c1c2Cov(X,Y)
Cov(5X,7Y)=∑πi[(5xi−5μx)(7yi−7μy)]=5∗7∑πi[(xi−μx)(yi−μy)]=35Cov(X,Y)
Cov(X+c1,Y+c2)=∑πi[((xi+c1)−(μx+c1))((yi+c2)−(μy+c2))]=∑πi[(xi−μx)(yi−μy)]=Cov(X,Y)
Cov(X+5,Y+7)=∑πi[((xi+5)−(μx+5))((yi+7)−(μy+7))]=∑πi[(xi−μx)(yi−μy)]=Cov(X,Y)
The addition of constants cancel each other out as in the variance formula.
7. Expectation and Variance of a Weighted Sum
Let $Z=X+Y$ so:
E[Z]=μz
by definition, but it can broken into its components $X$ and $Y$.
E[Z]=E[X+Y]=∑πi(xi+yi)=∑πi(xi)+∑πi(yi)=μx+μy
Recall:
(a+b)2=a(a+b)+b(a+b)=a2+2ab+b2
We will need this to understand $Var(c_1X+c_2Y)$
Again let $Z=X+Y$
Var(Z)=E[(Z−μz)2]=σ2z
but you may only be able to solve for $Z$ from the $X$ and $Y$.
Var(Z)=E[(Z−μz)2]=E[((X+Y)−(μx+μy))2]=
Think of $(X+Y)$ as $a$ and $(\mu_x+\mu_y)$ as $b$.
E[(X+Y)2−2(X+Y)(μx+μy)+(μx+μy)2]=
Again using $(a+b)^2=a^2+2ab+b^2$
E[X2+2XY+Y2−2Xμx−2Xμy−2Yμx−2Yμy+μ2x+2μxμy+μ2y]=
Yes, a big mess but the terms can be regrouped and come up with the following:
=E[(X2−2Xμx+μ2x)+(Y2−2Yμy+μ2y)+2(XY−Xμy−Yμx+μxμy)]=E[(X−μx)2+(Y−μy)2+2(X−μx)(Y−μy)]=E[(X−μx)2]+E[(Y−μy)2]+2E[(X−μx)(Y−μy)]=Var(X)+Var(Y)+2Cov(X,Y)=Var(Z)
From these concepts:
Var(c1X+c2Y)=Var(c1X)+Var(c2Y)+2Cov(c1X,c2Y)=c21Var(X)+c22Var(Y)+2c1c2Cov(X,Y)
If we added a constant, $c_3$ this not change the variance, see next formula:
Var(c1X+c2Y+c3)=Var(c1X)+Var(c2Y)+2Cov(c1X,c2Y)=c21Var(X)+c22Var(Y)+2c1c2Cov(X,Y)
Note: $Cov(X,X)=Var(X)$ and correlation, $\rho=\frac{Cov(X,Y)}{\sigma_x \sigma_y}$
8. Expectation and Variance of an Average of Independently Identically Distributed Random Variables
Let $X_1, X_2, \ldots, X_n$ be $n$ independently identically distributed (i.i.d.) random variables with mean of $\mu$ and
a variance of $\sigma^2$. Let the average of the i.i.d. random variables be denoted
ˉX=1nn∑i=1Xi.
Then the expectation of
E[ˉX]=E[1nn∑i=1Xi]=1nn∑i=1E[Xi]=1nnμ=μ,
and the variance of
Var(ˉX)=Var(1nn∑i=1Xi)=1n2n∑i=1Var(Xi)=1n2nσ2=σ2n.
Note: Since the random variables are independent the $Cov(X_i,X_j)=0$ for $i \neq j$.
[\latex]