楼主: eulalia
3937 3

[资产定价] 求助大神!最小二乘法LSM计算亚美式期权~~附matlab代码 [推广有奖]

  • 0关注
  • 0粉丝

小学生

85%

还不是VIP/贵宾

-

威望
0
论坛币
8 个
通用积分
0
学术水平
1 点
热心指数
1 点
信用等级
1 点
经验
317 点
帖子
10
精华
0
在线时间
9 小时
注册时间
2009-8-30
最后登录
2017-3-30

楼主
eulalia 发表于 2017-3-28 14:33:28 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
已经建好LSM算普通美式期权的模型,试算了没有问题,但修改成亚美式就始终算不出正确答案,有的时候美式的价格比欧式的还低……百思不得其解……求助大神指点!
matlab代码如下:
脚本:
clc; clear;


%% Stock price features.

%%
Spot = 4000;               % Spot price.
r = 0.0488;                 % Risk free rate.
q = 0;

% Option features.
K =4000;                  % Strike price.
v = 0.3;                % Volatility.
T =1/3;                % Maturity in years.

% Simulation features.
NT = 20;                % Number of time increments.
dt = T/NT;               % Time increment.
NS = 1e4;                % Number of simulated paths.

% Trinomial tree features.
%n = 250;                 % Time steps for trinomial tree.
EuroAmer = 'A';          % Flavor indicator for trinomial tree.
PutCall = 'P';           % Select a put in the trinomial tree.

%% Simulate the stock price process under Black Scholes
FirstCol1 = log(Spot).*ones(NS,1);
z=randn(NS,NT-1);
E1 = (r-q-0.5*v^2)*dt + sqrt(dt)*v.*z;
All1 = [FirstCol1 E1];
S1 = cumsum(All1,2);
S=exp(S1);
clear FirstCol1 E1 All1


%% Longstaff-Schwartz price
% Design matrix for the LSM algorithm
XmatrixHandle = {@(y)ones(length(y),1), @(y)(y),@(y)(y.^2)};
% Run the LSM algorithm
[EuroPriceLSM AmerPriceLSM] = BlackScholesLSM_asian_new(S,K,r,q,T,NS,NT,dt,PutCall,XmatrixHandle);
% Early exercise premium
PremiumLSM = AmerPriceLSM - EuroPriceLSM;


函数:

function [EuroPrice AmerPrice] = BlackScholesLSM_asian_new(S,K,r,q,T,NS,NT,dt,PutCall,XmatrixHandle)

% Longstaff-Schwartz method for American options
% Fabrice Douglas Rouah, FRouah.com and Volopta.com

% INPUTS
%  S = Matrix of simulated stock price, size NSxNT (rows are paths)
%  K = Strike
%  r = Risk free rate
%  q = Dividend yield
%  T = Maturity
%  NS = Number of stock price paths
%  NT = Number of time steps per path
%  dt = Time increment (T/NT)
%  PutCall = 'P' or 'C'

% Number of columns in the X matrix
NX = length(XmatrixHandle);

% Initialize the Cash Flows
CF = zeros(NS,NT);

%Create average price
S_avg=zeros(NS,NT);
S_sum=zeros(NS,NT);
parfor i=1:NT
    S_sum(:,i)=sym(sum(S(:,1:i),2));
    S_avg(:,i)=sym(S_sum(:,i)./i);
end

% Set the last cash flows to the intrinsic value
if strcmp(PutCall,'P')
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:matlab代码 MATLAB 最小二乘法 matla atlab features 正确答案 matlab price 模型

已有 1 人评分经验 学术水平 热心指数 信用等级 收起 理由
accumulation + 100 + 1 + 1 + 1 精彩帖子

总评分: 经验 + 100  学术水平 + 1  热心指数 + 1  信用等级 + 1   查看全部评分

本帖被以下文库推荐

沙发
eulalia 发表于 2017-3-28 14:34:55
额怎么发出来不完整……
函数:
function [EuroPrice AmerPrice] = BlackScholesLSM_asian_new(S,K,r,q,T,NS,NT,dt,PutCall,XmatrixHandle)

% Longstaff-Schwartz method for American options
% Fabrice Douglas Rouah, FRouah.com and Volopta.com

% INPUTS
%  S = Matrix of simulated stock price, size NSxNT (rows are paths)
%  K = Strike
%  r = Risk free rate
%  q = Dividend yield
%  T = Maturity
%  NS = Number of stock price paths
%  NT = Number of time steps per path
%  dt = Time increment (T/NT)
%  PutCall = 'P' or 'C'

% Number of columns in the X matrix
NX = length(XmatrixHandle);

% Initialize the Cash Flows
CF = zeros(NS,NT);

%Create average price
S_avg=zeros(NS,NT);
S_sum=zeros(NS,NT);
parfor i=1:NT
    S_sum(:,i)=sym(sum(S(:,1:i),2));
    S_avg(:,i)=sym(S_sum(:,i)./i);
end

% Set the last cash flows to the intrinsic value
if strcmp(PutCall,'P')
        CF(:,NT) = max(K - S_avg(:,NT), 0);
elseif strcmp(PutCall,'C')
        CF(:,NT) = max(S_avg(:,NT) - K, 0);
end

% European option value
EuroPrice = exp(-r*T)*mean(CF(:,NT));

% Work backwards through the stock prices until time j=2.
% We could work through to time j=1 but the regression will not be
% of full rank at time 1, so this is cleaner.
for j=NT-1:-1:2
        if strcmp(PutCall,'P')
                I = find(S_avg(:,j) < K);           % Indices for Puts
        else
                I = find(S_avg(:,j) > K);           % Indices for Calls
        end
        X = S(I,j);                         % X-vector = time j stock prices.
    EX=S_avg(I,j);   
        Y = CF(I,j+1)*exp(-r*dt);           % Y-vector = time j+1 discounted CF.
    Z = zeros(length(X),NX);            % Design matrix for regression to predict cash flows
    for k=1:NX
        Z(:, k) = feval(XmatrixHandle{k}, X);
    end
        beta = Z\Y;                               % Regression parameters.
        P = Z*beta;                         % Regression predicted CF.
        if strcmp(PutCall,'P')
                J = max(K - EX, 0) > P;          % Early exercise for puts.
        else
                J = max(EX - K, 0) > P;          % Early exercise for calls.
    end
        E = I(J);                           % Stock price indices where immediate exercise is optimal.
        C = setdiff((1:NS),E)';             % Stock price indices where continuation is optimal.
        if strcmp(PutCall,'P')
                CF(E,j) = max(K - EX(J), 0);     % Replace with early exercise for puts
        else
                CF(E,j) = max(EX(J) - K, 0);
        end
        CF(C,j) = exp(-r*dt)*CF(C,j+1);     % Continued CF are discounted back one period.
end

% American option value
AmerPrice = exp(-r*dt)*mean(CF(:,2));

藤椅
TimeT 发表于 2017-5-7 12:41:05
我觉得,你这个问题是用于regress用的basis function不够有效(或不够多),我看了一下,BlackScholesLSM_asian_new 中 basis function似乎只考虑了每个可行权时点的即时的股价,未考虑累计到该可行权时点的股价平均值。不用股价平均值作为basis function就可能使行权决策离“最优行权决策"很远,导致美式期权(因为行权时机不合适)的计算出现小于欧式期权的情况。

板凳
zqq— 发表于 2017-9-4 17:54:17
您好,请问这个代码是美式的还是亚美式的

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注jr
拉您进交流群
GMT+8, 2025-12-26 20:50