Stochastic calculus library in python
I am looking for a python library that would allow me to compute stochastic calculus stuff, like the (conditional) expectation of a random process I would define the diffusion. I had a lo开发者_JAVA百科ok a at simpy (simpy.sourceforge.net), but it does not seem to cover my needs.
This is for quick prototyping and experimentation. In java, I used with some success the (now inactive) http://martingale.berlios.de/Martingale.html library.
The problem is not difficult in itself, but there is a lot non trivial, boilerplate things to do (efficient memory use, variable reduction techniques, and so on).
Ideally, I would be able to write something like this (just illustrative):
def my_diffusion(t, dt, past_values, world, **kwargs): W1, W2 = world.correlated_brownians_pair(correlation=kwargs['rho']) X = past_values[-1] sigma_1 = kwargs['sigma1'] sigma_2 = kwargs['sigma2'] dX = kwargs['mu'] * X * dt + sigma_1 * W1 * X * math.sqrt(dt) + sigma_2 * W2 * X * X * math.sqrt(dt) return X + dX X = RandomProcess(diffusion=my_diffusion, x0 = 1.0) print X.expectancy(T=252, dt = 1./252., N_simul= 50000, world=World(random_generator='sobol'), sigma1 = 0.3, sigma2 = 0.01, rho=-0.1)
Does someone knows of something else than reimplementing it in numpy for example ?
Have you looked at sage?
The closest I've seen to this in Python is PyMC - an implementation of various Markov Chain Monte Carlo algorithms.
I know someone who uses Sundials to solve stochastic ODE/PDE problems, though I don't know enough about the library to be sure that it's appropriate in your case. There are python bindings for it here.
I'm working on a stochastic processes (including diffusion processes and some conditioning) python library. Check out this link to the google-project homepage. Cheers!
You can use StochPy (Stochastic modeling in Python)
https://pypi.python.org/pypi/StochPy
精彩评论