Code covered by the BSD License  

Highlights from
Graphically explore the Black-Scholes-Merton Option Pricing Model

image thumbnail

Graphically explore the Black-Scholes-Merton Option Pricing Model

by

 

10 Sep 2012 (Updated )

Visualize option price & gradient surfaces

priceOption(S0,K,r,T,sigma)
function [call, put] = priceOption(S0,K,r,T,sigma)
% priceOption computes European option prices using the
% Black-Scholes-Merton model
%
% Usage:
% [call, put] = priceOption(S0, K, r, T, sigma)
%
% Where the inputs are, in order, the underlying price, strike, rate, time
% to expiration and volatility.

% Copyright 2010 The MathWorks, Inc.

% Precompute terms that are used more than once
A = sigma .* sqrt(T);
E = K .* exp(-r.*T);

d1 = (1 ./ A) .* ( log(S0 ./ K) + T .* (r + sigma.^2 / 2) );
% Handle the case for when d1 has a 0/0. 
d1(isnan(d1)) = 0;
d2 = d1 - A;

call = S0 .* normcdf(d1)  -  E .* normcdf(d2);
put  =  E .* normcdf(-d2) - S0 .* normcdf(-d1);

Contact us