Code not looping - help please!

조회 수: 1 (최근 30일)
Floralis
Floralis 2016년 5월 11일
댓글: Eustace Tan 2016년 5월 14일
% *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
Floralis
Floralis 2016년 5월 11일
function [A,Sigma_A]=AV(E,L,r,h,iter)
Function Asset Value, gets vector of A(daily asset values) and Sigma_A(volatility of vector A).
Inputs are E (daily market price of shares/equity), L(total liabilities per share as in financial statements), r (US treasury 1 yr yield), h(time to maturity, set in 1 yr), iter (number of iterations of the loop). Variables are available in the attached file.
Adam
Adam 2016년 5월 11일
편집: Adam 2016년 5월 11일
What exactly in your loop is supposed to be different each time round? You don't use 'i' in it anywhere so at a glance it looks like it will just do the same thing every time round the loop.

댓글을 달려면 로그인하십시오.

답변 (1개)

Eustace Tan
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
Floralis 2016년 5월 11일
Hello Eustace, Comments are definitions of the variables, just wording. I wrote the code and I believe there must be an error somewhere else. Thanks for your answer.
Eustace Tan
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?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by