Fzero Solving for the same value

1 visualización (últimos 30 días)
Oscar de la Torre
Oscar de la Torre el 28 de Mzo. de 2019
Comentada: Oscar de la Torre el 29 de Mzo. de 2019
Hi,
I'm trying to use fzero to find the implied asset value of a firm. My function to calculate the asset value is:
Function F = myKMV1(x,st,vol,D,r)
x = x^2 ;%used to prevent negative numbers
d1 = log(x/D)+r+0.5*(vol*vol)/vol ;
d2 = d1 - vol ;
F = st - x*normcdf(d1)+D*exp(-r)*normcdf(d2);
I have to iterate through a vector with different share prices and for each share price there should be a different implied asset value. However, fzero always gives the same result even though the share price is changing? The code running the function is as follows:
fun = @(x) myKMV1(x, st1, vol1,D11, r1)
volNew = 1;
vol1 = AssetVolatility; %this is equal to 0.0582
D11 = D1; %this is equal to 88500000
r1 = UkGilt; % this is equal to 0.0185
while abs(vol1 - volNew) > 0.00001
vol1 = VolNew ;
for n = 1:252
st1 = st(n);
x(n) = fzero(fun, 1000)
end
end
Thanks for any help in advance!
  2 comentarios
Walter Roberson
Walter Roberson el 28 de Mzo. de 2019
You did not indicate what problem you are observing?
To test we need values for st1, vol1, D11, r1
Oscar de la Torre
Oscar de la Torre el 28 de Mzo. de 2019
The problem I'm observing is that the value fzero is solving for is the same even though st1 changes. st1 is a vector of values of which the first five are: [10757700, 10757700, 108652700, 112955850], vol1 = 0.0582, D11 = 88500000, and r1 = 0.0185. So because only the values of st1 change the values calculated by fzero, i.e. x, should change but with the code above the answer provided by fzero is constant.
Hope this clarifies,
Thanks!

Iniciar sesión para comentar.

Respuesta aceptada

Walter Roberson
Walter Roberson el 28 de Mzo. de 2019
When you define
fun = @(x)myKMV1(x,st1,vol1,D11,r1)
then at the time that that statement is executed (defining the function handle for assignment to fun) then the a copy is taken of the values of st1, vol1, D11, r1, and those values are saved along with the function handle. No matter how you might change those variables after that, the recorded values are brought back into memory for use by the anonymous function.
You should move the definition of fun to between the assignment to st1 and the use of fun in the fzero call.
  1 comentario
Oscar de la Torre
Oscar de la Torre el 29 de Mzo. de 2019
It works! Thank you so much. I really appreciate it I've spent days working on it without realising it.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre MATLAB en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by