How to code the 3 sigma method

68 次查看(过去 30 天)
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

回答(1 个)

Sindhu Priya
Sindhu Priya 2017-3-8
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.

类别

Help CenterFile Exchange 中查找有关 Biological and Health Sciences 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by