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

    %% Compute the Price of a Spread Option Using the Alternate Direction Implicit (ADI) Finite Difference Method  

% Copyright 2015 The MathWorks, Inc.


%% 
% Define the spread option dates. 
Settle = '01-Jun-2012';
Maturity = '01-Sep-2012';  

%% 
% Define asset 1. 
% Price and volatility of RBOB gasoline
  Price1gallon = 2.85;          % $/gallon
  Price1 = Price1gallon * 42;   % $/barrel
  Vol1 = 0.29;  

%% 
% Define asset 2. 
 % Price and volatility of WTI crude oil
   Price2 = 93.20;         % $/barrel
   Vol2 = 0.36;  

%% 
% Define the correlation between the underlying asset prices of asset 1
% and asset 2. 
Corr = 0.42;  

%% 
% Define the spread option. 
OptSpec = 'call';
Strike = 20;  

%% 
% Define the |RateSpec|. 
rates = 0.05;
Compounding = -1;
Basis = 1;
RateSpec = intenvset('ValuationDate', Settle, 'StartDates', Settle, ...
'EndDates', Maturity, 'Rates', rates, ...
'Compounding', Compounding, 'Basis', Basis)  

%% 
% Define the |StockSpec| for the two assets. 
StockSpec1 = stockspec(Vol1, Price1)
StockSpec2 = stockspec(Vol2, Price2)  

%% 
% Compute the spread option price and sensitivities based on the Alternate
% Direction Implicit (ADI) finite difference method. 
OutSpec = {'Price', 'Delta', 'Gamma'};
[Price, Delta, Gamma, PriceGrid, AssetPrice1, AssetPrice2, Times] = ...
spreadsensbyfd(RateSpec, StockSpec1, StockSpec2, Settle, ...
Maturity, OptSpec, Strike, Corr, 'OutSpec', OutSpec);  

%% 
% Display the price and sensitivities.  
Price
Delta
Gamma  

%% 
% Plot the finite difference grid. 
mesh(AssetPrice1, AssetPrice2, PriceGrid(:, :, 1)');
    title('Spread Option Prices for Range of Underlying Prices');
    xlabel('Price of underlying asset 1');
    ylabel('Price of underlying asset 2');
    zlabel('Price of spread option');