How to code the 3 sigma method

조회 수: 71 (최근 30일)
Enrico Scupola
Enrico Scupola 2017년 3월 2일
답변: Sindhu Priya 2017년 3월 8일
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