Skip to main content

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

Maintenance Documentation Status Binder

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

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

price_process-1.1.2-py3-none-any.whl (8.4 kB view details)

Uploaded Python 3

File details

Details for the file price_process-1.1.2-py3-none-any.whl.

File metadata

  • Download URL: price_process-1.1.2-py3-none-any.whl
  • Upload date:
  • Size: 8.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.4 pkginfo/1.7.1 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.8.5

File hashes

Hashes for price_process-1.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 baa2b5d2c56864b28bd1dde45265d66e25ca4ca3b973ec09caa064f6580ed585
MD5 d9ae2e9c2e14fa7464ce78dc5dacd804
BLAKE2b-256 9056ede75c20cf976f063b9b9f3930c1980dea709f8a13be0e3dd2232bfdc452

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page