%% Compute the Implied Volatility for an American Option Using the Barone-Adesi and Whaley Option Pricing Model
% This example shows how to compute implied volatility using the Barone-Adesi and Whaley option pricing model. Consider three American call options with exercise prices of $100 that expire on July 1, 2017. The underlying stock is trading at $100 on January 1, 2017 and pays a continuous dividend yield of 10%. The annualized continuously compounded risk-free rate is 10% per annum, and the option prices are $4.063, $6.77 and $9.46. Using this data, calculate the implied volatility of the stock using the Barone-Adesi and Whaley option pricing model.

AssetPrice = 100;
Settle = 'Jan-1-2017';
Maturity = 'Jul-1-2017';
Strike = 100;
DivAmount = 0.1;
Rate = 0.05;

%
% Define the RateSpec.

RateSpec = intenvset('ValuationDate', Settle, 'StartDates', Settle,...
'EndDates', Maturity, 'Rates', Rate, 'Compounding', -1, 'Basis', 1)

%
% Define the StockSpec.

StockSpec = stockspec(NaN, AssetPrice, {'continuous'}, DivAmount)

%
% Define the American option.

OptSpec = {'call'};
OptionPrice = [4.063;6.77;9.46];

%
% Compute the implied volatility for the American option.

ImpVol =  impvbybaw(RateSpec, StockSpec, Settle, Maturity, OptSpec,...
Strike, OptionPrice)

%
% Copyright 2012 The MathWorks, Inc.