Code not looping - help please!
显示 更早的评论
% *function [A,Sigma_A]=AV(E,L,r,h,iter)*
%Función ASSET VALUES
%Outputs
%A= matriz de valores de activos por acción (Total de Activos/N° de Acciones)en
%cada momento t.
%Sigma_A= volatilidad de la matriz A.
%Inputs
%E= matriz de precio de mercado de las acciones de la firma.
%L= matriz de pasivos totales por acción en cada momento t.
%r= tasa de interés libre de riesgo (one year US T-bill).
%h= T-t. Maturity de los pasivos y horizonte sobre el que se calculará la probabilidad de default.
%iter= number of iterations.
A=(E+L);%initial values
Sigma_A=std(A);%initial values
i=1;
while i<iter
%Calculating standard deviation of natural log of the assets daily
%return [ln(a_t/a_t-1)]
[n,~]=size(A);
J=zeros(n,1);
for n=2:n
J(n,1)=(A(n,1)/A(n-1,1));
end
J(1)=[];%first value is lost, needs to be eliminated before taking logs
JJ=log(J);
Sigma_A=std(JJ)*sqrt(n-1);
%Calculando d1 y d2 de la fórmula de Black&Scholes
d1=(log(A./L)+(r+Sigma_A^2*0.5)*h)/(Sigma_A*sqrt(h));
d2=d1-Sigma_A*sqrt(h);
Nd1=normcdf(d1);
Nd2=normcdf(d2);
%Reexpresando la fórmula de valuación de un call sobre el Equity en
%términos del valor de la firma (valor de los assets)
A=(E+L.*(exp(-r*h)).*Nd2)./Nd1;
i=i+1;
end
I am trying to iterate the Merton structural model in the assets equation, but every time I run the code, I get the very same vector for A and therefore same value for Sigma_A (volatility). Ideally I should get different vectors every time.. each one closer to the "real" values. It must be something I did wrong in the loop.
I would be very grateful if anyone could help me to find my mistake. I have read the documentation and several tutorials but made no advances.
3 个评论
Geoff Hayes
2016-5-11
Floralis - how are you calling this function? What are the inputs?
Floralis
2016-5-11
回答(1 个)
Eustace Tan
2016-5-11
Uncomment these lines, and then it's just the matter of plugging in the variables.
% *function [A,Sigma_A]=AV(E,L,r,h,iter)*
%A= matriz de valores de activos por acción (Total de Activos/N° de Acciones)en
%cada momento t.
%Sigma_A= volatilidad de la matriz A.
%Inputs
%E= matriz de precio de mercado de las acciones de la firma.
%L= matriz de pasivos totales por acción en cada momento t.
%r= tasa de interés libre de riesgo (one year US T-bill).
%h= T-t. Maturity de los pasivos y horizonte sobre el que se calculará la probabilidad de default.
%iter= number of iterations.
2 个评论
Floralis
2016-5-11
Eustace Tan
2016-5-14
Okay, here's the thing, your code loops, it just doesn't update the values. That is to say, your loop does not change the inputs after each iteration. Get it?
类别
在 帮助中心 和 File Exchange 中查找有关 Linear Predictive Coding 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!