# How to set a fixed stepsize in SDE Monte Carlo problem?

**URL:** <https://discourse.julialang.org/t/how-to-set-a-fixed-stepsize-in-sde-monte-carlo-problem/22744>\
**Category:** New to Julia\
**Tags:** question, sde\
**Created:** [April 4, 2019, 12:23pm UTC](https://discourse.julialang.org/t/how-to-set-a-fixed-stepsize-in-sde-monte-carlo-problem/22744 "2019-04-04T12:23:47Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![SSkor](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sskor/32/7623_2.png) [@SSkor](https://discourse.julialang.org/u/SSkor)\
**Post date:** [April 4, 2019, 12:23pm UTC](https://discourse.julialang.org/t/how-to-set-a-fixed-stepsize-in-sde-monte-carlo-problem/22744/1 "2019-04-04T12:23:47Z")

</div>

Hello! I’m a new julia user. I try to get a sample of trajectories via stochastic differential equations with fixed length = 1000.

So, for Wiener process I did it.

```julia
traj_length = 1000.0 
n = 100 
W = WienerProcess(0.0, 0.0) #WienerProcess(t0, W0)
prob = NoiseProblem(W, (0.0, traj_length))
monte_prob = MonteCarloProblem(prob)
sol = solve(monte_prob; dt=1.0, num_monte=n) 
A = Array(sol)

```

But for SDEProblem i always get 43x100 array while I need 1000x100.

```julia
α=0.15
β=.3
u₀=1/2
f(u,p,t) = α*u
g(u,p,t) = β*u
tspan = (0.0,1.0)
prob = SDEProblem(f,g,u₀,(0.0,1.0))
monte_prob = MonteCarloProblem(prob)
sol = solve(monte_prob, num_monte=n, dt=0.001) 
A = Array(sol)

```

How to set a fixed stepsize?

---

<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:** [April 4, 2019, 9:29pm UTC](https://discourse.julialang.org/t/how-to-set-a-fixed-stepsize-in-sde-monte-carlo-problem/22744/2 "2019-04-04T21:29:37Z")

</div>

> [@SSkor](#):
>
> How to set a fixed stepsize?

`sol = solve(monte_prob, num_monte=n, dt=0.001,adaptive=false)`, though you should consider using ``sol = solve(monte\_prob, num\_monte=n, saveat=0.001)` instead for stability and accuracy.

---

<div class="post-metadata">

**Author:** ![SSkor](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sskor/32/7623_2.png) [@SSkor](https://discourse.julialang.org/u/SSkor)\
**Post date:** [April 5, 2019, 12:59pm UTC](https://discourse.julialang.org/t/how-to-set-a-fixed-stepsize-in-sde-monte-carlo-problem/22744/3 "2019-04-05T12:59:16Z")

</div>

Thank you! It works!  
I’d like to make an attempt to delve deeper. What is better to use `NoiseProcess` or `SDEProblem`?

```julia
μ=0.15
σ=.3
u₀=1.0
f(u,p,t) = α*u
g(u,p,t) = β*u
prob = SDEProblem(f,g,u₀,(0.0,1.0))
monte_prob = MonteCarloProblem(prob)
sol = solve(monte_prob, num_monte=n, saveat=0.001)

```

```julia
W = GeometricBrownianMotionProcess(μ,σ,0.0,1.0,nothing)
prob = NoiseProblem(W,(0.0,1.0))
monte_prob = MonteCarloProblem(prob)
sol = solve(monte_prob, num_monte=n, dt=0.001, adaptive=false)

```

---

<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:** [April 5, 2019, 4:17pm UTC](https://discourse.julialang.org/t/how-to-set-a-fixed-stepsize-in-sde-monte-carlo-problem/22744/4 "2019-04-05T16:17:21Z")

</div>

> [@SSkor](#):
>
> I’d like to make an attempt to delve deeper. What is better to use `NoiseProcess` or `SDEProblem`

If it’s simple enough to have an analytical solution then you should use the noise process directly
