0

Currently I'm learning about SDE's. In my course notes the following example was given for the following SDE: This results in the following image:

\begin{array}{l} d B_{t}=\left(-K_{1} B_{t}+s_{t}+\frac{1}{2} B_{t} \sigma^{2}\right) d t-B_{t} \sigma d W_{t} \\ B_{t_{0}}=B_{0} \end{array}

enter image description here

With Python I tried to recreate the figure:

import numpy as np
import matplotlib.pyplot as plt

T = 100 N = 10000 dt = T/N K1 = 1 st = 3 Bt = 20 sigma = 1 y = np.zeros(N2) x = np.linspace(0,T,N2)

for i in range(N2): y[i] = Bt Bt += (-K1Bt + st + 0.5Btsigma*2)dt - Btsigmanp.random.normal(0, dt)

plt.plot(x, y)

The values for $K_1$, $s_t$ and $\sigma$ were not given, but I think I did a OK job.

Now I want to create this figure that shows the variance and mean. How do I modify my code in order to achieve this goal?

enter image description here

Tim
  • 684
  • How much does changing the y-axis help? Right now it's zoomed out quite a bit because plotting the standard deviation makes the y-axis start from $0$ – user6247850 Dec 03 '20 at 22:10

1 Answers1

1

Under the light of Monte Carlo, you can just simulate more random paths and the calculate the respective empirical mean and std.