#Introduction
PyS3DE is a solver of stochastic differential equations (SDE) implemented by Python, which both symbolic and numeric schemems are supported.
Numerical solvers include schemes for both with and without jumps.
Note: Scitools is used to generated the picture of simulated data only. To keep minimal necessary Python modules/libraries, it would be removed in TODO list. (Thanks, Yoav Ram) Necessary required submodules of scitools have been added to PySDE since 0.4; this means that scitools is not to be installed.
##Optional:
##Installation
-
Extract the source and enter the source directory
- Python2 version: cd Python2; python setup.py install
- Python3 version: cd Python3; python setup.py install
the files in demos include
- DiffusionJumps-1.sws DiffusionJumps.sws (for Sage notebook)
- demo.py
- sdedemo.tm, sdeJump.tm (for TeXmacs and Python plugin)
- sdedemo.ipynb (for IPython notebook)
- sdedemo.pdf
##Usages
- Symbolic Computation
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
(t+1)2 (
-at(t₀ + 1)2+ a t₀(t₀+ 1)2+ aw(t₀ + 1)2+ x₀)
───────────────────────────
(t₀ + 1)2
- Numeric Computation
import matplotlib.pylab as plt
from matplotlib import rc
rc('font',\*\*{'family':'sans-serif','sans-serif':['Helvetica']})
rc('text', usetex=True)
""" setup picture info """
plt.figure(figsize=(5,2))
plt.ylim(-0.5,1.5)
""" Initial data """
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.legend()
plt.savefig('Milstein.eps')
##Note
-
Symbolic/Numberic SDE solvers depend on part of the Scitools module which had been extracted and incorporated with the library, which it is not necessary to install scitools again.
-
Schemes for simulating SDE’s with jumps adds, see demo.
##DEMO
- python code: http://diffusion.cgu.edu.tw/ftp/sde (demo.py)
- TeXmacs with Python plugin: http://diffusion.cgu.edu.tw/ftp/sde (sdedemo.py)
- TeXmacs with Python plugin: SDE with jumps http://diffusion.cgu.edu.tw/ftp/sde (sdejump.py)
- Sage notebook(): http://diffusion.cgu.edu.tw/ftp/sde DiffusionJumps.sws, DiffusionJumps-1.sws
##Developer:
chu-ching huang: cchuang2009@gmail.com