backtesting value at risk independence test codes

조회 수: 1 (최근 30일)
shreya
shreya 2014년 8월 19일
댓글: Star Strider 2014년 8월 20일
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

답변 (1개)

Star Strider
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
shreya
shreya 2014년 8월 20일
thanks a lot! it worked
but i am facing another problem now, I am completely new to matlab. I got the above codes for backtesting from a website and now i see i am not getting the codes right.
I aim to forecast VaR values and do backtesting. however, i have my VaR values which i got from using the software WINRATS. I could not perform backtesting on that very software so thought of trying matlab since the codes available.
could you please tell me how to apply the codes for backtesting if i already have VaR values?
It would be great help.
Star Strider
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 CenterFile Exchange에서 Financial Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by