Calculation of covariance given a joint probability function
The joint probability function of two random variables, X and Y, denoted P(X, Y), gives the probability of joint occurrences of values of X and Y.
Joint probability function of returns of two stocks A and B
R_{B}=22 percent 
R_{B}=14 percent 
R_{B}=8 percent 

R_{A}=18 percent 
0.35 
0 
0 
R_{A}=12 percent 
0 
0.40 
0 
R_{A}=6 percent 
0 
0 
0.25 
The expected return of the stock A from the above table = 0.35*0.18 + 0.40*0.12 + 0.25*0.06 = 12.6 percent
The expected return of the stock B from the above table = 0.35*0.22 + 0.40*0.14 + 0.25*0.08 = 15.3 percent
Calculation of covariance:
Cov(R_{A}, R_{B}) = E{[R_{A}  E(R_{A})] [R_{B}  E(R_{B})]} = * [R_{A}  E(R_{A})] [R_{B}  E(R_{B})] = 0.35*[(0.180.126)(0.220.153)] + 0.40*[(0.120.126)(0.14 0.153)] + 0.25*[(0.060.126)(0.080.153)] = 0.002832
Var(R_{A}) = E{[R_{A } E(R_{A})]^{2}} = 0.35*(0.180.126)^{2} + 0.40*(0.120.126)^{2} + 0.25*(0.060.126)^{2} = 0.002124
Var(R_{B}) = E{[R_{B } E(R_{B})]^{2}}= 0.35*(0.220.153)^{2} + 0.40*(0.140.153)^{2} + 0.25*(0.080.153)^{2} = 0.003801
σ(R_{A}) = √Var(R_{A}) = √0.002124 = 0.0461 = 4.61 percent
σ(R_{B}) = √Var(R_{B}) = √0.003801 = 0.0617 = 6.17 percent
Corr(R_{A}, R_{B}) = Cov(R_{A}, R_{B})/ σ(R_{A}) σ(R_{B}) = 0.002832/(0.0461)(0.0617) = 0.9967.
Previous LOS: Expected value, standard deviation, covariance, and correlation of returns on a portfolio>
Next LOS: Updated probability using Bayes' formula