Skip to content

Commit 240e65f

Browse files
authored
Merge pull request #417 from QuantEcon/update_monte_carlo
[monte_carlo] updates and editorial suggestions
2 parents 8c53ec8 + 0b46db1 commit 240e65f

File tree

1 file changed

+61
-61
lines changed

1 file changed

+61
-61
lines changed

lectures/monte_carlo.md

+61-61
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ Suppose that, after analyzing the data, we guess that $S$ is well
8585
represented by a lognormal distribution with parameters $\mu, \sigma$ .
8686

8787
* $S$ has the same distribution as $\exp(\mu + \sigma Z)$ where $Z$ is standard normal.
88-
* we write this statement as $S \sim LN(\mu, \sigma)$.
88+
* We write this statement as $S \sim LN(\mu, \sigma)$.
8989

9090
Any good reference on statistics (such as
9191
[Wikipedia](https://en.wikipedia.org/wiki/Log-normal_distribution)) will tell
@@ -136,12 +136,12 @@ But fortunately there's an easy way to do this, at least approximately.
136136
This is the Monte Carlo method, which runs as follows:
137137

138138
1. Generate $n$ independent draws of $X_1$, $X_2$ and $X_3$ on a computer,
139-
1. Use these draws to generate $n$ independent draws of $S$, and
140-
1. Take the average value of these draws of $S$.
139+
1. use these draws to generate $n$ independent draws of $S$, and
140+
1. take the average value of these draws of $S$.
141141

142142
This average will be close to the true mean when $n$ is large.
143143

144-
This is due to the law of large numbers, which we discussed in {doc}`another lecture <lln_clt>`.
144+
This is due to the law of large numbers, which we discussed in {doc}`lln_clt`.
145145

146146
We use the following values for $p$ and each $\mu_i$ and $\sigma_i$.
147147

@@ -238,15 +238,15 @@ compute_mean_vectorized(n=10_000_000)
238238

239239

240240

241-
## Pricing a european call option under risk neutrality
241+
## Pricing a European call option under risk neutrality
242242

243243
Next we are going to price a European call option under risk neutrality.
244244

245245
Let's first discuss risk neutrality and then consider European options.
246246

247247

248248

249-
### Risk-Neutral Pricing
249+
### Risk-neutral pricing
250250

251251
When we use risk-neutral pricing, we determine the price of a given asset
252252
according to its expected payoff:
@@ -426,7 +426,7 @@ $$ \ln \frac{S_{t+1}}{S_t} = \mu + \sigma \xi_{t+1} $$
426426

427427
where
428428

429-
* $S_0$ is normally distributed and
429+
* $S_0$ is lognormally distributed and
430430
* $\{ \xi_t \}$ is IID and standard normal.
431431

432432

@@ -485,23 +485,23 @@ Here $\{\eta_t\}$ is also IID and standard normal.
485485
For the dynamic model, we adopt the following parameter values.
486486

487487
```{code-cell} ipython3
488-
μ = 0.0001
489-
ρ = 0.1
490-
ν = 0.001
491-
S0 = 10
492-
h0 = 0
488+
default_μ = 0.0001
489+
default_ρ = 0.1
490+
default_ν = 0.001
491+
default_S0 = 10
492+
default_h0 = 0
493493
```
494494

495495

496496

497-
(Here `S0` is $S_0$ and `h0` is $h_0$.)
497+
(Here `default_S0` is $S_0$ and `default_h0` is $h_0$.)
498498

499499
For the option we use the following defaults.
500500

501501
```{code-cell} ipython3
502-
K = 100
503-
n = 10
504-
β = 0.95
502+
default_K = 100
503+
default_n = 10
504+
default_β = 0.95
505505
```
506506

507507

@@ -515,7 +515,7 @@ $$ s_{t+1} = s_t + \mu + \exp(h_t) \xi_{t+1} $$
515515
Here is a function to simulate a path using this equation:
516516

517517
```{code-cell} ipython3
518-
def simulate_asset_price_path(μ=μ, S0=S0, h0=h0, n=n, ρ=ρ, ν=ν):
518+
def simulate_asset_price_path(μ=default_μ, S0=default_S0, h0=default_h0, n=default_n, ρ=default_ρ, ν=default_ν):
519519
s = np.empty(n+1)
520520
s[0] = np.log(S0)
521521
@@ -568,14 +568,14 @@ $$
568568
Here's a version using Python loops.
569569

570570
```{code-cell} ipython3
571-
def compute_call_price(β=β,
572-
μ=μ,
573-
S0=S0,
574-
h0=h0,
575-
K=K,
576-
n=n,
577-
ρ=ρ,
578-
ν=ν,
571+
def compute_call_price(β=default_β,
572+
μ=default_μ,
573+
S0=default_S0,
574+
h0=default_h0,
575+
K=default_K,
576+
n=default_n,
577+
ρ=default_ρ,
578+
ν=default_ν,
579579
M=10_000):
580580
current_sum = 0.0
581581
# For each sample path
@@ -617,14 +617,14 @@ Your task is to write a faster version of this code using NumPy.
617617
```
618618

619619
```{code-cell} ipython3
620-
def compute_call_price(β=β,
621-
μ=μ,
622-
S0=S0,
623-
h0=h0,
624-
K=K,
625-
n=n,
626-
ρ=ρ,
627-
ν=ν,
620+
def compute_call_price_vector(β=default_β,
621+
μ=default_μ,
622+
S0=default_S0,
623+
h0=default_h0,
624+
K=default_K,
625+
n=default_n,
626+
ρ=default_ρ,
627+
ν=default_ν,
628628
M=10_000):
629629
630630
s = np.full(M, np.log(S0))
@@ -640,7 +640,7 @@ def compute_call_price(β=β,
640640

641641
```{code-cell} ipython3
642642
%%time
643-
compute_call_price()
643+
compute_call_price_vector()
644644
```
645645

646646

@@ -676,27 +676,27 @@ Use the dynamics defined in {eq}`s_mc_dyms` to price the European call option.
676676
```
677677

678678
```{code-cell} ipython3
679-
μ = 0.0001
680-
ρ = 0.1
681-
ν = 0.001
682-
S0 = 10
683-
h0 = 0
684-
K = 100
685-
n = 10
686-
β = 0.95
687-
bp = 120
679+
default_μ = 0.0001
680+
default_ρ = 0.1
681+
default_ν = 0.001
682+
default_S0 = 10
683+
default_h0 = 0
684+
default_K = 100
685+
default_n = 10
686+
default_β = 0.95
687+
default_bp = 120
688688
```
689689

690690
```{code-cell} ipython3
691-
def compute_call_price_with_barrier(β=β,
692-
μ=μ,
693-
S0=S0,
694-
h0=h0,
695-
K=K,
696-
n=n,
697-
ρ=ρ,
698-
ν=ν,
699-
bp=bp,
691+
def compute_call_price_with_barrier(β=default_β,
692+
μ=default_μ,
693+
S0=default_S0,
694+
h0=default_h0,
695+
K=default_K,
696+
n=default_n,
697+
ρ=default_ρ,
698+
ν=default_ν,
699+
bp=default_bp,
700700
M=50_000):
701701
current_sum = 0.0
702702
# For each sample path
@@ -731,15 +731,15 @@ def compute_call_price_with_barrier(β=β,
731731
Let's look at the vectorized version which is faster than using Python loops.
732732

733733
```{code-cell} ipython3
734-
def compute_call_price_with_barrier_vector(β=β,
735-
μ=μ,
736-
S0=S0,
737-
h0=h0,
738-
K=K,
739-
n=n,
740-
ρ=ρ,
741-
ν=ν,
742-
bp=bp,
734+
def compute_call_price_with_barrier_vector(β=default_β,
735+
μ=default_μ,
736+
S0=default_S0,
737+
h0=default_h0,
738+
K=default_K,
739+
n=default_n,
740+
ρ=default_ρ,
741+
ν=default_ν,
742+
bp=default_bp,
743743
M=50_000):
744744
s = np.full(M, np.log(S0))
745745
h = np.full(M, h0)

0 commit comments

Comments
 (0)