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

Risposte (1)

Geoff Hayes
Geoff Hayes il 15 Mag 2016
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);

Categorie

Scopri di più su Financial Toolbox in Centro assistenza e File Exchange

Tag

Richiesto:

il 15 Mag 2016

Risposto:

il 15 Mag 2016

Community Treasure Hunt

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

Start Hunting!

Translated by