www.gusucode.com > fininst 案例源码程序 matlab代码 > fininst/ComputethePriceofanAmericanLookbackOptionUsingMonteCarloExample.m
%% Compute the Price of an American Lookback Option Using Monte Carlo Simulation Based on Geometric Brownian Motion % Copyright 2015 The MathWorks, Inc. %% % Define the option. S0 = 100; % Initial price of underlying asset Sigma = .2; % Volatility of underlying asset Strike = 110; % Strike OptSpec = 'call'; % Call option Settle = '1-Jan-2013'; % Settlement date of option Maturity = '1-Jan-2014'; % Maturity date 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 %% % 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 an American lookback option by finding the maximum price over periods. MaxPrices = zeros(NPERIODS+1, NTRIALS); LastPrice = squeeze(Paths(1,:,:))'; for i = 1:NPERIODS+1; MaxPrices(i,:) = max([LastPrice; Paths(i,:)]); LastPrice = MaxPrices(i,:); end LookbackPrice = optpricebysim(RateSpec, MaxPrices, Times, OptSpec, ... Strike, T, 'AmericanOpt', 1)