Fzero Solving for the same value
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
Walter Roberson
2019-3-28
You did not indicate what problem you are observing?
To test we need values for st1, vol1, D11, r1
采纳的回答
Walter Roberson
2019-3-28
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.
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!