Variable rate jumps diffeq?

I’m trying to get a variable rate jump to work. I am using


## jump in price
#rate1(u,p,t) = λ0 # constant jump rate
rate1(u,p,t) = λ0.*exp(u[2]) # volatility dependent jump rate
# jump is normal with st. dev. equal to λ1 times current st. dev.
affect1!(integrator) = (integrator.u[1] = integrator.u[1].+randn(size(integrator.u[1])).*λ1.*exp(integrator.u[2]./2.0))

# this works:
jump1 = ConstantRateJump(rate1,affect1!)
# this does not
#jump1 = VariableRateJump(rate1,affect1!)
jump_prob = JumpProblem(prob,Direct(), jump1)

The rate, rate1, depends on the second integrator, so I understand that it is a variable rate jump. However, I get a dimension error if I try to specify it as variable rate (jump1, commented out). The solver gives a solution if I specify it as constant rate.

Am I making an error in the syntax for a variable rate jump?
Thanks!

Here’s the environment, and the whole file, if it helps

(JD) pkg> st
Status `~/Desktop/JD/Project.toml`
  [a077e3f3] DiffEqProblemLibrary v4.8.0
  [0c46a032] DifferentialEquations v6.14.0 `https://github.com/SciML/DifferentialEquations.jl.git#master`
  [91a5bcdd] Plots v0.29.9
  [e6cf234a] RandomNumbers v1.4.0

(JD) pkg> 

using DifferentialEquations, Plots

function MyProblem(μ0,μ1,κ,α,σ,ρ,u0,tspan)
    f = function (du,u,p,t)
        du[1] = μ0 + μ1*(u[2]-α)/σ # drift in prices
        du[2] = κ*(α-u[2]) # mean reversion in shocks
    end
    g = function (du,u,p,t)
        du[1] = exp(u[2]/2.0)
        du[2] = σ
    end
    Γ = [1 ρ;ρ 1] # Covariance Matrix
    noise = CorrelatedWienerProcess!(Γ,tspan[1],zeros(2),zeros(2))
    sde_f = SDEFunction{true}(f,g)
    SDEProblem(sde_f,g,u0,tspan,noise=noise)
end

μ0 = 0.0
μ1 = 0.0
κ = 0.05
α = 0.2
σ = 0.2
ρ = -0.7
λ0 = 2.0
λ1 = 3.0
u0 = [0;α]
dt = 0.01
prob = MyProblem(μ0, μ1, κ, α, σ, ρ, u0, (0.0,1000.0))

## jump in price
#rate1(u,p,t) = λ0 # constant jump rate
rate1(u,p,t) = λ0.*exp(u[2]) # volatility dependent jump rate
# jump is normal with st. dev. equal to λ1 times current st. dev.
affect1!(integrator) = (integrator.u[1] = integrator.u[1].+randn(size(integrator.u[1])).*λ1.*exp(integrator.u[2]./2.0))

# this works:
jump1 = ConstantRateJump(rate1,affect1!)
# this does not
#jump1 = VariableRateJump(rate1,affect1!)
jump_prob = JumpProblem(prob,Direct(), jump1)
sol = solve(jump_prob,SRIW1(), dt=dt, adaptive=false)

An incidental question, is there a way to visualize exactly when jumps occur?

Xref: Specify jumps in a Heston-like model? - #6 by mcreel for the solution

1 Like

Hi @mcreel

I ran into the same problem today. The example from the tutorial

https://diffeq.sciml.ai/stable/tutorials/jump_diffusion/

works fine for the constant rate jump, but not for the variable rate jump

The error message I’m getting from the variable rate jump is

MethodError: no method matching CartesianIndices(::Array{Float64,1}, ::Int64, ::Int64)

BTW I updated to the latest version of DifferentialEquations.jl and the problem still exists

I just ran the tutorial code:

using OrdinaryDiffEq, DiffEqJump
function f(du,u,p,t)
  du[1] = u[1]
end

prob = ODEProblem(f,[0.2],(0.0,10.0))
rate(u,p,t) = u[1]
affect!(integrator) = (integrator.u[1] = integrator.u[1]/2)
jump = VariableRateJump(rate,affect!)
jump2 = deepcopy(jump)
jump_prob = JumpProblem(prob,Direct(),jump,jump2)
sol = solve(jump_prob,Tsit5())

It ran fine. What are you running?

Hi @tzxiong. Please see ChrisRackaukas’ answer in the other thread. The variable rate problem was more complicated than what I was interested in getting into, so I ended up working with constant rate jumps, and that all worked out well.

1 Like