Replication Code — Beyond Binary: The Architectural Efficiency of Ternary Regime-Switching
This Python script implements the methodology described in: “Beyond Binary: The Architectural Efficiency of Ternary Regime-Switching”
It executes a longitudinal backtest from 1977 through February 2026 to demonstrate the performance and risk-mitigation properties of the Ternary Regime Framework (TRF). By coordinating 13-month exponential moving averages with MACD momentum, the code simulates the TRAF Sticky architecture—a state-dependent logic that ignores “neutral” market noise to prevent costly whipsaws.
The script verifies how this ternary approach captures structural equity expansion while transitioning to 3-month Treasury bills during confirmed systemic contractions. The final output provides direct confirmation of the research results, including the stabilized Sharpe Ratio plateau, the 14.15% maximum drawdown, and the documented 77% reduction in the Ulcer Index relative to the S&P 500.
Click here for the code:
Python Code Access
The code is provided for educational and research purposes only.

