Python Solver for Stochastic Differential Equations!
Project description
==================
Brief Introduction
==================
PyS^3DE = Python Solver via Sympy + SciPy/NumPy for Stochastic Differential Equations!
PyS^3DE is a solver of stochastic differential equations (SDE) implemented by Python, which both symbolic and numeric schemes are supported.
Numerical solvers include schemes for both with and without jumps.
============
Installation
============
python setup.py build
python setup.py install
======
Usages
======
Symbolic Computation
"""
d X(t) = drift dt + diffusion dWt
Here,
2 X(t) 2
drift= ─────── - a (1+t)
1+t
2
diffusion = a (1+t)
x(0)=x₀ ;t(0)=t₀
"""
from sympy import *
from pysde import *
""" Main Codes Here """
x,dx,w,dw,t,dt,a=symbols('x dx w dw t dt a')
x0 =Symbol('x0'); t0 = Symbol('t0')
drift=2*x/(1+t)-a*(1+t)**2;diffusion=a*(1+t)**2
sol=SDE_solver(drift,diffusion,t0,x0)
pprint(sol)
Got
2 2 2 2
(t+1) (-a t(t₀ + 1) + a t₀(t₀+ 1) + a w (t₀ + 1) + x₀)
─────────────────────────────────────────────────────────
2
(t₀ + 1)
Numeric Computation
"""
d X(t) = -X(t) dt +X(t) d W(t)
"""
"""
Initial data
X(0)=1 for t in [0,10]
"""
x0=1.;t0=0.;tn=10.
x,dx=symbols('x dx')
[a,b,c,d]=[0,-1.,0,1.]
drift=a+b*x
diffusion=c+d*x
nt=200
T= linspace(t0, tn, nt+1)
""" Numerical Computation"""
X=Euler(drift,diffusion,x0,t0,tn,nt)
X,Y=Milstein(drift,diffusion,x0,t0,tn,nt)
"""Make picture"""
plt.plot(T, X, color="blue", linewidth=2.5, linestyle="-", label="Euler")
plt.plot(T, Y, color="red", linewidth=2.5, linestyle="--", label="Milstein")
plt.plot(T, np.exp(-T), color="green", linewidth=2.5, linestyle="--", label=r"$\exp(-t)$")
plt.ylim(X.min()-0.2, X.max()+0.2)
plt.title(r"$d X_t=-dt+d W_t,X_0=1$")
plt.savefig('Milstein.eps')
<img src="http://pythonhosted.org/PyS3DE/index_files/sde.png">
======
Todo's
======
Demo's
* Simulation for SDE's with Jumps
Brief Introduction
==================
PyS^3DE = Python Solver via Sympy + SciPy/NumPy for Stochastic Differential Equations!
PyS^3DE is a solver of stochastic differential equations (SDE) implemented by Python, which both symbolic and numeric schemes are supported.
Numerical solvers include schemes for both with and without jumps.
============
Installation
============
python setup.py build
python setup.py install
======
Usages
======
Symbolic Computation
"""
d X(t) = drift dt + diffusion dWt
Here,
2 X(t) 2
drift= ─────── - a (1+t)
1+t
2
diffusion = a (1+t)
x(0)=x₀ ;t(0)=t₀
"""
from sympy import *
from pysde import *
""" Main Codes Here """
x,dx,w,dw,t,dt,a=symbols('x dx w dw t dt a')
x0 =Symbol('x0'); t0 = Symbol('t0')
drift=2*x/(1+t)-a*(1+t)**2;diffusion=a*(1+t)**2
sol=SDE_solver(drift,diffusion,t0,x0)
pprint(sol)
Got
2 2 2 2
(t+1) (-a t(t₀ + 1) + a t₀(t₀+ 1) + a w (t₀ + 1) + x₀)
─────────────────────────────────────────────────────────
2
(t₀ + 1)
Numeric Computation
"""
d X(t) = -X(t) dt +X(t) d W(t)
"""
"""
Initial data
X(0)=1 for t in [0,10]
"""
x0=1.;t0=0.;tn=10.
x,dx=symbols('x dx')
[a,b,c,d]=[0,-1.,0,1.]
drift=a+b*x
diffusion=c+d*x
nt=200
T= linspace(t0, tn, nt+1)
""" Numerical Computation"""
X=Euler(drift,diffusion,x0,t0,tn,nt)
X,Y=Milstein(drift,diffusion,x0,t0,tn,nt)
"""Make picture"""
plt.plot(T, X, color="blue", linewidth=2.5, linestyle="-", label="Euler")
plt.plot(T, Y, color="red", linewidth=2.5, linestyle="--", label="Milstein")
plt.plot(T, np.exp(-T), color="green", linewidth=2.5, linestyle="--", label=r"$\exp(-t)$")
plt.ylim(X.min()-0.2, X.max()+0.2)
plt.title(r"$d X_t=-dt+d W_t,X_0=1$")
plt.savefig('Milstein.eps')
<img src="http://pythonhosted.org/PyS3DE/index_files/sde.png">
======
Todo's
======
Demo's
* Simulation for SDE's with Jumps