Sei sulla pagina 1di 10

金融商品設計與評價 HW12

第六組

一、​Importance Sampling

Down-and-Out Call Option

延續上週所做的 ​DOCallMCCond ​,使用 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);

% Generate asset paths and payoffs for the down and in


option
NCrossed = 0;
Payoff = zeros(NRepl,1);
Times = zeros(NRepl,1);
StockVals = zeros(NRepl,1);
Code ISRatio = zeros(NRepl,1);

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

if​ (NCrossed > 0)


[Caux,Paux] =
blsprice(StockVals(1:NCrossed),X,r,T-Times(1:NCrossed),si
gma);
Payoff(1:NCrossed) = exp(-r*Times(1:NCrossed)) .*
Caux .* ISRatio(1:NCrossed);
end
[Cdo,~,CI] = normfit(Call - Payoff);
end

% S0=50; X=52; r=0.1; T=2/12; sigma=0.4; Sb=40; NStep=60;


NRepl=10000; bp0=0; bp20=20; bp50=50; bp200=200;

Outcome

Compare the Effects of Importance Sampling

比較 ​bp ​分別在0、20、50及200時,對跨過次數 ​NCrossed ​的影響。從結果可知,當 ​bp


越大,​ ​NCrossed 也會越大,與 ​Down-and-Out Put 的結果一致。

% CompDOPutMCCondIS.m Compare DOPutMC,MCcond


function​ CompDOCallMCCondIS()
S0=50; X=52; r=0.1; T=2/12; sigma=0.4; Sb=40; NStep=60;
Code NRepl=10000;
bp0=0; bp20=20; bp50=50; bp200=200;

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

Lookback Call Option - Crude MC

回顧型選擇權的報酬是路經相依,所以必須先利用先前建立的 ​AssetPaths1 ​函數得到股價


路徑。接著找出每條路徑中最低股價 ​S_min​,然後再求出一次模擬所得到的報酬。利用一個
迴圈計算 ​NRepl ​次模擬,接著將每一次模擬所得到的報酬折現到今天,再計算報酬平均值,
就可以得到回顧型買權目前的價值。

% 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

[C,~,CI] = normfit( exp(-rdi*T) * Payoff);


end

% S0=50; X=50; r=0.1; T=5/12; sigma=0.4; NSamples=5;


NRepl=50000;
Outcome

Lookback Call Option - Control Variates

用 ​ControlVars(i) = Payoff + c * (sum(StockPath) - ExpSum) ​設定 Control


Variate,則此新變數的期望值與 ​Payoff ​相同,但變異會減少。因此,可縮小 Confidence
Interval 的寬度。

% AsianMCCV.m
function​ [C,CI] =
LookbackMCCV_call(S0,r,T,sigma,NSamples,NRepl,NPilot)

% pilot replications to set control parameter


TryPath=AssetPaths1(S0,r,sigma,T,NSamples,NPilot);
StockSum = sum(TryPath,2); ​% sum each row
TryS_min=min(TryPath,[],2); ​% find the minimum in each
row
TryPayoff = exp(-r*T) * (TryPath(:,end) - TryS_min); ​%
calculate the discounted payoff
MatCov = cov(StockSum, TryPayoff);
c = - MatCov(1,2) / var(StockSum);
Code
dt = T / NSamples;
ExpSum = S0 * (1 - exp((NSamples + 1)*r*dt)) / (1 -
exp(r*dt));

% 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

% S0=50; X=50; r=0.1; T=5/12; sigma=0.4; NSamples=5;


NRepl=45000; NPilot=5000;

Outcome

Lookback Put Option - Crude MC

回顧型選擇權的報酬是路經相依,所以必須先利用先前建立的 ​AssetPaths1 ​函數得到股價


路徑。接著找出每條路徑中最高股價 ​S_max​,然後再求出一次模擬所得到的報酬。利用一個
迴圈計算 ​NRepl ​次模擬,接著將每一次模擬所得到的報酬折現到今天,再計算報酬平均值,
就可以得到回顧型賣權目前的價值。

% 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

[P,~,CI] = normfit( exp(-r*T) * Payoff);


end

% S0=50; X=50; r=0.1; T=5/12; sigma=0.4; NSamples=5;


NRepl=50000;
Outcome

Lookback Put Option - Control Variates

一樣地,用 ​ControlVars(i) = Payoff + c * (sum(StockPath) - ExpSum) ​設定


Control Variate,則此新變數的期望值與 ​Payoff ​相同,但變異會減少。因此,可縮小
Confidence Interval 的寬度。

% AsianMCCV.m
function​ [P,CI] =
LookbackMCCV_put(S0,r,T,sigma,NSamples,NRepl,NPilot)

% pilot replications to set control parameter


TryPath=AssetPaths1(S0,r,sigma,T,NSamples,NPilot);
StockSum = sum(TryPath,2); ​% sum each row
TryS_max=max(TryPath,[],2); ​% find the maximum in each
row
TryPayoff = exp(-r*T) * (TryS_max - TryPath(:,end)); ​%
calculate the discounted payoff
MatCov = cov(StockSum, TryPayoff);
c = - MatCov(1,2) / var(StockSum);
Code
dt = T / NSamples;
ExpSum = S0 * (1 - exp((NSamples + 1)*r*dt)) / (1 -
exp(r*dt));

% 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

% S0=50; X=50; r=0.1; T=5/12; sigma=0.4; NSamples=5;


NRepl=45000; NPilot=5000;

Outcome

Lookback Call Option -Halton

首先利用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

Potrebbero piacerti anche