@@ -104,10 +104,11 @@ The `scipy.stats` subpackage supplies
|
104 | 104 | |
105 | 105 | ### Random Variables and Distributions |
106 | 106 | |
107 | | -Recall that `numpy.random` provides functions for generating random variables |
| 107 | +Recall that `numpy.random` provides tools for generating random variables |
108 | 108 | |
109 | 109 | ```{code-cell} python3 |
110 | | -np.random.beta(5, 5, size=3) |
| 110 | +rng = np.random.default_rng() |
| 111 | +rng.beta(5, 5, size=3) |
111 | 112 | ``` |
112 | 113 | |
113 | 114 | This generates a draw from the distribution with the density function below when `a, b = 5, 5` |
@@ -188,8 +189,8 @@ For example, `scipy.stats.linregress` implements simple linear regression
|
188 | 189 | ```{code-cell} python3 |
189 | 190 | from scipy.stats import linregress |
190 | 191 | |
191 | | -x = np.random.randn(200) |
192 | | -y = 2 * x + 0.1 * np.random.randn(200) |
| 192 | +x = rng.standard_normal(200) |
| 193 | +y = 2 * x + 0.1 * rng.standard_normal(200) |
193 | 194 | gradient, intercept, r_value, p_value, std_err = linregress(x, y) |
194 | 195 | gradient, intercept |
195 | 196 | ``` |
@@ -572,8 +573,9 @@ Set `M = 10_000_000`
|
572 | 573 | Here is one solution: |
573 | 574 | |
574 | 575 | ```{code-cell} ipython3 |
| 576 | +rng = np.random.default_rng() |
575 | 577 | M = 10_000_000 |
576 | | -S = np.exp(μ + σ * np.random.randn(M)) |
| 578 | +S = np.exp(μ + σ * rng.standard_normal(M)) |
577 | 579 | return_draws = np.maximum(S - K, 0) |
578 | 580 | P = β**n * np.mean(return_draws) |
579 | 581 | print(f"The Monte Carlo option price is {P:3f}") |
|