Simulation HJM model via stochastic Diffeq

I want to do forward curve simulation from simplest HJM model using awesome DiffEq package:

using Parameters
using Statistics
using Printf
using Plots
using DifferentialEquations

σ = 1.4
M = 10
u₀= 10
f(u,p,t) = 0
g(u,p,t) = u * σ * exp(- α * (M-t))
dt = 1
tspan = (0.0,10.0)
prob = SDEProblem(f,g,u₀,(0.0,10.0))	
sol = solve(prob,EM(),dt=dt,save_noise=true)
ensembleprob = EnsembleProblem(prob)
sol = solve(ensembleprob,EnsembleThreads(),trajectories=100)

Using my code I can get simulation F(t,) for fixed maturity T = 10:

My code threat T as fixed parameter, but I want to get simulations of the whole forward (for all T) curve at any moment t:

Can I treat T correctly: to get the whole forward curve for each t and not fixed maturity T?


Are you saying T is a continuous variable itself? As in, you have a PDE?

Ideally I want T to be a continuous variable, to get continious forward curve at any moment.
But discrete T also have a meaning of monthly tradable futures, so it is also possible way.

In case of discrete T I need to use smth like this example about Systems of SDE?:

Here is viz of my final aim:

Source of pics: HJM/hjm.ipynb at main · omartinsky/HJM · GitHub


1 Like

For discrete T you can use an ensemble of simulations:

which seems to be what they did in that notebook. If you want a truly continuous T you could represent it as a stochastic partial differential equation, though solving that could get a little tricky (and it would have a different noise than normal so it would be a little odd).

Thank you for your answers. I’ll try and write here my results.
I think it would be useful for users, who want to build quantitative finance models with Julia and DiffEq.

Note that this is a heterogenous community and people will have a hard time helping you from this because we don’t know what does HJM stands for and neither what z is and we have to guess that T is a parameter which is independent of z. I am not sure you want an ensemble problem here, I imagine it can well be that all F(., M) are driven by the same noise?

HJM model is a general framework for modelling the evolution of interest rates curves:

This framework was adopted to build commodity forward curves. And my formula is the simplest possible version of this model. Pertrubation dF(t,T) is specified as deterministic shape function \sigma multiplied by Gaussian factor dz.

T is a parameter which is indepent of z. The meaning of T is time to the delivery of commodity.

I imagine it can well be that all F(., M) are driven by the same noise?

yes, this is exactly what I am looking for.

This is then the right thing to follow writing g in parallel for all “dimensions” given by the discretisation of T.

1 Like