<a href="https://colab.research.google.com/github/Bertha-ding/20MA573-yuning-ding/blob/master/hw/hw11.ipynb" target="_parent"></a>


```
import scipy.stats as ss
import numpy as np
c = ss.norm(0,1).cdf(-2)
print("the exact price is", c)
```

    the exact price is 0.022750131948179195



```
def OMC(N,alpha):
  s=0
  for i in range(N):
    if np.random.normal(0,1)<-2:
      s+=1
  return s/N
```


```
OMC(1000,2)
```




    0.028




```
def IS(N,alpha):
  s=0
  for i in range(N):
    A= np.random.normal(-alpha,1)
    if A<-2:
      s+= np.exp(alpha**2/2 + alpha*A)
  return s/N
```


```
IS(1000,2)
```




    0.022493176379587303




```
var_IS=0
var_omc=0
for i in range(10000):
  var_omc+= (c - OMC(1000,2))**2
  var_IS += (c - IS(1000,2))**2
  mse_omc = var_omc/10000
  mse_IS = var_IS/10000
print(mse_omc)
print(mse_IS)
```

    2.2159788036515605e-05
    1.235122055437548e-06



```
def MSE_OMC(alpha_hat,N):
  for i in range (N):
    x=ss.norm(0,1).cdf(-2)
  MSE_OMC = (1/N)*(x-x**2)
  return MSE_OMC
```


```
MSE_OMC(3,10000)
```




    2.2232563444519632e-06



\begin{equation}
\begin{aligned}
MSE(\hat{v}) &= var(\hat{v}) \\
&= \frac{1}{n} var(I(Y_{i} < - 2) e^{\frac{1}{2} \alpha^{2} + \alpha Y_{i}}) \\
&= \frac{1}{n} \{ \mathbb{E} [I(Y_{i} < - 2) e^{ \alpha^{2} + 2 \alpha Y_{i}}] - \Phi^{2}(-2) \}. \\
\end{aligned}
\end{equation}

\begin{equation}
\begin{aligned}
\mathbb{E} [I(Y_{i} < - 2) e^{ \alpha^{2} + 2 \alpha Y_{i}}] &= \int_{- \infty}^{-2} e^{\alpha^{2}+ 2 \alpha y}  \frac{1}{\sqrt{2 \pi}} e^{- \frac{(y + \alpha)^{2}}{2}} \, d y \\
&= \int_{- \infty}^{-2} \frac{1}{\sqrt{2 \pi}} e^{- \frac{y^{2} - \alpha y - \alpha^{2}}{2}} \, d y \\
&= \int_{- \infty}^{-2} \frac{1}{\sqrt{2 \pi}} e^{- \frac{(y - \alpha)^{2}}{2}}  e^{\alpha^{2}} \, d y  \\
&= e^{\alpha^{2}} \Phi(-2-\alpha),
\end{aligned}
\end{equation}

$$MSE(\hat{v}) = \frac{1}{n} \{e^{\alpha^{2}} \Phi(-2-\alpha) - \Phi^{2}(-2)\}.$$



```
def MSE_IS(alpha_hat,N):
  for i in range (N):
    x=ss.norm(0,1).cdf(-2)
    y=ss.norm(0,1).cdf(-2-alpha_hat)
    mse_IS = (1/N)*np.exp(alpha_hat**2)*y-(x**2)
  return mse_IS
```


```
MSE_IS(2,10000)
```




    -0.0005173955845382296




```
diff = MSE_OMC(3,10000)-MSE_IS(3,10000)
```


```
diff
```




    0.0005195594838295247



as we can see, as n is big enough, the mse of omc and IS is converge to 0, and under same alpha, the mse of IS is less than mse of omc.


```

```

09f12b20aad75fbe17c502091a1e6ee232159828
ipynb
Jupyter Notebook
hw/hw11.ipynb
Bertha-ding/20MA573-yuning-ding
21b8fb9596b4d72eff972643602bb8e55f26453c
MIT
hw/hw11.ipynb
Bertha-ding/20MA573-yuning-ding
21b8fb9596b4d72eff972643602bb8e55f26453c
MIT
hw/hw11.ipynb
Bertha-ding/20MA573-yuning-ding
21b8fb9596b4d72eff972643602bb8e55f26453c
MIT
Qwen/Qwen-72B
1. YES
2. YES