📄 regressionnowdefault1.m
字号:
function [prices,exercisetime]=regressionnowdefault1(St,k,r,theta,T,sigma,m,b,seed)
% Output:
% prices: the value of defual option
% exercisetime: termination time of mortgage
% Input:
% St: price of underlying asset at time zero
% k: exercise price
% r: interest rate in year
% theta: the growth rate of the price of underlying asset in year
% T: contract maturity
% sigma: volitility of price of underlying asset
% m: number of time steps
% b: paths of underlying asset
r=log(1+r/12);
theta=log(1+theta/12);
sigma=sqrt(sigma/12);
dt=T/m;
discount=exp(-r*dt);
discountvector=exp(-r*dt*(1:m)');
a=zeros(3,1);
spaths=genpaths(St,theta,sigma,T,m,b,seed);
spaths(:,1)=[];
cashflows=max(0,k(m)-spaths(:,m));
exercisetime=m*ones(b,1);
for step=m-1:-1:1;
inmoney=find(spaths(:,step)<k(step));
if ~isempty(inmoney)
xdata=spaths(inmoney,step);
regrmat=[ones(length(xdata),1),xdata,xdata.^2];
ydata=cashflows(inmoney).*discountvector(exercisetime(inmoney)-step);
a=regrmat\ydata;
intrinsicvalue=k(step)-xdata;
continuationvalue=regrmat*a;
exercise=find(intrinsicvalue>continuationvalue);
g=inmoney(exercise);
cashflows(g)=intrinsicvalue(exercise);
exercisetime(g)=step;
end
end
prices=cashflows.*discountvector(exercisetime);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -