Skip to main content

Library for generating various stochastic price sequences

Project description

Price process generator

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/planned generators are

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

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 for a more advanced use case.

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.0-py3-none-any.whl (3.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: price_process-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 3.5 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f8fac5fffb32b904fffb8cdb69b0d1205a6f53571b1b3abdb1dd4776789fb160
MD5 211fa488488290b86ede86cc5746928d
BLAKE2b-256 d70db6e45f8d1eeedd2d9d5b7454a0a9a8857cefd1f293067b999d413340799c

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