# Calculate variance of sum random variables

Suppose random variable $$X$$ takes 3 values $$1, 2, 3$$ with probability $$\frac{1}{3}$$. Sample 1000 times from $$X$$ independently and do the following operations. Take a number $$T=0$$. If 1 comes, add 0.18 with $$T$$, if 2 comes add 0.05 with $$T$$ if 3 comes add -0.29 with $$T$$. It is clear expected value of $$T$$ is $$\frac{(0.18+0.05-0.29)1000}{3}=-20$$. How to calculate variance of $$T$$? Experimentally I am getting around 38.75. This is my Sage code.

C= [0.18, 0.05, -0.29]
D=[]
for j in range(10000):
T=0
for i in range(N):
aa=random()
if(aa<=1/3):
T=T+C[0]
if(aa>1/3 and aa<=2/3):
T=T+C[1]
if(aa>2/3):
T=T+C[2]

D.append(T)
print mean(D), variance(D)

• You do the same calculations that you've done for the expected value, but for variance instead: en.wikipedia.org/wiki/Variance#Discrete_random_variable Oct 5, 2019 at 8:43
• So variance should be 1000*((0.18^2+0.05^2+0.29^2)*(1/3)-((0.18+0.05+0.29)*(1/3))^2)=39.27 ?
– str
Oct 5, 2019 at 9:02
• look like, congrats! Oct 5, 2019 at 9:07
• Thank you so much for your help.
– str
Oct 5, 2019 at 9:15

$$Var(X)=\sum_{l=1}^k(Var(X_l))+\sum_{l
$$Var(Y)=\frac{1}{n}*(\sum_{i=1}^ny_i^2-\frac{1}{n}(\sum_{i=1}^n y_i)^2)$$
We can calculate this with knowing that n=3; and Y = {0.18, 0.05, -0.29} $$Var(Y) = 0.03926667$$ Now replacing $$Var(X_l)$$ with $$Var(Y)$$ in formula 1 and k = 1000
We reach $$Var(X) = 1000*0.03926667=39.26667$$