Euler–Maruyama Simulation for a State-Dependent Stochastic Differential Equation
Summary
The document asks how to apply the Euler–Maruyama method to a one-dimensional stochastic differential equation with time- and state-dependent drift and diffusion. Its example starts at one and asks for a Monte Carlo estimate of the expected positive part of one minus the squared process value at a specified horizon. It also includes sample code for geometric Brownian motion, illustrating Brownian increments, fine and coarse time steps, and comparison with an exact solution.
That sample uses constant drift and volatility in a multiplicative model, so it cannot be transferred directly to the proposed equation. The general method evaluates the drift and diffusion at each current time and state, advances with a time increment and a scaled Brownian increment, and repeats across simulated paths before averaging the payoff. The document does not provide a complete implementation or numerical estimate for its state-dependent example; the accepted response points to an external numerical methods chapter.
Key ideas
- Euler–Maruyama advances an SDE using drift over each time step and diffusion multiplied by a Brownian increment.
- The example requires recalculating drift and diffusion from the current time and simulated state.
- Monte Carlo estimation averages the payoff across simulated process paths at the target horizon.
- The included geometric Brownian motion code illustrates the method but uses different coefficients and dynamics.
Tags
Full text
# Euler Discretization python code
# Euler Discretization python code
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
np.random.seed(1)
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]
X_em_small.append(X)
# 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])
X_em_big.append(X)
# 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.
## Answer by amdopt (score 2, accepted)
https://quant.stackexchange.com/a/71026
I believe this link will have what you are looking for.
Python Numerical Methods -- Chapter 22.3Shown in full with attribution under the source's licence. Licence: CC BY-SA 4.0 (Stack Exchange)
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.