pricegen
This utility helps simulate statistically randomized series of prices, based on the models below:
- Geometric Brownian motion
- Mean reversion (optional)
Generating a next price
from pricegen import random_price
current_price = 100
next_price = random_price(current_price, sigma=0.20)
Generating a series of prices
from pricegen import random_price, generate_prices
initial_price = 100
# Daily prices over a year (252 trading days)
price = initial_price
for _ in range(252):
price = random_price(price, sigma=0.20, time=1.0/252)
print(price)
# Or equivalently:
for price in generate_prices(252, initial_price, sigma=0.20, time=1.0/252):
print(price)
Volatility and time interval
# These two calls are roughly equivalent
# Case 1:
random_price(price, sigma=0.20, time=1.0/252)
# Annual volatility: 20%
# Time interval: (1.0 / 252) year
# Case 2:
random_price(price, sigma=0.20/math.sqrt(252)) # time == 1.0 by default
# Daily volatility: 20% / sqrt(252)
# Time interval: 1.0 day
# Note:
# "time" represents the time interval relative to 1.0.
# "sigma" is interpreted as volatility for time == 1.0.
# Internally, there is no assumption about the unit of time (year/month/day).
Mean reversion
from pricegen import random_price
initial_price = 100
# Daily prices over a year (252 trading days)
price = initial_price
for _ in range(252):
price = random_price(price, sigma=0.20, time=1.0/252, mean=initial_price)
print(price)
# Mean reversion helps prevent the price from becoming too high or too low
# by attracting the price to a targe while maintaining a specific volatility.
Using a custom Random class
from pricegen import PriceGenerator
generator = PriceGenerator(random=custom_random)
# custom_random needs to have .gauss() method
generator.random_price(100, 0.20)
Ad-hoc random noise
from pricegen import random_price
random_price(100, 0.20, noise=custom_gauss(0.0, 1.0))
Metadata
Release files for pricegen 0.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pricegen-0.0.1.tar.gz | 2.9 kB | Without provenance | Details for pricegen-0.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pricegen-0.0.1-py3-none-any.whl | Python 3 | none | any | Details for pricegen-0.0.1-py3-none-any.whl |
Total release size: 7.3 kB
Release files / pricegen-0.0.1.tar.gz
| Download URL | pricegen-0.0.1.tar.gz |
|---|---|
| Size | 2.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
cd563761dde31cf68e45f1da65f40ab8899adbf93608b6d415da4738e5abeb9e
|
|
BLAKE2b-256 checksum How to use checksums |
ea51ffce608b3cad3b7bb1a37382efdb6d9d1722b0225c0803458299263f65fc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.3
|
Release files / pricegen-0.0.1-py3-none-any.whl
| Download URL | pricegen-0.0.1-py3-none-any.whl |
|---|---|
| Size | 4.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b542f97f5707a8d97e5837167e1b818265c3cb599ebb1496cdd1bf56a7d3c206
|
|
BLAKE2b-256 checksum How to use checksums |
ed604adad698e8359eb140bd6a4bbbce64e48b1e13e7a583b83e0752734835a4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.3
|
Security for pricegen 0.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.