-
-
Notifications
You must be signed in to change notification settings - Fork 49
Open
Description
I'm trying to use diffeqpy to simulate some trajectories of the geometric Brownian motion but I'm having some issues accessing the elements of the solution.
My code is the following:
from diffeqpy import de
import numpy as np
def gbm(A0, mu, sigma, t0, t1, dt=0.01, trajectories=1):
def f(du, u, p, t):
du[0] = u[0] * p[0]
def g(du, u, p, t):
du[0] = u[0] * p[1]
prob = de.SDEProblem(f, g, [A0], (t0, t1), [mu, sigma])
eprob = de.EnsembleProblem(prob)
return de.solve(
eprob,
de.SRIW1(),
de.EnsembleThreads(),
dt=dt,
adaptive=False,
trajectories=trajectories,
)
res = gbm(100.0, 0.05, 0.2, 0.0, 1.0, trajectories=5)In Julia, I would do simply res[1] to get the first path. I could then also do res[1](x) to get the value of that path at some arbitrary x in the domain of the solution. Can I do this in Python somehow?
When I try res[0] in Python, I get an error:
>>> res[0]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'PyCall.jlwrap' object is not subscriptableI know that I could bypass this partly by using saveat=np.arange(t0, t1 + dt, dt), for example, in the call to de.solve, but that requires knowing x in advance.
Metadata
Metadata
Assignees
Labels
No labels