Price dynamics can alternate between chaotic and orderly phases. When a system’s largest Lyapunov exponent drops and the correlation dimension compresses, trajectories become more predictable—often coinciding with trendable structure. Pairing this with a simple trend filter and Hurst exponent provides a compact framework to trade regime transitions rather than raw noise.
def next(self):
if self.order is not None:
return
# accumulate rolling returns
if not np.isnan(self.returns[0]):
self.returns_history.append(self.returns[0])
if len(self.returns_history) > self.p.lookback * 2:
self.returns_history = self.returns_history[-self.p.lookback * 2:]
# need enough history
if len(self.returns_history) < self.p.lookback:
return
# compute chaos metrics on the latest window
= np.array(self.returns_history[-self.p.lookback:])
recent = self.analyze_strange_attractor(recent)
lyap, corr_dim, hurst
# track previous regime state
= self.lyapunov_exponent
prev_lyap self.lyapunov_exponent = lyap
self.correlation_dimension = corr_dim
self.hurst_exponent = hurst
# trade only on transitions into "order" with trend alignment
= (lyap < self.p.lyap_threshold and prev_lyap >= self.p.lyap_threshold
long_setup and corr_dim < self.p.corr_dim_threshold
and self.data.close[0] > self.trend_ma[0])
= (lyap < self.p.lyap_threshold and prev_lyap >= self.p.lyap_threshold
short_setup and corr_dim < self.p.corr_dim_threshold
and self.data.close[0] < self.trend_ma[0])
# exits on renewed chaos
= (lyap > self.p.lyap_threshold * 2 and self.position)
chaos_exit
# alternative thrust: Hurst persistence gates with trend
= (hurst > 0.6 and self.data.close[0] > self.trend_ma[0] and not self.position)
hurst_long = (hurst < 0.4 and self.data.close[0] < self.trend_ma[0] and not self.position)
hurst_short
# execute
if long_setup:
if self.position.size < 0 and self.stop_order: self.cancel(self.stop_order)
self.order = self.close() if self.position.size < 0 else self.buy()
elif short_setup:
if self.position.size > 0 and self.stop_order: self.cancel(self.stop_order)
self.order = self.close() if self.position.size > 0 else self.sell()
elif chaos_exit:
if self.stop_order: self.cancel(self.stop_order)
self.order = self.close()
elif hurst_long:
self.order = self.buy()
elif hurst_short:
self.order = self.sell()
lyap_threshold
to demand cleaner order and fewer
trades in choppy assets.corr_dim_threshold
to isolate simpler
attractors; loosen to participate more.trend_period
to match the instrument’s dominant
cycle.= load_strategy("ChaosStrategy")
strategy
= "DOGE-USD"
ticker = "2018-01-01"
start = "2025-01-01"
end = 12
window_months
= run_rolling_backtest(ticker=ticker, start=start, end=end, window_months=window_months) df
Interpretation: The chaos–order regime framework achieved high total returns with a strong win rate and modest drawdowns relative to crypto’s inherent volatility. The strategy excelled in strong trending regimes (175% peak window gain) but also showed periods of muted performance when regime shifts were less distinct. This suggests the model’s edge is concentrated in high-persistence structural transitions—exactly where chaos theory predicts the largest predictability boost.