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
Geoff Hayes 2016 年 5 月 11 日
Floralis - how are you calling this function? What are the inputs?
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 日

0 投票

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?

サインインしてコメントする。

質問済み:

2016 年 5 月 11 日

コメント済み:

2016 年 5 月 14 日

Community Treasure Hunt

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

Start Hunting!

Translated by