%% Price an American Barrier Down In Put Option
% Compute the price of an American down in put option using the following data:

Rates = 0.0325;
Settle = '01-Jan-2016';
Maturity = '01-Jan-2017';
Compounding = -1;
Basis = 1;

%
% Define a RateSpec.

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

%
% Define a StockSpec.

 AssetPrice = 40;
 Volatility = 0.20;
 StockSpec = stockspec(Volatility,AssetPrice)

%
% Calculate the price of an American barrier down in put option.

Strike = 45;
OptSpec = 'put';
Barrier = 35;
BarrierSpec = 'DI';
AmericanOpt = 1;

Price = barrierbyls(RateSpec,StockSpec,OptSpec,Strike,Settle,Maturity,BarrierSpec,...
Barrier,'NumTrials',2000,'AmericanOpt',AmericanOpt)

% Copyright 2012 The MathWorks, Inc.