%% Compute Option Prices and Sensitivities Using the Black-Scholes Option Pricing Model
% This example shows how to compute option prices and sensitivities using the Black-Scholes option pricing model. Consider a European call and put options with an exercise price of $30 that expires on June 1, 2008. The underlying stock is trading at $30 on January 1, 2008 and has a volatility of 30% per annum. The annualized continuously compounded risk-free rate is 5% per annum. Using this data, compute the delta, gamma, and price of the options using the Black-Scholes model.

AssetPrice = 30;
Strike = 30;
Sigma = .30;
Rates = 0.05;
Settle = 'January-01-2008';
Maturity = 'June -01-2008';

% define the RateSpec and StockSpec
RateSpec = intenvset('ValuationDate', Settle, 'StartDates', Settle, 'EndDates',...
Maturity, 'Rates', Rates, 'Compounding',-1, 'Basis', 1);

StockSpec = stockspec(Sigma, AssetPrice);

% define the options
OptSpec = {'call', 'put'};

OutSpec = {'Delta','Gamma','Price'};
[Delta, Gamma, Price] = optstocksensbybls(RateSpec, StockSpec, Settle,...
Maturity, OptSpec, Strike,'OutSpec', OutSpec)

% Copyright 2015 The MathWorks, Inc.