Not enough input arguments.

% This function computes the Black-Scholes option price for both put and call
% Using given parameters
% -------------------------------------------------------------------------
function OptionPrice = BSAnalytical(CallPutFlag,S,X,T,r,sigma)
% -------------------------------------------------------------------------
% INPUTS:
% CallPutFlag: either 'C' or 'P' indicates call or put
% S : current stock price
% X : strike price
% T : time to maturity (in years)
% r : interest rate
% OUTPUT:
% OptionPrice: option price
% -------------------------------------------------------------------------
% sqrt(T) : Obtain the square root of time to maturity
% Black-Scholes Formula
d1 = (log(S / X) + (r + sigma ^ 2 / 2) * T) / (sigma * sqrt(T));
d2 = d1 - (sigma * sqrt(T));
if (CallPutFlag == 'C'),
OptionPrice = S * normcdf(d1) - X * exp(-r * T) * normcdf(d2); % compute the call price
else
OptionPrice = X * exp(-r * T) * normcdf(-d2) - S * normcdf(-d1); % compute put price
end
end

回答 (1 件)

Geoff Hayes
Geoff Hayes 2016 年 5 月 15 日

0 投票

Unati - the error message is telling you exactly what the problem is: you are calling the BSAnalytical function and not supplying enough input parameters. The function signature is
function OptionPrice = BSAnalytical(CallPutFlag,S,X,T,r,sigma)
so you must provide the CallPutFlag, S, X, T, r, and sigma inputs. For example, define these variables as (see the function header for description of each input variable with the exception of sigma)
CallPutFlag = 'C';
S = 42.00; % current stock price
X = 39.00; % strike price
T = 12; % time to maturity in years
r = 0.05; % interest rate
sigma = 0.1;
OptionPrice = BSAnalytical(CallPutFlag,S,X,T,r,sigma);

カテゴリ

ヘルプ センター および File ExchangeFinancial Toolbox についてさらに検索

タグ

質問済み:

2016 年 5 月 15 日

回答済み:

2016 年 5 月 15 日

Community Treasure Hunt

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

Start Hunting!

Translated by