% 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 Exchange에서 Financial 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