4/15/2021 HW5 E[1 - JXp\WeU NoWebook
localhoVW:8888/noWebookV/DoZnloadV/HomeZoUk/HW5 E[1.ip\nb# 1/5
IQ¦[39]:
:L[[PUN!
:PT\SH[PVUPZHSZV\ZLKPU[OLÄUHUJPHSTHYRL[-VYL_HTWSLZPT\SH[PVUJHUIL\ZLK[VZPT\SH[L
Z[VJRWYPJL:PUJL[OLZ[VJRWYPJLPZ\Z\HSS`HZZ\TLK[VILJVU[PU\V\ZS`JOHUNPUNWLVWSL\Z\HSS`
KPZJYL[PaL[OL[PTLPU[VZTHSSPU[LY]HSZH[ HUKZPT\SH[LZ[VJRWYPJLH[LHJO[PTLWVPU[
8B7VPU[ZD
;VWYLWHYLMVYZ[VJRWYPJLZPT\SH[PVUSL[ZÄYZ[SVVRH[HZPTWSLYWYVJLZZ!)YV^UPHUTV[PVUWYVJLZZ
;OLZ[HUKHYK)YV^UPHUTV[PVUJHUILKLÄULKHZMVSSV^Z!
MVYHU`NP]LU[^V[PTLWVPU[Z HUK
^OLYL PZHUVYTHSKPZ[YPI\[PVU^P[OHZ[OLTLHUHUK HZ[OL]HYPHUJL
5V[PJL[OLZPTPSHYP[`IL[^LLU)YV^UPHUTV[PVUHUKHOVTVNLULV\Z7VPZZVUWYVJLZZ!
>LJHUZPT\SH[L)YV^UPHUTV[PVU\ZPUN[OLMVSSV^PUNHSNVYP[OT!
:[HY[^P[O HUK
MVY [V !
ZHTWSL MYVT
\WKH[L \ZPUN
)HZLKVU[OLWYL]PV\ZHSNVYP[OT
:PT\SH[L H[
#This imports all the packages \ou need for the homeZork
#Please run this first
import QXmS\ as QS
import VciS\.VSecial as VSVS
import maWSlRWlib.S\SlRW as SlW
%maWSlRWlib iQliQe
import V\mS\
import VciS\.VWaWV as VSVW
import VimS\
import cRS\
!SiS iQVWall h\SeURSW -T
import h\SeURSW
4/15/2021 HW5 E[1 - JXp\WeU NoWebook
localhoVW:8888/noWebookV/DoZnloadV/HomeZoUk/HW5 E[1.ip\nb# 2/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oZnloadV/HomeZoUk/HW5 E[1.ip\nb# 3/5
IQ¦[25]:
IQ¦[26]:
IQ¦[27]:
8B7VPU[ZD
(ZZ\TL[OH[^L^HU[[V\ZLZPT\SH[PVU[VLZ[PTH[L ^OLU
/LYL PZ[OLH]LYHNLWYPJLVMZ[VJRWYPJLIL[^LLU
HUK
.LULYH[LZHTWSLZVM \ZPUN -VYLHJOYV\UK[OLZHTWSLVM
JHUILHWWYV_PTH[LK\ZPUN[OLH]LYHNLVMHSS[OLZ[VJRWYPJLZ^LJHSJ\SH[LKIL[^LLUHUK;
)HZLK[OLZLZHTWSLZYLWVY[[OLJLU[LYHUK[OL^PK[OVMH JVUÄKLUJLPU[LY]HSMVY
(WWS`[OLHU[P[OL[PJTL[OVK[V HUKYLWVY[[OLJLU[LYHUK[OL^PK[OVMH JVUÄKLUJL
PU[LY]HSMVY IHZLKVUNLULYH[PUNNLULYH[LZHTWSLZVM \ZPUN
IQ¦[28]:
IQ¦[29]:
8B7VPU[ZD
(ZZ\TL^L^HU[[VLZ[PTH[L ^OLU
>P[OV\[\ZPUNHU`]HYPHUJLYLK\J[PVU[LJOUPX\LNLULYH[LZHTWSLZVM
\ZPUN )HZLK[OLZLZHTWSLZYLWVY[
[OLJLU[LYHUK[OL^PK[OVMH JVUÄKLUJLPU[LY]HSMVY
ZHTWSLZVM \ZPUN )HZLK[OLZL
ZHTWSLZYLWVY[[OLJLU[LYHUK[OL^PK[OVMH JVUÄKLUJLPU[LY]HSMVY
#generate S_t
def S_W(W,a, mX, Vigma2):
return SW
##run the S_t(t) 5 times and plot the trajector\ for each case
QS.UaQdRm.Veed(10)
#Zithout using Yariance reduction
QS.UaQdRm.Veed(10)
#antithetic method
QS.UaQdRm.Veed(10)
4/15/2021 HW5 E[1 - JXp\WeU NoWebook
localhoVW:8888/noWebookV/DoZnloadV/HomeZoUk/HW5 E[1.ip\nb# 4/5
IQ¦[30]:
IQ¦[31]:
8B7VPU[ZD
(ZZ\TL[OH[HWLYZVU^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[Z\ZLPTWVY[HUJLZHTWSPUN[VYLK\JL[OL]HYPHUJL>OLUZHTWSPUN PUZ[LHKVMZHTWSPUNMYVT
SL[ZZHTWSL ZV[OH[P[PZTVYLSPRLS`MVY\Z[V
ZLL
(ZZ\TL[OH[ \ZLPTWVY[HUJLZHTWSPUN[VYLK\JL[OL]HYPHUJLPU8,Z[PTH[L
IHZLKVUZPT\SH[PUN[OLZ`Z[LT[PTLZ
)HZLKVU[OLJLU[YHSSPTP[[OLVYLTJHSJ\SH[L[OL^PK[OVM[OL JVUÄKLUJLPU[LY]HSVM
9LWVY[IV[O]HS\LZ
IQ¦[34]:
8B7VPU[ZD
>LJHU\ZLO`WLYVW[[VÄUK[OLILZ[WHYHTL[LY
:LHYJO IL[^LLUHUK\ZPUN h\SeURSW [VYLK\JL[OL^PK[OVM[OL JVUÄKLUJL
PU[LY]HSVM IHZLKVUZHTWSLZ>OLUKVPUN[OLZLHYJOWLYMVYT WSe
HSNVYP[OTHUK\ZLP[LYH[PVUZ5VULLK[VZL[\WLHYS`Z[VWWPUN9LWVY[[OLILZ[
9LWVY[[OLLZ[PTH[L
)HZLKVUJLU[YHSSPTP[[OLVYLTJHSJ\SH[L[OL^PK[OVM[OL JVUÄKLUJLPU[LY]HSVM
9LWVY[[OL]HS\L
IQ¦[35]:
IQ¦[36]:
IQ¦[37]:
IQ¦[38]:
#importance sampling
QS.UaQdRm.Veed(10)
##h\opt to find optimal alpha
##report the best alpha
#use more samples to estimate the probabilit\ and Zidth of confidence inter