Skip to main content

travis codecov pypi pyversions

  • Exact methods for simulating fractional Brownian motion (fBm) or fractional Gaussian noise (fGn) in python.

  • Approximate simulation of multifractional Brownian motion (mBm) or multifractional Gaussian noise (mGn).

Installation

The fbm package is available on PyPI and can be installed via pip:

pip install fbm

fractional Brownian motion

Fractional Brownian motion can be generated via either Hosking’s method, the Cholesky method, or the Davies-Harte method. All three methods are theoretically exact in generating a discretely sampled fBm/fGn.

Usage:

from fbm import FBM


f = FBM(n=1024, hurst=0.75, length=1, method='daviesharte')
# or
f = FBM(1024, 0.75)

# Generate a fBm realization
fbm_sample = f.fbm()

# Generate a fGn realization
fgn_sample = f.fgn()

# Get the times associated with the fBm
t_values = f.times()

where n is the number of equispaced increments desired for a fBm with Hurst parameter hurst on the interval [0, length]. Method can be either 'hosking', 'cholesky', or 'daviesharte'. The fbm() method returns a length n+1 array of discrete values for the fBm (includes 0). The fgn() method returns a length n array of fBm increments, or fGn. The times() method returns a length n+1 array of times corresponding to the fBm realizations.

The n and hurst parameters are required. The length parameter defaults to 1 and method defaults to 'daviesharte'.

For simulating multiple realizations use the FBM class provided as above. Some intermediate values are cached for repeated simulation.

For one-off samples of fBm or fGn there are separate functions available:

from fbm import fbm, fgn, times


# Generate a fBm realization
fbm_sample = fbm(n=1024, hurst=0.75, length=1, method='daviesharte')

# Generate a fGn realization
fgn_sample = fgn(n=1024, hurst=0.75, length=1, method='daviesharte')

# Get the times associated with the fBm
t_values = times(n=1024, length=1)

For fastest performance use the Davies and Harte method. Note that the Davies and Harte method can fail if the Hurst parameter hurst is close to 1 and there are a small amount of increments n. If this occurs, a warning is printed to the console and it will fallback to using Hosking’s method to generate the realization. See page 412 of the following paper for a more detailed explanation:

  • Wood, Andrew TA, and Grace Chan. “Simulation of stationary Gaussian processes in [0, 1] d.” Journal of computational and graphical statistics 3, no. 4 (1994): 409-432.

Hosking’s method:

  • Hosking, Jonathan RM. “Modeling persistence in hydrological time series using fractional differencing.” Water resources research 20, no. 12 (1984): 1898-1908.

Cholesky method:

  • Asmussen, Søren. Stochastic simulation with a view towards stochastic processes. University of Aarhus. Centre for Mathematical Physics and Stochastics (MaPhySto)[MPS], 1998.

Davies Harte method:

  • Davies, Robert B., and D. S. Harte. “Tests for Hurst effect.” Biometrika 74, no. 1 (1987): 95-101.

multifractional Brownian motion

This package supports approximate generation of multifractional Brownian motion. The current method uses the Riemann–Liouville fractional integral representation of mBm.

Usage:

import math
from fbm import MBM


# Example Hurst function with respect to time.
def h(t):
    return 0.25 * math.sin(20*t) + 0.5

m = MBM(n=1024, hurst=h, length=1, method='riemannliouville')
# or
m = MBM(1024, h)

# Generate a mBm realization
mbm_sample = m.mbm()

# Generate a mGn realization
mgn_sample = m.mgn()

# Get the times associated with the mBm
t_values = m.times()

The hurst argument here should be a callable that accepts one argument and returns a float in (0, 1).

For one-off samples of mBm or mGn there are separate functions available:

from fbm import mbm, mgn, times


# Define a hurst function
def h(t):
    return 0.75 - 0.5 * t

# Generate a mbm realization
mbm_sample = mbm(n=1024, hurst=h, length=1, method='riemannliouville')

# Generate a fGn realization
mgn_sample = mgn(n=1024, hurst=h, length=1, method='riemannliouville')

# Get the times associated with the mBm
t_values = times(n=1024, length=1)

Riemann-Liouville representation method:

Approximate method originally proposed for fBm in

  • Rambaldi, Sandro, and Ombretta Pinazza. “An accurate fractional Brownian motion generator.” Physica A: Statistical Mechanics and its Applications 208, no. 1 (1994): 21-30.

Adapted to approximate mBm in

  • Muniandy, S. V., and S. C. Lim. “Modeling of locally self-similar processes using multifractional Brownian motion of Riemann-Liouville type.” Physical Review E 63, no. 4 (2001): 046104.

Release files for fbm 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fbm 0.3.0
File Size Uploaded
fbm-0.3.0.tar.gz 9.5 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for fbm 0.3.0
File Interpreter ABI Platform
fbm-0.3.0-py3-none-any.whl Python 3 none any Details
fbm-0.3.0-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 28.2 kB

Release files / fbm-0.3.0.tar.gz

Download URL fbm-0.3.0.tar.gz
Size 9.5 kB
Tags Source
SHA-256 checksum
How to use checksums
4f1cf868a3af0bb0da88e7a87bfc8f868817af29e926b4bebcc96d4c362e72ee
BLAKE2b-256 checksum
How to use checksums
a952a241755499462dd688858ccced125be3d338555b7a0e4d5f101236b91c71
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.3

Release files / fbm-0.3.0-py3-none-any.whl

Download URL fbm-0.3.0-py3-none-any.whl
Size 9.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
88d30a0851cbe72ba9c5cc1b668e9e1c49f460ace21cce6ebe7aa0b7f681d358
BLAKE2b-256 checksum
How to use checksums
331469ba4b1b00790c2608a63cc695c93cef6d932ec83a7bba8cfa8245350f84
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.3

Release files / fbm-0.3.0-py2.py3-none-any.whl

Download URL fbm-0.3.0-py2.py3-none-any.whl
Size 9.4 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
8e03e230021f433d631dc289eecb6905a11a60eb6a89bd5a9dc4e66adcc22945
BLAKE2b-256 checksum
How to use checksums
16f8f103aa4947ae83ce8e91c448c284ac71b88e449e5418c7baff69c7c51624
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.3

Release history Release notifications | RSS feed

This release

0.3.0 This release

3 release files

0.2.0

2 release files

0.1.1

2 release files

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page