Library for generating various stochastic price sequences
Project description
Price process generator
A synthetic data source
This library provides various vectorized generators of stochastic processes modelling price dynamics. The generated synthetic price data can be used in Monte Carlo simulations (or similar statistical experiments) and potentially as training data.
Currently the implemented generators:
Planned features:
- Generative adversarial network (GAN) implementation
- Improved interface with
ising.py
Installation
pip install price_process
to get the current PyPi version or clone this repo and run pip install .
in the directory
for most recent version.
Basic usage
The textbook stochastic price model
The standard model of stochastic price dynamics is the SDE
with solution the geometric Brownian motion
In order to display, say 10 samples of a 1000 point process, one would run
from price_process.process import *
price_proc = Gaussian([1000, 10]).to_geometric(0, 0.04)
price_proc.plot()
The np.ndarray
output is accessed through price_proc.process
The Levy stable process
The most immediate generalization to the Wiener process (Brownian motion) that is still relevant to asset pricing is the Levy stable process which introduces two parameters that respectively changes the tail weight and skewness as compared to the normal distribution.
As in the previous example, we run
from price_process.process import *
Levy(1.5, 0.02, [1000, 10]).to_geometric(0, 0.05).plot().plot()
Ising price model
Perhaps the most interesting generator that is currently implemented is the Ising model of price dynamics. This is a statistical mechanical model that captures the competition between going with the local consensus trade decision and contradiciting the consensus. Please refer to my notebook for details of the model.
from price_process.process import *
Ising(0.05, 500, [1000, 10]).plot()
Note that Ising(...).process
is already a price process so one should not evoke .to_geometric(drift, vol)
. See
the documentation for all the parameters of this model and recommended ranges.
Custom process
Custom generators can be implemented by subclassing Process
. The only requirement is that self.size
to be
given as an input of shape [n_steps, n_samples]
and the desired process to be assigned to self.process
.
Here is how one might implement the gamma process for instance
from price_process.process import *
from scipy.stats import gamma
import numpy as np
class Gamma(Process):
def __init__(self, alpha, beta, size, initial=0, T=1):
super().__init__(size, initial=initial, T=T)
self.alpha, self.beta = alpha, beta
self.rvs = gamma.rvs(alpha, size=self.size, scale=1/self.beta)
self.process = np.cumsum(self.rvs, axis=0)
See this notebook for a more advanced use case (Gamma sampled Wiener process).
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Hashes for price_process-1.1.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 32c105b2af00c7107b8e96dca67c89d3857a34ed090aeb45dddfdb5868f3d84d |
|
MD5 | 26109939588f301c89cca39c3e2c0c9e |
|
BLAKE2b-256 | eb258576425584dcae5fba0abb831e92329e47d66834135a87dd39848d0fae2e |