How to code the 3 sigma method
68 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi guys, I need to code the 3 sigma method in Matlab and I don't know how to do it. Basically the idea is to create a range from mean + 3 sigma(standard deviation) to mean - 3 sigma. Then I need to construct a dummy variable (not sure about that) to see how many times the SP500 returns are outside this range basically and then compute the probability of having this values in the whole set of observations. The aim is to compute the empirical probability of having booms and busts (extrema) and comparing this probability with the one coming from a Normal distribution (theoretical probability).
Your help would be very appreciated. Thanks.
Guys I tried this code but I got an error in the dummy variable ... r_logActual are the log returns of 6 assets ( matrix).
for x=1:6
upperbound(x,:) = mean(r_logActual(:,x))+3*std(r_logActual(:,x));
lowerbound(x,:) = mean(r_logActual(:,x))-3*std(r_logActual(:,x));
end
for n = 1:6
if r_logActual(:,n) <= upperbound(n:1) & r_logActual(:,n) >= lowerbound(n:1)
emp_prob(x)=1;
else
emp_prob(x)=0;
end
end
0 comentarios
Respuestas (1)
Sindhu Priya
el 8 de Mzo. de 2017
Hi Enrico,
There is a small mistake in the logic where you compare the upperbound and lowerbound with the actual values.
upperbound(n:1) & lowerbound(n:1) will return a 0X1 column vector, it might be the line which is causing the error.
The corrected code is as follows,
for x=1:6
upperbound(x,:) = mean(r_logActual(:,x))+3*std(r_logActual(:,x));
lowerbound(x,:) = mean(r_logActual(:,x))-3*std(r_logActual(:,x));
end
for n = 1:6
if r_logActual(:,n) <= upperbound(n,1) & r_logActual(:,n) >= lowerbound(n,1)
emp_prob(x)=1;
else
emp_prob(x)=0;
end
end
Hope it will resolve the issue.
0 comentarios
Ver también
Categorías
Más información sobre Biological and Health Sciences en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!