At time t the spot price is Pn i¼1qixiðtÞ.. 6.7.1 Naive Monte Carlo The procedure ‘basket’ estimates c using naive Monte Carlo.. asset price at time t; # sigma[i1]=volatility of asset i1
Trang 1‘K’=55, ‘sigma’=0.1, ‘n’=16
‘# replications’=100, ‘paths per replication’=2500, ‘strata’=100
‘point estimate of price’=0.2023819565
‘estimated standard error’=0.00002354664402
13753
¼ 0:02171666756
‘K’=50, ‘sigma’=0.1, ‘n’=16
‘# replications’=100, ‘paths per replication’=2500, ‘strata’=100
‘point estimate of price’=1.919506766
‘estimated standard error’=0.00006567443424
13753
¼ 0:01089879722
‘K’=45, ‘sigma’=0.1, ‘n’=16
‘# replications’=100, ‘paths per replication’=2500, ‘strata’=100
‘point estimate of price’=6.055282128
‘estimated standard error’=0.0001914854216
Consider a basket (or portfolio) consisting of n assets The basket contains a
quantity qi of asset i where i¼ 1; ; n Let r; i; fXiðuÞ; u T ; 0 ug
denote the risk-free interest rate, volatilty, and prices in [0,T ] of one unit of
the ith asset At time t the spot price is Pn
i¼1qixiðtÞ Let denote thecorrelation between the returns on the assets and let the Cholesky decomposi-
tion of this beb bT ¼ r Then the price of a European call option at time t
with strike price K and exercise time T is the discounted expected payoff in a
risk-neutral world, that is
whereW Nð0; rÞ: P ut W ¼ bZ where Z Nð0; IÞ
6.7.1 Naive Monte Carlo
The procedure ‘basket’ estimates c using naive Monte Carlo It performs
npathreplications of the payoff Ensure that the procedure ‘STDNORM’
in Appendix 6.1 and the Linear Algebra and statistics packages are loaded
Trang 2> basket:=proc(r,x,sigma,q,rho,T,t,n,npath,K) localb,c1,c2,i1,i2,mean,R,spot,stderr,theta,w,xav,xi,z; globali,X2;
#
# Computes call price for basket option using naive Monte Carlo;
# load STDNORM and Linear Algebra package;
#
# r=risk-free interest rate;
# x[i1]= i1th asset price at time t;
# sigma[i1]=volatility of asset i1;
# q[i1]=quantity of asset i1 in basket;
# rho=correlation matrix for returns between assets;
# T=exercise time;
# npath=number of paths
# K=strike price;
#spot:=Transpose(x).q;
for i2 from 1 to npath do;
for i1 from 1 to n do;
print("point estimate of price"=mean);
print("estimated standard error"=stderr);
end proc:
2666666666666666666666666666666666666666666664
Trang 3‘K’=660, ‘spot’=660., ‘r’=0.04, ‘n’=4, ‘t’=0, ‘T’=0.5,
‘x’ ¼
52:543
264
375; ‘q’ ¼
20806040
264
375,
‘sigma’¼
0:30:20:30:4
264
375; ‘rho’ ¼
1 0:7 0:5 0:30:7 1 0:6 0:20:5 0:6 1 0:40:3 0:2 0:4 1
264
375
‘# paths’ = 10000
‘point estimate of price’ = 47.20505098
‘estimated standard error’ = 0.7072233067
‘K’=600, ‘spot’=660., ‘r’=0.04, ‘n’=4, ‘t’=0, ‘T’=0.5,
‘x’ ¼
52:543
264
375; ‘q’ ¼
20806040
264
375,
Trang 4‘sigma’ ¼
0:30:20:30:4
264
375; ‘rho’ ¼
1 0:7 0:5 0:30:7 1 0:6 0:20:5 0:6 1 0:40:3 0:2 0:4 1
264
375
‘# paths’ = 10000
‘point estimate of price’ = 84.02729573
‘estimated standard error’ = 0.8807106819
266666664
> K:=720;seed:=randomize(9624651);basket(r,x,sigma,q,rho,T,t,n,npath,K);
K:=720seed:=9624651
‘K’= 720, ‘spot’=660., ‘r’=0.04, ‘n’=4, ‘t’=0, ‘T’=0.5,
‘x’ ¼
52:543
264
375; ‘q’ ¼
20806040
264
375,
‘sigma’ ¼
0:30:20:30:4
264
375; ‘rho’ ¼
1 0:7 0:5 0:30:7 1 0:6 0:20:5 0:6 1 0:40:3 0:2 0:4 1
264
375
‘# paths’ = 10000
‘point estimate of price’ = 23.48827444
‘estimated standard error’ = 0.5139235861
2666666666666666666664
[ Now change the vector of volatilities
> sigma:=Vector([0.05,0.1,0.15,0.05]);
:¼
0:050:10:150:05
264
375
266664
> K:=660;seed:=randomize(9624651);basket(r,x,sigma,q,rho,T,t,n,npath,K);
K:=600;seed:=randomize(9624651);basket(r,x,sigma,q,rho,T,t,n,npath,K);
K:=720;seed:=randomize(9624651);basket(r,x,sigma,q,rho,T,t,n,npath,K);
266666
Trang 5K :¼ 660seed :¼ 9624651
‘K’=660, ‘spot’=660., ‘r’=0.04, ‘n’=4, ‘t’=0, ‘T’=0.5,
‘x’ ¼
52:543
264
375; ‘q’ ¼
20806040
264
375,
‘sigma’ ¼
0:050:10:150:05
264
375; ‘rho’ ¼
1 0:7 0:5 0:30:7 1 0:6 0:20:5 0:6 1 0:40:3 0:2 0:4 1
264
375
‘# paths’ = 10000
‘point estimate of price’ = 22.73700052
‘estimated standard error’ = 0.2834997907
K :¼ 600seed :¼ 9624651
‘K’=600, ‘spot’=660., ‘r’=0.04, ‘n’=4, ‘t’=0, ‘T’=0.5,
‘x’ ¼
52:543
264
375; ‘q’ ¼
20806040
264
375,
‘sigma’ ¼
0:050:10:150:05
264
375; ‘rho’ ¼
1 0:7 0:5 0:30:7 1 0:6 0:20:5 0:6 1 0:40:3 0:2 0:4 1
264
375
‘# paths’ = 10000
‘point estimate of price’ = 71.67610118
‘estimated standard error’ = 0.3903638189
K :¼ 720seed :¼ 9624651
‘K’=720, ‘spot’=660., ‘r’=0.04, ‘n’=4, ‘t’=0, ‘T’=0.5,
‘x’ ¼
52:543
264
375; ‘q’ ¼
20806040
264
375,
‘sigma’ ¼
0:050:10:150:05
264
375; ‘rho’ ¼
1 0:7 0:5 0:30:7 1 0:6 0:20:5 0:6 1 0:40:3 0:2 0:4 1
264
375
Trang 6‘# paths’ = 10000
‘point estimate of price’ = 2.744216261
‘estimated standard error’ = 0.1003118091
2664
b0bq
The procedure ‘basketimppoststratv2’ below implements these two iance reduction devices See Table 6.3 in the text for the variance reduc-tion ratios achieved
Trang 7# Computes call price for basket option using importance
sampling with post stratification
# load STDNORM, Linear Algebra package, and Statistics
package
#
# r=risk-free interest rate;
# x[i1]= i1th asset price at time t;
# sigma[i1]=volatility of asset i1;
# q[i1]:=quantity of asset i1;
# rho[i1, j]:=correlation between returns on assets i1 and j;
# T=exercise time;
# m=number of strata
# npath=number of paths in one replication; should be at
least 20*m for post stratification to be efficient;
# K=strike price;
# p=number of replications;
# upper=an upper bound for lambda;
# f[j]=number of paths falling in stratum j in one
Trang 8for jj from 1 to p do:
theta:=0;
for j from 1 to m do s[j]:=0;f[j]:=0 end do;
for i2 from 1 to npath do;
print("K"=K,"spot"=spot,"r"=r,"n"=n,"t"=t,"T"=T,"x"=x,
"q"=q,"sigma"=sigma,"rho"=rho);
print("# replications"=p,"paths perreplication"=npath,"strata"=m);
print("point estimate of price"=mean);
print("estimated standard error"=stderr);
2666666666666666666666666666666666666666666666666666
Trang 9375
‘K’=660, ‘spot’=660., ‘r’=0.04, ‘n’=4, ‘t’=0, ‘T’=0.5,
‘x’ ¼
52:543
264
375; ‘q’ ¼
20806040
264
375,
‘sigma’ ¼
0:30:20:30:4
264
375; ‘rho’ ¼
1 0:7 0:5 0:30:7 1 0:6 0:20:5 0:6 1 0:40:3 0:2 0:4 1
264
375
‘# replications’ = 25, ‘paths per replication’ = 400, ‘strata’ = 20
‘point estimate of price’ = 48.03048912
‘estimated standard error’ = 0.04919665583
‘approximate 95% confidence interval for reciprocal variance
Trang 10> seed:=randomize(9624651);K:=600:basketimppoststratv2(r,x,sigma,q,rho,T,t,n,m,npath,K,p,upper);
seed :¼ 9624651
‘lambda’ ¼ 3:589486716; ‘beta’ ¼
0:5897151083850928900:2906095186127429790:3924690008997681610:230185997913606666
264
375
‘K’=600, ‘spot’=660., ‘r’=0.04, ‘n’=4, ‘t’=0, ‘T’=0.5,
‘x’ ¼
52:543
264
375; ‘q’ ¼
20806040
264
375,
‘sigma’ ¼
0:30:20:30:4
264
375; ‘rho’ ¼
1 0:7 0:5 0:30:7 1 0:6 0:20:5 0:6 1 0:40:3 0:2 0:4 1
264
375
‘# replications’=25, ‘paths per replication’=400, ‘strata’=20
‘point estimate of price’=85.18136772
‘estimated standard error’=0.06450488957
‘approximate 95% confidence interval for reciprocal variance of error=’,
124.1839457,
‘to’, 394.1881451
26666666666666666666666666666
> seed:=randomize(9624651);K:=720:basketimppoststratv2(r,x,sigma,q,rho,T,t,n,m,npath,K,p,upper);
seed :¼ 9624651
‘lambda’ ¼ 6:065827969; ‘beta’ ¼
0:9965520647393203420:4910973310477080860:6632283752469805280:388988391569389748
264
375
‘K’=720, ‘spot’=660., ‘r’=0.04, ‘n’=4, ‘t’=0, ‘T’=0.5,
‘x’ ¼
52:543
264
375; ‘q’ ¼
20806040
264
375,
266666666666666666664
Trang 11‘sigma’ ¼
0:30:20:30:4
264
375; ‘rho’ ¼
1 0:7 0:5 0:30:7 1 0:6 0:20:5 0:6 1 0:40:3 0:2 0:4 1
264
375
‘# replications’=25, ‘paths per replication’=400, ‘strata’=20
‘point estimate of price’=24.03898507
‘estimated standard error’=0.02821965008
‘approximate 95% confidence interval for reciprocal variance of
264
375
264
375
‘K’=660, ‘spot’=660., ‘r’=0.04, ‘n’=4, ‘t’=0, ‘T’=0.5,
‘x’ ¼
52:543
264
375; ‘q’ ¼
20806040
264
375,
‘sigma’ ¼
0:050:10:150:05
264
375; ‘rho’ ¼
1 0:7 0:5 0:30:7 1 0:6 0:20:5 0:6 1 0:40:3 0:2 0:4 1
264
375
‘# replications’=25, ‘paths per replication’=400, ‘strata’=20
‘point estimate of price’=23.09053636
Trang 12‘‘estimated standard error’’= 0.009617279541
‘approximate 95% confidence interval for reciprocal variance of error =’,
5586.582894, ‘‘to’’, 17733.08729
266
> seed:=randomize(9624651);K:=600:basketimppoststratv2(r,x,sigma,q,rho,T,t,n,m,npath,K,p,upper);
seed :¼ 9624651
‘lambda’ ¼ 5:407253416 ‘beta’ ¼
0:3176870924067420880:2193666225964937260:2488741512073879280:0442439933277393033
264
375
‘K’=600, ‘spot’=660., ‘r’=0.04, ‘n’=4, ‘t’=0, ‘T’=0.5,
‘x’ ¼
52:543
264
375; ‘q’ ¼
20806040
264
375,
‘sigma’ ¼
0:050:10:150:05
264
375; ‘rho’ ¼
1 0:7 0:5 0:30:7 1 0:6 0:20:5 0:6 1 0:40:3 0:2 0:4 1
264
375
‘# replications’=25, ‘paths per replication’=400, ‘strata’=20
‘point estimate of price’=72.24856764
‘estimated standard error’=0.03901100494
‘approximate 95% confidence interval for reciprocal variance of error =’,
339.5286687, ‘to’, 1077.741373
266666666666666666666666666
> seed:=randomize(9624651);K:=720:basketimppoststratv2(r,x,sigma,q,rho,T,t,n,m,npath,K,p,upper);
seed :¼ 9624651
‘lambda’ ¼ 20:43485296; ‘beta’ ¼
1:200589009091433290:8290206380612443740:9405341851408761670:167204942779322074
264
375
266666666666664
Trang 13‘K’=720, ‘spot’=660., ‘r’=0.04, ‘n’=4, ‘t’=0, ‘T’=0.5,
‘x’ ¼
52:543
264
375; ‘q’ ¼
20806040
264
375,
‘sigma’ ¼
0:050:10:150:05
264
375; ‘rho’ ¼
1 0:7 0:5 0:30:7 1 0:6 0:20:5 0:6 1 0:40:3 0:2 0:4 1
264
375
‘# replications’ = 25, ‘paths per replication’ = 400, ‘strata’ = 20
‘point estimate of price’ = 2.865814172
‘estimated standard error’ = 0.002971217579
‘approximate 95% confidence interval for reciprocal variance of error=’,
The procedure ‘meanreverting’ generates a volatility processfðtÞg in ½0; T at
t¼ 0; ; nh, where ðtÞ ¼ eYðtÞandYðtÞ is an Ornstein–Uhlenbeck process,
dY ¼ ðm Y Þdt þ dB;
where 0 < ; and fBðtÞg is a standard Brownian motion Remember to
load ‘STDNORM’ in Appendix 6.1 Define 2¼ 2/ð2Þ: There is a
and so
EððtÞÞ ¼ exp½yð0Þe tþ ð1 e tÞm þ 0:5 2ð1 e2 tÞ
> with(stats);
Warning, these names have been redefined: anova, describe,
fit, importdata, random, statevalf, statplots, transform
Trang 14> meanreverting:=proc(T,n,seed,alpha,m,nu,y0) localh,P,j,z,a,b,d,A,Y;
#
# Procedure generates a list [{[j*h,exp(Y(j*h))],j=0 n}]where Y(j*h) is the position of the OU process (withparameters alpha,m,nu) at time jh
#global i,X2;
i:=false;
randomize(seed);
h:=T/n;
Y:=y0;P[0]:=[0,evalf(exp(y0))];
Trang 15A slow mean reverting volatility process(alpha=0.5) with the expected volatility
0.130.14
0.110.12
Notice in the realization above that the volatility is taking an exceptionally
long time to reach a value equal to its asymptotic expectation Now increase
from 0.5 to 5 Observe in the plot below that the reversion to the mean is
far more rapid
PLOT(CURVES(v1,v2),TITLE("A faster mean reverting volatility
process\n (alpha=5) with the expected
Trang 16A faster mean reverting volatility process(alpha=5) with the expected volatility0.3
Trang 17PLOT(CURVES(v1,v2),TITLE("A fast mean reverting volatility
process \n (alpha=50) with the expected
A fast mean reverting volatility process(alpha=50) with the expected volatility0.3
Trang 19Appendix 7: Discrete event simulation
7.1 G/G/1 queue simulation using the regenerative technique
For procedure ‘gg1’, the aim is to estimate the long-run average line length.Line length is the number of customers in the queueing system It includes anycustomer currently being served (The queue length is the number of customerswaiting for service.) The program assumes that interarrival times are indepen-dently Weibull distributed with Pðx < XÞ ¼ exp½ðxÞ for 0 < ; 0 < x,and that service durations are independently distributed with complementarycumulative distribution Pðx < DÞ ¼ exp½ðxÞ for 0 < ; 0 < x The expec-tation and standard deviation of these are printed out For stationary beha-viour, the mean interarrival time should be greater than the mean serviceduration Other distributions can be used by suitable modifications to theprogram The three-phase method for discrete event simulation is used Thebound state changes are (i) customer arrival and (ii) customer departure Theonly conditional state change is (iii) start customer service Separate streams areused for the two types of sampling activity This has benefits when performingantithetic replications The regeneration points are those instants at which thesystem enters the empty and idle state and n regeneration cycles are simulated
Trang 20> gg1:=proc(lambda,mu,gam,beta,n,seed1,seed2) localrho,seeda,seedb,m,clock,L,Lp,a,d,reward,k,tau,prev,delta,u,v,R,tau,TAU,b1,b2,a1,a2,a3,a4,a5,a6,f,stderr,a7,gam1,beta1,gam2,gam3,beta2,beta3,v1;
for m from 1 to n do;
# START OF NEW CYCLEtau:=0;
tau:=min(a,d);
delta:=tau-tauprev;
reward:=reward+delta*L;
# CHECK FOR ’END OF CYCLE’
if tau=a and L=0 then break end if;
# CHECK FOR BOUND ACTIVITY ’ARRIVAL’
if tau=a thenL:=L+1;
Trang 21d:=infinityend if;
# CHECK FOR CONDITIONAL ACTIVITY ’START SERVICE’
if L >0 and d=infinity then;
# TAU[m]=LENGTH OF m th REGENERATIVE CYCLE
# R[m]=CYCLE ’REWARD’=int(L(t),t=0 TAU[m]), where L(t)IS
NUMBER IN SYSTEM AT TIME t, AND t IS THE ELAPSED TIME SINCE
a7:=a6*(1+(a5/a1/a2-a4/a2/a2)/n); #a7 IS MODIFIED RATIO
ESTIMATOR OF TIN, M.(1965),JASA, 60, 294-307
f:=a3+a4*a7^2-2*a7*a5;
stderr:=sqrt(f/n)/a2;
print("mean cycle length"=a2);
print("estimate of mean line length"=a7);
print("95% Conf Interval for mean line
‘Mean interarrival time’=1 ‘Std dev of interarrival time’=0.5000000000
‘Mean service duration’=0.5000000000, ‘Std dev of service duration’=0.5000000000
‘mean cycle length’=2.003817572
Trang 22‘estimate of mean line length’=0.9993680613
‘95% Confidence interval for mean line length’=0.9503482328,’to’, 1.048387890
‘ \ _’
‘Mean interarrival time’=1., ‘Std dev of interarrival time’=0.6666666667
‘Mean service duration’=0.6666666667, ‘Std dev of service duration’=0.6666666667
‘mean cycle length’=3.014993555
‘estimate of mean line length’=2.030197245
‘95%Confidence interval for mean line length’=1.903465437, ‘to’, 2.156929053
‘ \ ’
‘Mean interarrival time’=1., ‘Std dev of interarrival time’=0.9090909091
‘Mean service duration’=0.9090909091, ‘Std dev of service duration’=0.9090909091
‘mean cycle length’=11.44855979
‘estimate of mean line length’=10.32733293
‘95% Confidence interval for mean line length’=9.087027523, ‘to’, 11.56763834
2
6
> gg1(1,2,1,1,10000,246978,71586);
print(" ");
gg1(1,1.5,1,1,10000,246978,71586);
print(" ");
gg1(1,1.1,1,1,10000,246978,71586);
‘Mean interarrival time’=1., ‘Std dev of interarrival time’=0.5000000000
‘Mean service duration’=0.5000000000, ‘Std dev of service duration’=0.5000000000
‘mean cycle length’=1.980971270
‘estimate of mean line length’=1.006757945
‘95% Confidence interval for mean line length’=0.9547306296, ‘to’, 1.053785260
‘ _\ _’
‘Mean interarrival time’=1., ‘Std dev of interarrival time’=0.6666666667
‘Mean service duration’=0.6666666667, ‘Std dev of service duration’=0.6666666667
‘mean cycle length’=2.958999958
‘estimate of mean line length’=1.952424988
‘95% Confidence interval for mean line length’=1.839236291, ‘to’, 2.065613685
‘ ’