# Jump Process with Drift

**URL:** https://discourse.julialang.org/t/jump-process-with-drift/115166
**Category:** Modelling & Simulations
**Tags:** differentialequation
**Created:** [June 4, 2024, 12:33pm UTC](https://discourse.julialang.org/t/jump-process-with-drift/115166 "2024-06-04T12:33:55Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Mieszko](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mieszko/32/202770_2.png) [@Mieszko](https://discourse.julialang.org/u/Mieszko)
#### Post date: [June 4, 2024, 12:33pm UTC](https://discourse.julialang.org/t/jump-process-with-drift/115166/1 "2024-06-04T12:33:55Z")

</div>

Hey, I am trying to simulate with the use of JumpProcesses.jl the following stochastic differential equation:  
dX\_t = -X\_tdt + dN\_t.

Do you know, if there is any straightforward way of defining the f (drift) function in this case? If you go for the following:

> function f(du, u, p, t)  
> du[1] = -u[1]  
> end

then as far as I understand your process has the following form:

dX\_t = \exp(-X\_t)dt + dN\_t.

---

<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: [June 4, 2024, 12:38pm UTC](https://discourse.julialang.org/t/jump-process-with-drift/115166/2 "2024-06-04T12:38:10Z")

</div>

> [@Mieszko](#):
>
> then as far as I understand your process has the following form:

No, that would put your equation in the right form.

---

<div class="post-metadata">

### Author: ![Mieszko](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mieszko/32/202770_2.png) [@Mieszko](https://discourse.julialang.org/u/Mieszko)
#### Post date: [June 5, 2024, 8:59pm UTC](https://discourse.julialang.org/t/jump-process-with-drift/115166/3 "2024-06-05T20:59:39Z")

</div>

Thank you for pointing this.  
I am a bit confused since all the paths I get when simulating this process are positive:  
 ![julia_plot](https://global.discourse-cdn.com/julialang/original/3X/c/5/c552de5b67af9ae140bba3c658838218eb0f3393.png)  
For the comparison, using the jumpdiff library from python and simulating the same process, the paths look like this:  
 ![python_plot](https://global.discourse-cdn.com/julialang/original/3X/b/0/b0a4cb0a291ba5bd6c81ad125eb76ca62d5a6e41.png)  
Is there any reason, why Julia’s path gives only positive value (some shifting etc.), or is there something else wrong?

I am using the following code for the Julia path:

> > using DifferentialEquations, Plots, JumpProcesses
> 
> > timestep = Float64(0.05)  
> > t = range(0, timestep, length=100)
> 
> function f(du, u, p, t)  
> du[1] = -u[1]  
> end
> 
> rate(u, p, t) = 1.0
> 
> function affect!(integrator)  
> integrator.u[1] += 1  
> nothing  
> end
> 
> jump = ConstantRateJump(rate, affect!)
> 
> prob = ODEProblem(f, [0.0], (10.0, 100.0))  
> jump\_prob = JumpProblem(prob, Direct(), jump)  
> sol = solve(jump\_prob, Tsit5(), saveat=timestep)
> 
> plot(sol)

---

<div class="post-metadata">

### Author: ![Dan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dan/32/42581_2.png) [@Dan](https://discourse.julialang.org/u/Dan)
#### Post date: [June 5, 2024, 9:09pm UTC](https://discourse.julialang.org/t/jump-process-with-drift/115166/4 "2024-06-05T21:09:43Z")

</div>

The jump amplitude parameter in Python jumpdiff library is the standard deviation of a Gaussian distributed jump `N(0,sigma^2)` and as such can take both negative and positive values.

In the Julia code:

```julia
function affect!(integrator)
    integrator.u[1] += 1
    nothing
end

```

the jump is a +1 jump only (at a specified rate). To get the same as the Python effect use:

```julia
function affect!(integrator)
    integrator.u[1] += randn()
    nothing
end

```

---

<div class="post-metadata">

### Author: ![Mieszko](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mieszko/32/202770_2.png) [@Mieszko](https://discourse.julialang.org/u/Mieszko)
#### Post date: [June 5, 2024, 9:47pm UTC](https://discourse.julialang.org/t/jump-process-with-drift/115166/5 "2024-06-05T21:47:37Z")

</div>

Thanks, that makes much more sense now!
