pystable
: Stable distributions in Pythonpystable
is a Python module for calculating various
quantities related to stable distributions.
It implements
several parameterisations
and can convert
between them as required.
The generation of random variables is by an
algorithm of Chambers, Mallows and Stuck [CMS],
and the calculation of densities and distribution functions
is via the integral formula given in Nolan [N].
The module should be considered alpha quality. There are several known issues.
Here it is: pystable.py
.
Health warning! Although I work with stable distributions every day, I am not an expert in numerical methods, and I can't guarantee any level of accuracy for this code. I'd welcome any advice about implementation.
I don't have a proper Python package for this yet.
However, if you are on a Unix-based platform, you should
be able to simply put the file pystable.py
somewhere and run python in that
directory; you should then be able to import the module,
as below.
In addition to the standard library, the module requires the pygraph and scipy packages.
Here are a few simple use cases.
from pystable import * import pylab st = StableVar(pn_ST,alpha=1.5,beta=0.5) # Draw a histogram: x = rstable(10000,st) pylab.hist(x,bins=100,range=(-10,10)) # heavy tails make the cutoff essential pylab.show() # My First Stable Process Simulation pylab.cla() N = 100000 dt = 1/float(N) t = pylab.linspace(dt,1,N) x = map(lambda y: pow(dt, 1/st.params['alpha'])*y, rstable(len(t),st)) for i in range(len(x)-1): x[i+1] = x[i]+x[i+1] pylab.plot(t,x) pylab.show()
These produced the following pictures.
You might also have fun with this simple animation of a
stable process:
stable_anim.py
View online here: Documentation. This is an (accurate) draft.
A. R. Watson, `pystable' Python module.
URL http://caskly.org/arw/stable