Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
第六組
一、Importance Sampling
% DOPutMCCondIS.m
function [Cdo,CI,NCrossed] =
DOCallMCCondIS(S0,X,r,T,sigma,Sb,NSteps,NRepl,bp)
dt = T/NSteps;
nudt = (r-0.5*sigma^2)*dt;
b = bp*nudt;
sidt = sigma*sqrt(dt);
[Call,Put] = blsprice(S0,X,r,T,sigma);
for i=1:NRepl
% generate normals
vetZ = nudt - b + sidt*randn(1,NSteps);
LogPath = cumsum([log(S0), vetZ]);
Path = exp(LogPath);
jcrossed = min(find( Path <= Sb ));
if not(isempty(jcrossed))
NCrossed = NCrossed + 1;
TBreach = jcrossed - 1;
Times(NCrossed) = TBreach * dt;
StockVals(NCrossed) = Path(jcrossed);
ISRatio(NCrossed) = exp( TBreach*b^2/2/sigma^2/dt
+b/sigma^2/dt*sum(vetZ(1:TBreach)) - TBreach*b/sigma^2*(r
- sigma^2/2));
end
end
Outcome
randn('seed',0);
[DOCallMCCondIS0,CI2,NCrossed2]=DOCallMCCondIS(S0,X,r,T,s
igma,Sb,NStep,NRepl,bp0);
randn('seed',0);
[DOCallMCCondIS20,CI3,NCrossed3]=DOCallMCCondIS(S0,X,r,T,
sigma,Sb,NStep,NRepl,bp20);
randn('seed',0);
[DOCallMCCondIS50,CI4,NCrossed4]=DOCallMCCondIS(S0,X,r,T,
sigma,Sb,NStep,NRepl,bp50);
randn('seed',0);
[DOCallMCCondIS200,CI5,NCrossed5]=DOCallMCCondIS(S0,X,r,T
,sigma,Sb,NStep,NRepl,bp200);
DOCallMCCondIS0
CI2
NCrossed2
DOCallMCCondIS20
CI3
NCrossed3
DOCallMCCondIS50
CI4
NCrossed4
DOCallMCCondIS200
CI5
NCrossed5
end
Outcome
二、Lookback Options
% AsianMC.m
function [C,CI] =
LookbackMC_call(S0,r,T,sigma,NSamples,NRepl)
Payoff = zeros(NRepl,1);
randn('seed',0);
for i=1:NRepl
Path=AssetPaths1(S0,r,sigma,T,NSamples,1);
Code S_min=min(Path); % find the minimum asset price
Payoff(i) = Path(NSamples) - S_min; % always greater
than 0
end
% AsianMCCV.m
function [C,CI] =
LookbackMCCV_call(S0,r,T,sigma,NSamples,NRepl,NPilot)
% MC run
ControlVars = zeros(NRepl,1);
for i=1:NRepl
StockPath = AssetPaths1(S0,r,sigma,T,NSamples,1);
S_min=min(StockPath); % find the minimum
Payoff = exp(-r*T) * (StockPath(NSamples) - S_min); %
find the discounted payoff
ControlVars(i) = Payoff + c * (sum(StockPath) -
ExpSum);
end
[C,~,CI] = normfit(ControlVars);
end
Outcome
% AsianMC.m
function [P,CI] =
LookbackMC_put(S0,r,T,sigma,NSamples,NRepl)
Payoff = zeros(NRepl,1);
randn('seed',0);
for i=1:NRepl
Path=AssetPaths1(S0,r,sigma,T,NSamples,1);
S_max=max(Path); % find the maximum asset price
Code
Payoff(i) = S_max - Path(NSamples); % always greater
than 0
end
% AsianMCCV.m
function [P,CI] =
LookbackMCCV_put(S0,r,T,sigma,NSamples,NRepl,NPilot)
% MC run
ControlVars = zeros(NRepl,1);
for i=1:NRepl
StockPath = AssetPaths1(S0,r,sigma,T,NSamples,1);
S_max=max(StockPath); % find the maximum
Payoff = exp(-r*T) * (S_max - StockPath(NSamples)); %
find the discounted payoff
ControlVars(i) = Payoff + c * (sum(StockPath) -
ExpSum);
end
[P,~,CI] = normfit(ControlVars);
end
Outcome
首先利用HaltonPaths函數,先模擬整個股價矩陣。然後找出每條路徑中的最高股價SMax,
計算到期時的Payoff。最後再將得到的回顧行買權報償折現到今天,計算模擬NRep1次後報酬
的平均值,就可以得到回顧型買權目前的價值。
LookbackHalton.m
%
function[P,CI]=LookbackHalton(S0,r,T,sigma,NSteps,NRep1)
Payoff=zeros(NRep1,1);
Path=HaltonPaths(S0,r,sigma,T,NSteps,NRep1);
SMax=max(Path,[],2);
Payoff=max(0,SMax-Path(NSteps+1));
[P,aux,CI]=nornfit(exp(-r*T)*Payoff);
end
%HaltonPaths.m
Code function SPaths=HaltonPaths(S0,mu,sigma,T,NSteps,NRep1)
dt=T/NSeps;
nudt=(mu-0.5*sigma^2)*dt;
sidt=sigma*sqrt(dt);
NRep1=2*ceil(NRep1/2);
%Use Box Muller to generate standard normals
RandMat=zeros(NRep1,NSteps);
seeds=myprimes(2*NSteps);
Base1=seeds(1:NSteps);
Base2=seeds((NSteps+1):(2*NSteps));
for i=1:NSteps
H1=GetHalton(NRep1/2,Base1(i));
H2=GetHalton(NRep1/2,Base2(i));
VLog=sqrt(-2*log(H1));
Norm1=VLog.*cos(2*pi*H2);
Norm2=VLog.*sin(2*pi*H2);
RandMat(:,i)=[Norm1;Norm2];
end
Increments=nudt+sidt*RandMat;
LogPaths=cumsum([log(S0)*ones(NRep1,1),Increments],2);
Spaths=exp(LogPaths);
end
Outcome