15

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 ?

LeMiz
  • 5,554
  • 5
  • 28
  • 23
  • Note: This is very interesting material, but unfortunately it does not seem to include path/time dependant processes: http://pymc.googlecode.com/svn/doc/index.html) – LeMiz Oct 18 '09 at 11:15
  • Doing stuff like this for a living, I can assure you that you can get along with trivial code (ie. no variance reduction techniques) if you use quasirandom numbers (eg. Sobol sequences). – Alexandre C. Jul 01 '11 at 18:21
  • I also do that for a living (and in Paris too)! Being able the reuse the same drawings when simulating your underlyings can be very useful beside just reducing the estimator variance. And sobol sequences have their drawbacks, also. But of course, the question was about experimentation, not production code. – LeMiz Jul 03 '11 at 20:17
  • there are a few libraries I know of in R if they would be useful to you – pyCthon Dec 22 '12 at 20:04
  • @pyCthon, could you please share the names – Nick Oct 22 '22 at 00:17

5 Answers5

1

Have you looked at sage?

John La Rooy
  • 295,403
  • 53
  • 369
  • 502
1

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

gliptak
  • 3,592
  • 2
  • 29
  • 61
rlotun
  • 7,897
  • 4
  • 28
  • 23
0

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
  • 62,729
  • 22
  • 87
  • 114
  • 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 Oct 18 '09 at 11:20
0

You can use StochPy (Stochastic modeling in Python)

https://pypi.python.org/pypi/StochPy

Samir Alhejaj
  • 157
  • 2
  • 16
0

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!

Cam.Davidson.Pilon
  • 1,606
  • 1
  • 17
  • 31