backtrader.indicators.hurst module

Hurst Exponent Module - Hurst exponent indicator.

This module provides the Hurst Exponent indicator for measuring long-term memory of time series.

Classes:

HurstExponent: Hurst exponent indicator (alias: Hurst).

Example

class MyStrategy(bt.Strategy):
def __init__(self):

# Use at least 2000 samples for stable Hurst values self.hurst = bt.indicators.Hurst(self.data.close, period=2000)

def next(self):

# H > 0.5: trending series, H < 0.5: mean-reverting if len(self.data) >= 2000:

if self.hurst[0] > 0.5:

# Trend following strategy pass

class backtrader.indicators.hurst.HurstExponent[source]

Bases: PeriodN

Interpretation of the results

  1. Geometric random walk (H=0.5)

  2. Mean-reverting series (H<0.5)

  3. Trending Series (H>0.5)

Important notes:

  • The default period is 40, but experimentation by users has shown that it would be advisable to have at least 2000 samples (i.e.: a period of at least 2000) to have stable values.

  • The lag_start and lag_end values will default to be 2 and self.p.period / 2 unless the parameters are specified.

    Experimentation by users has also shown that values of around 10 and 500 produce good results

The original values (40, 2, self.p.period / 2) are kept for backwards compatibility

frompackages = (('numpy', ('asarray', 'log10', 'polyfit', 'sqrt', 'std', 'subtract')),)
alias = ('Hurst',)
__init__(*args, **kwargs)
next()[source]

Calculate Hurst Exponent for the current bar.

once(start, end)[source]

Calculate Hurst Exponent in runonce mode

packages = ()
backtrader.indicators.hurst.Hurst

alias of HurstExponent