@@ -104,10 +104,11 @@ The `scipy.stats` subpackage supplies
104104
105105### Random Variables and Distributions
106106
107- Recall that ` numpy.random ` provides functions for generating random variables
107+ Recall that ` numpy.random ` provides tools for generating random variables
108108
109109``` {code-cell} python3
110- np.random.beta(5, 5, size=3)
110+ rng = np.random.default_rng()
111+ rng.beta(5, 5, size=3)
111112```
112113
113114This 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
188189``` {code-cell} python3
189190from scipy.stats import linregress
190191
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)
193194gradient, intercept, r_value, p_value, std_err = linregress(x, y)
194195gradient, intercept
195196```
@@ -572,8 +573,9 @@ Set `M = 10_000_000`
572573Here is one solution:
573574
574575``` {code-cell} ipython3
576+ rng = np.random.default_rng()
575577M = 10_000_000
576- S = np.exp(μ + σ * np.random.randn (M))
578+ S = np.exp(μ + σ * rng.standard_normal (M))
577579return_draws = np.maximum(S - K, 0)
578580P = β**n * np.mean(return_draws)
579581print(f"The Monte Carlo option price is {P:3f}")
0 commit comments