HurstExponent — Hurst Exponent
תוכן זה אינו זמין עדיין בשפה שלך.
A rescaled-range estimate of persistence: above 0.5 the series trends, below 0.5 it mean-reverts, 0.5 is a random walk. The classic answer to “is this instrument worth trend- following at all”.
Signature
HurstExponent(period, on=<source>)| Argument | Type | Required | Notes |
|---|---|---|---|
period |
int Param or literal | Yes | Return window. Default 64, bounds 16–400. |
on= |
symbol, OHLCV field, or indicator | No | Source. Defaults to the trade symbol’s close. |
Formula
The window of log returns is cut into non-overlapping chunks of n/8, n/4, n/2 and n
returns (newest first). Each chunk’s rescaled range R/S — the range of its cumulative
deviations from its mean over its standard deviation — is averaged per size, and H is the
least-squares slope of log(R/S) against log(size):
$$ H = \frac{k\sum x_i y_i - \sum x_i \sum y_i}{k\sum x_i^2 - (\sum x_i)^2}, \quad x_i = \log s_i, \quad y_i = \log \overline{(R/S)}_{s_i} $$
Warmup
period + 1 bars; 0.5 (the random-walk value) until then.
Reading the value
hurst.valuehurst.value > 0.55Example
class HurstRegime(Strategy): """Trend-follow only in a persistent regime.""" trade = Symbol() sizing = FixedCapital()
def execute(self): hurst = HurstExponent(64, on=self.trade) sma = SMA(50, on=self.trade) if hurst.value > 0.55 and self.trade.close > sma.value and self.trade.is_flat: self.buy(self.trade, reason=f"Hurst {hurst.value:.2f}") if hurst.value < 0.45 and self.trade.is_long: self.sell(self.trade, self.trade.position, reason="Regime turned mean-reverting")Notes
- Harold Hurst (1951); the classic rescaled-range regression across four window sizes.
- Not clamped. The estimate is the slope, whatever it is: on short windows R/S is biased upward and a reading can leave [0, 1]. An earlier two-scale version clamped to [0, 1] and so sat at exactly 0.00 or 1.00 on about one daily bar in seven — a flat line that meant “the estimate broke down”, not “the market is maximally persistent”. Minimum period is 16, so the smallest chunk holds two returns.