# Sensitivity of a SDE w.r.t tspan

Hi all,

I’m using SciMLSensitivity.jl to get the sensitivities of the transformation defined by:

f(S_T) = exp(- r * T) * max(S(T) - K, 0.0),

where S_T is the solution at time T of a SDE system of the form:

dS_t = \mu * S_t * dt + \sigma * S_t * dW_t .

I’m particularly interested in computing the derivative of f w.r.t t, i.e:

\frac{\partial f(S_t)}{\partial t} \vert_{t=0}

Unfortunately, I can’t get the correct results.

When running the following example not only \frac{\partial f(S_t)}{\partial t} \vert_{t=0} breaks but all the other derivatives too:

using DifferentialEquations
using SciMLSensitivity
using ForwardDiff
using Statistics

f(u, p, t) = p * u
g(u, p, t) = p * u
out(u, p)  = max(u(p) - p, 0.0)

u0 = 100.
μ  = 0.02
σ  = 0.12
K  = 90.0
T  = 1.0
p  = [u0, μ, σ, T, K]

prob = SDEProblem{false}(f, g, u0, (0.0, 1.0), p)

function mean_of_solution(x)
_prob = remake(prob; u0 = x, p = x, tspan=(0.0, x))
ens   = EnsembleProblem(_prob, output_func = (sol, i) -> (out(sol, x), false))
sol   = solve(ens, EM(); dt=1/252, trajectories=10000, sensealg=ForwardDiffSensitivity())
v     = exp(- x * x) * mean(sol)

return v
end



Moreover, when running this example

using DifferentialEquations
using SciMLSensitivity
using ForwardDiff
using Statistics

f(u, p, t) = p * u
g(u, p, t) = p * u
out(u, p)  = max(u(p) - p, 0.0)

u0 = 100.
μ  = 0.02
σ  = 0.12
K  = 90.0
T  = 1.0
p  = [u0, μ, σ, T, K]

prob = SDEProblem{false}(f, g, u0, (0.0, 1.0), p)

function mean_of_solution(x)
_prob = remake(prob; u0 = x, p = x, tspan=(0.0, 1.0))
ens   = EnsembleProblem(_prob, output_func = (sol, i) -> (out(sol, x), false))
sol   = solve(ens, EM(); dt=1/252, trajectories=10000, sensealg=ForwardDiffSensitivity())
v     = exp(- x * x) * mean(sol)

return v
end


Hi Chris, yes sure 