backtesting value at risk independence test codes
조회 수: 1 (최근 30일)
이전 댓글 표시
i have been trying to do backtesting using the following code, but i get an error saying the functtion defination is not permited in this context.the codes are as follows:-
function res=ind_test(V)
T=length(V);
J=zeros(T,4);
for i = 2:T
J(i,1)=V(i-1)==0 & V(i)==0;
J(i,2)=V(i-1)==0 & V(i)==1;
J(i,3)=V(i-1)==1 & V(i)==0;
J(i,4)=V(i-1)==1 & V(i)==1;
end
V_00=sum(J(:,1));
V_01=sum(J(:,2));
V_10=sum(J(:,3));
V_11=sum(J(:,4));
p_00=V_00/(V_00+V_01);
p_01=V_01/(V_00+V_01);
p_10=V_10/(V_10+V_11);
p_11=V_11/(V_10+V_11);
hat_p=(V_01+V_11)/(V_00+V_01+V_10+V_11);
a=(1-hat_p)^(V_00+V_10)*(hat_p)^(V_01+V_11);
b=(p_00)^(V_00)*(p_01)^(V_01)*(p_10)^(V_10)*p_11^(V_11);
res= -2*log(a/b);
end
댓글 수: 0
답변 (1개)
Star Strider
2014년 8월 19일
The problem may be that you are using the function in a script .m file. Function definitions (except Aononymous Functions) are not permitted in script .m files.
Save your function (the one you listed in your Question) as: ind_test.m in your MATLAB search path. Then call it from your script as:
res = ind_test(V);
That should work.
댓글 수: 2
Star Strider
2014년 8월 20일
My pleasure!
I’m glad it worked!
Unfortunately, I have no knowledge at all of backtesting, so I can’t help you with that. According to the documentation, the Financial Toolbox and Econometrics Toolbox, specifically the documentation on Vector Autoregressive Models, might be able to help.
That’s the best I can do. I’m not an Economist, so I don’t have the background to help you.
참고 항목
카테고리
Help Center 및 File Exchange에서 Financial Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!