Write the Euler discretization of the 1-dimensional stochastic equation

$dXt = b (t, X_t) \space dt + \sigma (t, X_t) \space dW_t$

For this part I would say all right because it is a purely theoretical part that I find on any stochastic calculus book.

The problem arises on the optional part: Set $b (t, x) = tx$, $\sigma (t, x) = \sqrt {t (x + 1)}$ e $X_0 = 1$, numerically approximate the expected value $max$ {$0, 1 - (X_{0.5})^2$} using the Euler-Monte Carlo method.

The discretized equation will be:

$$dX_{t,j+1} = X_{t,j} tX_{t,j} + t_j X_{t,j} \Delta + \sqrt {t_j (X_{t,j} + 1)^+} \Delta W_j$$ with $X_{t_0} = 1$

Could you point me to a book or a site with a python code for writing this method? Thanks!

I find this code:

# Create Brownian Motion
dB = np.sqrt(dt) * np.random.randn(N)
B  = np.cumsum(dB)

# Exact Solution
Y = X0 * np.exp((mu - 0.5*sigma**2)*t + (sigma * B))

# EM Approximation - small dt
X_em_small, X = [], X0
for j in range(N):  
    X += mu*X*dt + sigma*X*dB[j]

# EM Approximation - big dt
X_em_big, X, R = [], X0, 2
coarse_grid = np.arange(dt,1+dt,R*dt)
for j in range(int(N/R)):
    X += mu*X* (R*dt) + sigma*X*sum(dB[R*(j-1):R*j])
# Plot
plt.plot(t, Y, label="Exact ($Y_t$)", color=pal[0])
plt.plot(t, X_em_small, label="EM ($X_t$): Fine Grid", color=pal[1], ls='--')
plt.plot(coarse_grid, X_em_big, label="EM ($X_t$): Coarse Grid", color=pal[2], ls='--')
plt.title('E-M Approximation vs. Exact Simulation'); plt.xlabel('t'); plt.legend(loc = 2);

how can i apply it to my text? Thanks very very much.

  • $\begingroup$ Hi, can someone help me with the code? Thanks. $\endgroup$
    – GloBag578
    May 30 at 9:53

1 Answer 1


I believe this link will have what you are looking for.

Python Numerical Methods -- Chapter 22.3

  • $\begingroup$ Thanks very much. $\endgroup$
    – GloBag578
    May 30 at 9:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.