# Running a Stratonovich SDE backwards

I’m very new to Julia, SDE’s and DifferentialEquations, so please bear with me. I need to solve a Stratonovich SDE both forward and backward in time, and arrive at the exact same solution. I understand that this should be possible to do using the EulerHeun solver but I haven’t gotten it to work.

This is what I have so far. I tried to adapt the code used in this answer to a related question about solving an SDE en separate windows in a consistent manner.

``````using DifferentialEquations, RandomNumbers

# Define the problem
f(dx, x, u, t) = (dx .= x)
g(dx, x, u, t) = (dx .= x)
dt = 2^(-6)

# Solve for 0-1
rng = Xorshifts.Xoroshiro128Plus(1)
x0 = [1 / 2]
tspan = (0., 1.)
noise = WienerProcess(0., 0., rng=rng, reseed=false)
prob = SDEProblem(f, g, x0, tspan, noise=noise)
sol_part1 = solve(prob, EulerHeun(), dt=dt)
plot(noise.t,noise.u)

# Solve for 1-0
fback(dx, x, u, t) = (dx .= -x) # reverse drift
gback(dx, x, u, t) = (dx .= -x) # reverse diffusion
x1 = sol_part1.u[end] # start from the end
prob = SDEProblem(fback,gback, x1, reverse(tspan), noise=noise) # reverse tspan
sol_part2 = solve(prob, EulerHeun(), dt=-dt) # negate dt
sol_part2.u[end][1] ≈ x0[1] # not even remotely similar
``````

@frankschae has done a lot of this:

See the tests in: