# Speed up jump diffusion solution for estimation?

**URL:** <https://discourse.julialang.org/t/speed-up-jump-diffusion-solution-for-estimation/43174>\
**Category:** General Usage\
**Tags:** diffeq\
**Created:** [July 16, 2020, 12:24pm UTC](https://discourse.julialang.org/t/speed-up-jump-diffusion-solution-for-estimation/43174 "2020-07-16T12:24:46Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![mcreel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mcreel/32/30088_2.png) [@mcreel](https://discourse.julialang.org/u/mcreel)\
**Post date:** [July 16, 2020, 12:24pm UTC](https://discourse.julialang.org/t/speed-up-jump-diffusion-solution-for-estimation/43174/1 "2020-07-16T12:24:46Z")

</div>

I am interested in estimating the parameters of a jump diffusion using simulation-based methods, and filtering statistics through a neural net. The basic idea is working quite well. Now, I need to make the simulations as fast as possible, while keeping decent accuracy, so as not to loose identification of the parameters. I need to generate many solutions at different parameter vectors. Currently, I’m using the SRIW1 algorithm (in DifferentialEquations.jl):

```julia
sol = solve(jump_prob,SRIW1(), dt=dt, adaptive=false)

```

I am wondering if a different algorithm would be more better, to increase speed. I tried a few others, and did not see very large differences in solution time. I have experimented with julia threads and OPENBLAS threads, but I don’t see that the SRIW1 method is using either of them. I don’t have access to a useful GPU. Is there any recommendation for changing algorithms, tolerances, or means of using parallelism?

For reference, here’s the non-jump portion of the model:

```julia
function Diffusion(μ0,μ1,κ,α,σ,ρ,u0,tspan)
    f = function (du,u,p,t)
        du[1] = μ0 + μ1*(u[2]-α)/σ # drift in log 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.0 ρ;ρ 1.0] # 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

```

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [July 16, 2020, 12:43pm UTC](https://discourse.julialang.org/t/speed-up-jump-diffusion-solution-for-estimation/43174/2 "2020-07-16T12:43:38Z")

</div>

How often are the jumps? I think it’s going to be difficult to beat what you have there (unless the jumps are rapid, in which case some of the new regular jump diffusion solvers could be applicable), and focusing on the parallelism might be the best choice.

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [July 16, 2020, 12:44pm UTC](https://discourse.julialang.org/t/speed-up-jump-diffusion-solution-for-estimation/43174/3 "2020-07-16T12:44:31Z")

</div>

What do your jumps look like? Are they mass action jumps? Where is the profile spending most of its time?

---

<div class="post-metadata">

**Author:** ![mcreel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mcreel/32/30088_2.png) [@mcreel](https://discourse.julialang.org/u/mcreel)\
**Post date:** [July 16, 2020, 1:10pm UTC](https://discourse.julialang.org/t/speed-up-jump-diffusion-solution-for-estimation/43174/4 "2020-07-16T13:10:15Z")

</div>

> [@ChrisRackauckas](#):
>
> ss action jumps? Where is the profile spending most of its time?

The jumps are infrequent (λ0 is between 0.0 and 0.05).

```julia
## jump in log price
rate(u,p,t) = ## jump in log price
rate(u,p,t) = λ0
# jump is random sign times λ1 times current st. dev.
affect1!(integrator) = (integrator.u[1] = integrator.u[1].+rand([-1.0,1.0]).*λ1.*exp(integrator.u[2]./2.0))
jump = ConstantRateJump(rate,affect1!)
jump_prob = JumpProblem(prob,Direct(), jump)
sol = solve(jump_prob,SRIW1(), dt=dt, adaptive=false)

```

The time span is long: (0,10000). I have parallel processing working ok, once the solution is done, but the solution itself seems to be done using only a single thread. That’s where I was hoping to find a way to parallelize. I’m using this in a MCMC algorithm, at the moment, but perhaps I will have to go to SMC, instead.

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [July 17, 2020, 4:05am UTC](https://discourse.julialang.org/t/speed-up-jump-diffusion-solution-for-estimation/43174/5 "2020-07-17T04:05:32Z")

</div>

I’m not sure classical methods can do any better here (long time spans), but we do keep trying to optimize this more and more. `saveat` at longer intervals probably helps, since I assume you don’t need every step in there?

BTW, I think for estimation, directly using the PDE formulation might be more efficient if you’re fitting via distributional information. That might be something to look into.

---

<div class="post-metadata">

**Author:** ![mcreel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mcreel/32/30088_2.png) [@mcreel](https://discourse.julialang.org/u/mcreel)\
**Post date:** [July 17, 2020, 5:34am UTC](https://discourse.julialang.org/t/speed-up-jump-diffusion-solution-for-estimation/43174/6 "2020-07-17T05:34:33Z")

</div>

I am computing realized volatility measures, so I need the solution at every regular short interval. I’m fitting via statistics, as in ABC or GMM. The solution is already pretty quick, I just wanted to make sure I was not missing some obvious opportunity to speed it up. I think my best option for speeding this up is to use posterior sampler that can sample in parallel, rather than the simple MCMC I’m currently using. Thanks!

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [July 17, 2020, 6:33am UTC](https://discourse.julialang.org/t/speed-up-jump-diffusion-solution-for-estimation/43174/7 "2020-07-17T06:33:47Z")

</div>

> [@mcreel](#):
>
> I think my best option for speeding this up is to use posterior sampler that can sample in parallel, rather than the simple MCMC I’m currently using.

Yeah, that’s probably a good way to go.

---

<div class="post-metadata">

**Author:** ![mcreel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mcreel/32/30088_2.png) [@mcreel](https://discourse.julialang.org/u/mcreel)\
**Post date:** [September 13, 2020, 2:20pm UTC](https://discourse.julialang.org/t/speed-up-jump-diffusion-solution-for-estimation/43174/8 "2020-09-13T14:20:13Z")

</div>

In the end, I have used multiple MCMC chains, which seems to work pretty well. Estimating the model using data generated at known parameter values recovers the true parameters with pretty good precision, as can be seen here [https://github.com/mcreel/SNM/tree/master/examples/JD/SimulationEstimation](https://github.com/mcreel/SNM/tree/master/examples/JD/SimulationEstimation). Thanks for the help.

---

<div class="post-metadata">

**Author:** ![mschauer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mschauer/32/13946_2.png) [@mschauer](https://discourse.julialang.org/u/mschauer)\
**Post date:** [September 13, 2020, 2:30pm UTC](https://discourse.julialang.org/t/speed-up-jump-diffusion-solution-for-estimation/43174/9 "2020-09-13T14:30:57Z")

</div>

Perhaps too late but conditional on the jumps the parameters of the drift part are conjugate — you can just read their posterior from the trajectory with proposition 5.6 in [https://arxiv.org/pdf/1712.03807.pdf](https://arxiv.org/pdf/1712.03807.pdf) if you have a continuous time observation

---

<div class="post-metadata">

**Author:** ![mschauer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mschauer/32/13946_2.png) [@mschauer](https://discourse.julialang.org/u/mschauer)\
**Post date:** [September 13, 2020, 2:50pm UTC](https://discourse.julialang.org/t/speed-up-jump-diffusion-solution-for-estimation/43174/10 "2020-09-13T14:50:54Z")

</div>

@ChrisRackauckas Do you have conjugate analysis of drift parameters somewhere in the ecosystem?

---

<div class="post-metadata">

**Author:** ![mcreel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mcreel/32/30088_2.png) [@mcreel](https://discourse.julialang.org/u/mcreel)\
**Post date:** [September 13, 2020, 3:22pm UTC](https://discourse.julialang.org/t/speed-up-jump-diffusion-solution-for-estimation/43174/11 "2020-09-13T15:22:15Z")

</div>

The example I’m working with is observed in discrete time (end of trading day), so I believe that this proposition would not apply. Thanks for the reference, it has some pretty interesting animations.

---

<div class="post-metadata">

**Author:** ![Yifan\_Liu](https://avatars.discourse-cdn.com/v4/letter/y/4da419/32.png) [@Yifan\_Liu](https://discourse.julialang.org/u/Yifan_Liu)\
**Post date:** [September 13, 2020, 3:28pm UTC](https://discourse.julialang.org/t/speed-up-jump-diffusion-solution-for-estimation/43174/12 "2020-09-13T15:28:07Z")

</div>

R has a package called yuima that can estimate jump and other stochastic processes. I am looking for a Julia counterpart.

---

<div class="post-metadata">

**Author:** ![mschauer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mschauer/32/13946_2.png) [@mschauer](https://discourse.julialang.org/u/mschauer)\
**Post date:** [September 13, 2020, 6:30pm UTC](https://discourse.julialang.org/t/speed-up-jump-diffusion-solution-for-estimation/43174/13 "2020-09-13T18:30:16Z")

</div>

Yeah, you could still think of using the result in a data augmentation setting where you sample the joint posterior of parameters and latent path, but that’ll become a story of its own (my paper linked is concerned with that)

---

<div class="post-metadata">

**Author:** ![mschauer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mschauer/32/13946_2.png) [@mschauer](https://discourse.julialang.org/u/mschauer)\
**Post date:** [November 16, 2020, 11:02am UTC](https://discourse.julialang.org/t/speed-up-jump-diffusion-solution-for-estimation/43174/14 "2020-11-16T11:02:13Z")

</div>

> @ChrisRackauckas Do you have conjugate analysis of drift parameters somewhere in the ecosystem?

Work in progress in [Regression by frankschae · Pull Request #15 · mschauer/MitosisStochasticDiffEq.jl · GitHub](https://github.com/mschauer/MitosisStochasticDiffEq.jl/pull/15)
