@@ -124,10 +124,11 @@ a = np.identity(3)
124124
125125### متغیرهای تصادفی و توزیعها
126126
127- به یاد بیاورید که ` numpy.random ` توابعی را برای تولید متغیرهای تصادفی فراهم میکند
127+ به یاد بیاورید که ` numpy.random ` ابزارهایی را برای تولید متغیرهای تصادفی فراهم میکند
128128
129129``` {code-cell} python3
130- np.random.beta(5, 5, size=3)
130+ rng = np.random.default_rng()
131+ rng.beta(5, 5, size=3)
131132```
132133
133134این یک نمونه از توزیع با تابع چگالی زیر را وقتی ` a, b = 5, 5 ` تولید میکند
@@ -208,8 +209,8 @@ plt.show()
208209``` {code-cell} python3
209210from scipy.stats import linregress
210211
211- x = np.random.randn (200)
212- y = 2 * x + 0.1 * np.random.randn (200)
212+ x = rng.standard_normal (200)
213+ y = 2 * x + 0.1 * rng.standard_normal (200)
213214gradient, intercept, r_value, p_value, std_err = linregress(x, y)
214215gradient, intercept
215216```
@@ -592,8 +593,9 @@ $$ \mathbb E \max\{ S_n - K, 0 \}
592593در اینجا یک راهحل آورده شده است:
593594
594595``` {code-cell} ipython3
596+ rng = np.random.default_rng()
595597M = 10_000_000
596- S = np.exp(μ + σ * np.random.randn (M))
598+ S = np.exp(μ + σ * rng.standard_normal (M))
597599return_draws = np.maximum(S - K, 0)
598600P = β**n * np.mean(return_draws)
599601print(f"The Monte Carlo option price is {P:3f}")
@@ -648,4 +650,4 @@ bisect(f, 0, 1)
648650```
649651
650652``` {solution-end}
651- ```
653+ ```
0 commit comments