Trading Dev AcademyFree quant education

Free lesson · Differential equations

Euler stepping, convergence and stability

Open interactive lessonPractice calculationsExplore labs

Start with the idea

  • A numerical solver repeatedly approximates the change over a short time interval.
  • Explicit Euler uses the slope at the beginning of each interval.
  • Smaller steps can reduce approximation error, but the scheme must also be stable for the equation being solved.
Symbols, units & horizon
  • n: time-step index
  • h: positive time-step length
  • t_n=nh: grid time
  • f(t,y): rate function defining the ODE
  • y_n: numerical state, not generally the exact solution at t_n
  • κ: positive decay speed
  • |1−κh|<1: stability condition for this scalar Euler decay example

When and why to use this

Use an exact solvable equation as a benchmark, compare several step sizes, and test stability. The ODE lab deliberately allows unstable steps so their consequences are visible.

  • A local slope is not constant over a finite interval, so replacing the full path with repeated tangent steps introduces discretisation error.
  • Under standard smoothness and stability conditions, explicit Euler has first-order global error over a fixed horizon.
  • For a decay equation, a step can be so large that the numerical solution oscillates or grows even though the exact solution decays.
  • This is an algorithmic effect, not newly discovered behaviour of the physical or financial model.
yn+1=yn+hf(tn,yn),y′=−κy ⇒ yn+1=(1−κh)yn
Calculus: derivation and arithmetic

Euler stepping, convergence and stability

  1. Integrate y′=f(t,y) over one step: y(t+h)−y(t)=∫ₜᵗ⁺ʰ f(s,y(s))ds. Replace the integrand by its starting value to obtain Euler’s update.
  2. For f=−κy, factor the update into (1−κh)y_n. Repeating n times gives y_n=(1−κh)ⁿy₀.
  3. Decay of the numerical magnitude requires |1−κh|<1, equivalent to 0<κh<2. If 1<κh<2 the numerical path alternates sign even though its magnitude decays.
Work it by hand

For κ=2 and y₀=1, h=.25 gives successive values 1,.5,.25. The exact value at t=.5 is exp(−1)≈.3679. With h=1.1 the multiplier is −1.2, so the numerical magnitude grows.

An analogy to remember

Following a curved route using straight steps works better with appropriately short steps. A step that is too long can cross the destination and keep overshooting.

How this becomes a building block

ODE solvers support calibration, filtering and deterministic state evolution. Euler–Maruyama adds a Brownian increment to a similar update, but stochastic convergence notions differ. Solver error should be checked before interpreting a simulation result as model risk or economic evidence.

Python implementation

Self-contained teaching example. Python 3.10+; dependencies and input conventions are shown in the code and notation. Run in your own Python environment.

def euler(function,initial,start,end,steps):
    if not isinstance(steps,int) or steps<1 or end<=start: raise ValueError("Valid interval and positive steps required")
    h=(end-start)/steps
    t,y=start,initial
    path=[(t,y)]
    for i in range(steps):
        y=y+h*function(t,y)
        t=start+(i+1)*h
        path.append((t,y))
    return path

print(euler(lambda t,y:-2*y,1,0,.5,2))

Continue learning

Differential Equations & Numerical Models — all lessons
  1. Start with a rate rule and an initial value
  2. Ordinary differential equations: growth and mean reversion
  3. Euler stepping, convergence and stability
  4. Partial differential equations and the bridge to current research

Quantitative finance and development glossary · Python resources and libraries · Research sources and limitations