@@ -12,7 +12,6 @@ kernelspec:
1212---
1313
1414
15-
1615# Monte Carlo and Option Pricing
1716
1817## Overview
@@ -49,7 +48,6 @@ from numpy.random import randn
4948```
5049
5150
52-
5351## An Introduction to Monte Carlo
5452
5553In this section we describe how Monte Carlo can be used to compute
@@ -153,7 +151,6 @@ p = 0.5
153151```
154152
155153
156-
157154#### A Routine using Loops in Python
158155
159156
@@ -177,7 +174,6 @@ S / n
177174```
178175
179176
180-
181177We can also construct a function that contains these operations:
182178
183179``` {code-cell} ipython3
@@ -192,15 +188,13 @@ def compute_mean(n=1_000_000):
192188```
193189
194190
195-
196191Now let's call it.
197192
198193``` {code-cell} ipython3
199194compute_mean()
200195```
201196
202197
203-
204198### A Vectorized Routine
205199
206200If we want a more accurate estimate we should increase $n$.
@@ -225,7 +219,6 @@ compute_mean_vectorized()
225219```
226220
227221
228-
229222Notice that this routine is much faster.
230223
231224We can increase $n$ to get more accuracy and still have reasonable speed:
@@ -237,7 +230,6 @@ compute_mean_vectorized(n=10_000_000)
237230```
238231
239232
240-
241233## Pricing a European Call Option under Risk Neutrality
242234
243235Next we are going to price a European call option under risk neutrality.
284276$$
285277
286278
287-
288279### A Comment on Risk
289280
290281As suggested by the name, the risk-neutral price ignores risk.
@@ -306,7 +297,6 @@ Nonetheless, the risk-neutral price is an important benchmark, which economists
306297and financial market participants try to calculate every day.
307298
308299
309-
310300### Discounting
311301
312302Another thing we ignored in the previous discussion was time.
336326$$
337327
338328
339-
340329### European Call Options
341330
342331Now let's price a European call option.
@@ -388,15 +377,13 @@ n = 10
388377```
389378
390379
391-
392380We set the simulation size to
393381
394382``` {code-cell} ipython3
395383M = 10_000_000
396384```
397385
398386
399-
400387Here is our code
401388
402389``` {code-cell} ipython3
@@ -407,7 +394,6 @@ print(f"The Monte Carlo option price is approximately {P:3f}")
407394```
408395
409396
410-
411397## Pricing Via a Dynamic Model
412398
413399In this exercise we investigate a more realistic model for the share price $S_n$.
479465Here $\{ \eta_t\} $ is also IID and standard normal.
480466
481467
482-
483468### Default Parameters
484469
485470For the dynamic model, we adopt the following parameter values.
@@ -493,7 +478,6 @@ h0 = 0
493478```
494479
495480
496-
497481(Here ` S0 ` is $S_0$ and ` h0 ` is $h_0$.)
498482
499483For the option we use the following defaults.
@@ -505,7 +489,6 @@ n = 10
505489```
506490
507491
508-
509492### Visualizations
510493
511494With $s_t := \ln S_t$, the price dynamics become
@@ -528,7 +511,6 @@ def simulate_asset_price_path(μ=μ, S0=S0, h0=h0, n=n, ρ=ρ, ν=ν):
528511```
529512
530513
531-
532514Here we plot the paths and the log of the paths.
533515
534516``` {code-cell} ipython3
@@ -547,7 +529,6 @@ plt.show()
547529```
548530
549531
550-
551532### Computing the Price
552533
553534Now that our model is more complicated, we cannot easily determine the
@@ -598,7 +579,6 @@ compute_call_price()
598579```
599580
600581
601-
602582## Exercises
603583
604584``` {exercise}
@@ -644,7 +624,6 @@ compute_call_price()
644624```
645625
646626
647-
648627Notice that this version is faster than the one using a Python loop.
649628
650629Now let's try with larger $M$ to get a more accurate calculation.
@@ -655,7 +634,6 @@ compute_call_price(M=10_000_000)
655634```
656635
657636
658-
659637``` {solution-end}
660638```
661639
@@ -703,17 +681,18 @@ def compute_call_price_with_barrier(β=β,
703681 for m in range(M):
704682 s = np.log(S0)
705683 h = h0
706- is_null = False
684+ payoff = 0
707685 # Simulate forward in time
708686 for t in range(n):
709687 s = s + μ + np.exp(h) * randn()
710688 h = ρ * h + ν * randn()
711689 if np.exp(s) > bp:
712- is_null = True
713-
714- if not is_null:
715- # And add the value max{S_n - K, 0} to current_sum
716- current_sum += np.maximum(np.exp(s) - K, 0)
690+ payoff = 0
691+ break
692+ else:
693+ payoff = np.maximum(np.exp(s) - K, 0)
694+ # And add the payoff to current_sum
695+ current_sum += payoff
717696
718697 return β**n * current_sum / M
719698```
0 commit comments