function [C,P] = blackscholes(E,tm,S,r,sigma) % % Implements the Black Scholes analytic formula. % See page 79 of "The Mathematics of Financial Derivatives" % by Paul Willmott. % % Inputs: % E: exercise price % tm: time to expiry % S: current asset price % r: interest rate % sigma: asset volatility % % Note: Any input can be a vector and the output will be a % corresponding vector. % % Written by: % -- % John L. Weatherwax 2007-11-13 % % email: wax@alum.mit.edu % % Please send comments and especially bug reports to the % above email address. % %----- % to prevent warnings, in the case of zero inputs we offset E/S some E = E+eps; S = S+eps; num1 = log(S./E) + ( r + 0.5*(sigma.^2) ).*tm; d1 = num1./(sigma.*sqrt(tm+eps)); num2 = log(S./E) + ( r - 0.5*(sigma.^2) ).*tm; d2 = num2./(sigma.*sqrt(tm+eps)); % the call price: C = S.*normcdf(d1,0,1) - E.*exp(-r*tm).*normcdf(d2,0,1); % the put price: P = E.*exp(-r*tm).*normcdf(-d2,0,1) - S.*normcdf(-d1,0,1);