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

Respuestas (1)

Geoff Hayes
Geoff Hayes el 15 de Mayo de 2016

0 votos

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);

Categorías

Más información sobre Financial Toolbox en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 15 de Mayo de 2016

Respondida:

el 15 de Mayo de 2016

Community Treasure Hunt

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

Start Hunting!

Translated by