SodesPy (Stochastic Ordinary Differential Equations Suite in Python) is a high-performance library for numerically solving stochastic differential equations (SDEs).
Project description
SodesPy
SodesPy (Stochastic Ordinary Differential Equations Suite in Python) is a high-performance library for numerically solving stochastic differential equations (SDEs).
SodesPy provides many Ito and Stratonovich discretization schemes, an intuitive interface to define SDE systems and the option to solve them using CPU, GPUs or even TPUs.
With SodesPy you can solve, for example, the following (and many more) well known SDEs:
- Heston Model. A model for determining the evolution of the volatility of an underlying asset.
- Geometric Brownian Motion. The basic model for stock prices under Black–Scholes framework.
- Ornstein Uhlenbeck Process. A model with applications in mathematical finance and physics.
- Affine short rate. A general class for short rate models.
- Stochastic SIR Epidemic Model. A compartmental epidemiologic model.
- Stochastic Lorenz Attractor. A stochastic form of the classic Lorenz Attractor system.
Furthermore, SodesPy offers the following discretization schemes:
-
Classic:
- Euler. Classical scheme with 0.5 strong convergence and general noise.
-
Stochastic Runge Kutta (SRK):
Examples
If you want to define an Euler process you need to define the drift and diffusion functions, the discretization step and the initial condition. Taking this into account, an Euler process input file looks like:
from sodespy import *
scheme = "Euler"
noise_type = "Diagonal"
x0 = [.1, .1]
dt = 1 / 252
paths = 1000
tspan = (0.0, 1.0)
μs = [0.05, 0.044]
σs = [0.05, 0.044]
mu = [lambda x, t: μs[i] * x[i] for i in range(2)]
sigma = [lambda x, t: σs[i] * x[i] for i in range(2)]
sdes = SDESystem(mu, sigma, noise_type, scheme, x0, tspan, dt, paths)
sdes.simulate()
Another nice example that shows the flexibility of SodesPy is the Lorenz attractor, which can be written as:
from sodespy import *
scheme = "Euler"
noise_type = "Diagonal"
paths = 1
tspan = (0.0, 20.0)
dt = 1 / 252
x0 = [1.0, 0.0, 0.0]
α = 10.0
β = 28.0
γ = 8 / 3
mu = [lambda x, t: α * (x[1] - x[0]),
lambda x, t: x[0] * (β - x[2]) - x[1],
lambda x, t: x[0] * x[1] - γ * x[2]]
sigma = [lambda x, t: 10.0,
lambda x, t: 10.0,
lambda x, t: 10.0]
sdes = SDESystem(mu, sigma, noise_type, scheme, x0, tspan, dt, paths)
sdes.simulate()
plt.plot(sdes.solution)
plt.show()
This will plot the beautiful Lorenz attractor:
Installation
SodesPy can be installed via pip install sodespy
Author
SodesPy is authored by mpkuperman
License
SodesPy is distributed under the GPL-3.0 License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file sodespy-0.0.1.tar.gz
.
File metadata
- Download URL: sodespy-0.0.1.tar.gz
- Upload date:
- Size: 20.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8cee1c60dc29ce2f41fafdd53b0b677d43af948e114047067a9e2b0df42f01c4 |
|
MD5 | e2bb39861ed07a3b9665d9109ad1121e |
|
BLAKE2b-256 | 5eee9b6d24a3604e57a32d6b86e3871e6492f41e880f3d8f458e2e38d3a60e23 |
File details
Details for the file sodespy-0.0.1-py3-none-any.whl
.
File metadata
- Download URL: sodespy-0.0.1-py3-none-any.whl
- Upload date:
- Size: 20.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0a14fd373da31cf86065f4fb641cfc902c7a0c87cb24a2e356dcf4b240b5d793 |
|
MD5 | 68f5d053f6b0efac632985b2b46f491b |
|
BLAKE2b-256 | bd3857ffaa12d71094fa0fdc44ce7ba09408ce4db53537d9bbc65137cd4c320a |