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

price_process-1.1.3-py3-none-any.whl (8.6 kB view hashes)

Uploaded Python 3

Supported by

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