fsolve not working, always say near zero?

my Black-Scholes Function:
-----------------
function C = bs ( Interest, Volatility, Stock, StrikePrice, TimeToMaturity )
d1 = (log(Stock ./ StrikePrice) + (Interest + (Volatility .^ 2) ./ 2) .* TimeToMaturity) ./ (Volatility .* sqrt(TimeToMaturity));
d2 = (log(Stock ./ StrikePrice) + (Interest - (Volatility .^ 2) ./ 2) .* TimeToMaturity) ./ (Volatility .* sqrt(TimeToMaturity));
C = normcdf(d1) .* Stock - normcdf(d2) .* StrikePrice .* exp(-Interest .* TimeToMaturity);
end
----------------------------------------------------------------
My new function for fsolve
---------------
function F = myfunc(C, Interest, Volatility, Stock, StrikePrice, TimeToMaturity)
F = C - bs(Interest, Volatility, Stock, StrikePrice, TimeToMaturity);
end
-----------------------------------------------------------------
Now I make C =261
volatility = fsolve(@(x) myfunc(261,0.05,x,1033.56, 775, 1/52), 1);
The answer should be around 1.12, but I only get these:
fsolve completed because the vector of function values is near zero as measured by the default value of the function tolerance, and the problem appears regular as measured by the gradient.
Equation solved. The sum of squared function values, r = 1.289886e-20, is less than sqrt(options.TolFun) = 1.000000e-03. The relative norm of the gradient of r, 9.923745e-10, is less than options.TolFun = 1.000000e-06.
Please Help!! Thank you very much!

 採用された回答

Amit
Amit 2014 年 1 月 21 日
編集済み: Amit 2014 年 1 月 21 日

0 投票

type
volatility
This is the variable that you stored the solution. I just tested it. The volatility comes to be 1.1195 which is close to 1.12.
The 'Equation solved. The sum of squared function values, r = 1.289886e-20, is less than sqrt(options.TolFun) = 1.000000e-03. The relative norm of the gradient of r, 9.923745e-10, is less than options.TolFun = 1.000000e-06.' is telling you that a solution is found.

2 件のコメント

Tiancong
Tiancong 2014 年 1 月 21 日
YES! Finally I got this right, thank you sooooooo much!
Tiancong
Tiancong 2014 年 1 月 21 日
You are awesome !!! Thank you!

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeEarth and Planetary Science についてさらに検索

タグ

質問済み:

2014 年 1 月 21 日

コメント済み:

2014 年 1 月 21 日

Community Treasure Hunt

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

Start Hunting!

Translated by