www.gusucode.com > fininst 案例源码程序 matlab代码 > fininst/ComputethePriceofaBermudanOptionUsingMonteCarloSimulatioExample.m

    %% Compute the Price of a Bermudan Option Using Monte Carlo Simulation Based on Geometric Brownian Motion  

% Copyright 2015 The MathWorks, Inc.


%% 
% Define the option. 
S0 = 80; % Initial price of underlying asset
Sigma = .3; % Volatility of underlying asset
Strike = 75; % Strike
OptSpec = 'put'; % Put option
Settle = '1-Jan-2013'; % Settlement date of option
Maturity = '1-Jan-2014'; % Maturity date of option
ExerciseDates = {'1-Jun-2013', '1-Jan-2014'}; % Exercise dates of option
r = .05; % Risk-free rate (annual, continuous compounding)
Compounding = -1; % Continuous compounding
Basis = 0; % Act/Act day count convention
T = yearfrac(Settle, Maturity, Basis); % Time to expiration in years
ExerciseTimes = yearfrac(Settle, ExerciseDates, Basis)'; % Exercise times  

%% 
% Set up the |gbm| object and run the Monte Carlo simulation based on Geometric
% Brownian Motion (GBM) using the |simBySolution| method from Financial
% Toolbox(TM). 
NTRIALS = 1000;
NPERIODS = daysact(Settle, Maturity);
dt = T/NPERIODS;
OptionGBM = gbm(r, Sigma, 'StartState', S0);
[Paths, Times, Z] = simBySolution(OptionGBM, NPERIODS, ...
'NTRIALS',NTRIALS, 'DeltaTime',dt,'Antithetic',true);  

%% 
% Create the interest-rate term structure to define |RateSpec|. 
RateSpec = intenvset('ValuationDate', Settle, 'StartDates', Settle, ...
           'EndDates', Maturity, 'Rate', r, 'Compounding', Compounding, ...
           'Basis', Basis)  

%% 
% Price the Bermudan option. 
SimulatedPrices = squeeze(Paths);
BermudanPrice = optpricebysim(RateSpec, SimulatedPrices, Times, ...
OptSpec, Strike, ExerciseTimes)