backtesting value at risk independence test codes
    1 visualización (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
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 comentarios
Respuestas (1)
  Star Strider
      
      
 el 19 de Ag. de 2014
        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 comentarios
  Star Strider
      
      
 el 20 de Ag. de 2014
				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.
Ver también
Categorías
				Más información sobre Financial Toolbox 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!

