Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 look 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 ?

like image 942
LeMiz Avatar asked Oct 18 '09 10:10

LeMiz


2 Answers

Have you looked at sage?

like image 168
John La Rooy Avatar answered Sep 19 '22 18:09

John La Rooy


The closest I've seen to this in Python is PyMC - an implementation of various Markov Chain Monte Carlo algorithms.

like image 37
rlotun Avatar answered Sep 21 '22 18:09

rlotun