How to use DifferentialEquations.jl to do a Monte Carlo

Hi,
I managed to simulate (with EnsembleProblem ) 1000 paths of a 2-dimensional SDE. Let’s call the one dimensional components x(t) and y(t). I have some problems handling the solution to the problem: the paths are of different lengths ( hence I cannot call Array(sol) ) and the solutions’ “u” are computed at different times, is this normal as the default behaviour?. I’d like to know how to get for each path the cumulative time integral of x(t)*y(t), and then compute the Monte Carlo average across the paths.
I include some code for reference:

X₀ = [0.01, p.ωb]
prob_x = SDEProblem(μ, Σ, X₀, T_span, p, noise_rate_prototype = zeros(2, 2))
ensembleprob = EnsembleProblem(prob_x)
sol_SDE = solve(ensembleprob, EnsembleThreads(), trajectories = 1000)

Yes, if you use adaptive time stepping then they will be calculated at different times. If you want it to save all at the same times, use saveat. For example:

sol_SDE = solve(ensembleprob, EnsembleThreads(), trajectories = 1000, saveat = 0.1)

saves at every dt=0.1. For more information, see the output control options in:

The best thing to do is just add a psuedo term to the SDE that is du[3] = u[1]*u[2], and thus u[3] is the integral.

2 Likes