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

question
#1

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.

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.

α=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?

#2

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.

1 Like
#3

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

μ=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)
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)
#4

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

2 Likes