Package: fbm
Exact methods for simulating fractional Brownian motion (fBm) or fractional
Gaussian noise (fGn) in python.Approximatesimulation of multifractional Brownian motion (mBm) or
multifractional Gaussian noise (mGn).InstallationThe fbm package is available on PyPI and can be installed via pip:pip install fbmfractional Brownian motionFractional 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:fromfbmimportFBMf=FBM(n=1024,hurst=0.75,length=1,method='daviesharte')# orf=FBM(1024,0.75)# Generate a fBm realizationfbm_sample=f.fbm()# Generate a fGn realizationfgn_sample=f.fgn()# Get the times associated with the fBmt_values=f.times()wherenis the number of equispaced increments desired for a fBm with Hurst
parameterhurston the interval [0,length]. Method can be
either'hosking','cholesky', or'daviesharte'. Thefbm()method returns a lengthn+1array of discrete values for the fBm (includes
0). Thefgn()method returns a lengthnarray of fBm
increments, or fGn. Thetimes()method returns a lengthn+1array of
times corresponding to the fBm realizations.Thenandhurstparameters are required. Thelengthparameter
defaults to 1 andmethoddefaults 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:fromfbmimportfbm,fgn,times# Generate a fBm realizationfbm_sample=fbm(n=1024,hurst=0.75,length=1,method='daviesharte')# Generate a fGn realizationfgn_sample=fgn(n=1024,hurst=0.75,length=1,method='daviesharte')# Get the times associated with the fBmt_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 parameterhurstis close to
1 and there are a small amount of incrementsn. 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 motionThis package supportsapproximategeneration of multifractional
Brownian motion. The current method uses the Riemann–Liouville fractional
integral representation of mBm.Usage:importmathfromfbmimportMBM# Example Hurst function with respect to time.defh(t):return0.25*math.sin(20*t)+0.5m=MBM(n=1024,hurst=h,length=1,method='riemannliouville')# orm=MBM(1024,h)# Generate a mBm realizationmbm_sample=m.mbm()# Generate a mGn realizationmgn_sample=m.mgn()# Get the times associated with the mBmt_values=m.times()Thehurstargument 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:fromfbmimportmbm,mgn,times# Define a hurst functiondefh(t):return0.75-0.5*t# Generate a mbm realizationmbm_sample=mbm(n=1024,hurst=h,length=1,method='riemannliouville')# Generate a fGn realizationmgn_sample=mgn(n=1024,hurst=h,length=1,method='riemannliouville')# Get the times associated with the mBmt_values=times(n=1024,length=1)Riemann-Liouville representation method:Approximatemethod originally proposed for fBm inRambaldi, 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 inMuniandy, 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.