views:

401

answers:

3

Hello,

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 ?

A: 

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.

Chinmay Kanchi
This is a PDE solver, not a MC tool. I wish I could convert all my problems to a low dimension PDE... Right now, I am just wanting to investigate the look and feel of some models (what the trajectories look like for example)
LeMiz
+1  A: 

Have you looked at sage?

gnibbler
I haven't found a stochastic simulation package in Sage.
LeMiz
A: 

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

rlotun