# Algorithmic Trading on Bitcoin with Market Microstructure Resilience Testing ## Thesis Overview This repository contains the source code, data, and manuscript for the Bachelor of Science in Computer Science thesis titled **"Algorithmic Trading on Bitcoin with Market Microstructure Resilience Testing."** The research investigates the limitations of static mean-reversion strategies in non-stationary cryptocurrency markets and proposes an adaptive architecture using Hidden Markov Models (HMM) to mitigate catastrophic risk. --- ## Abstract This study attempted to develop a profitable mean-reversion strategy for Bitcoin using Volume-Enhanced Bollinger Bands (VEBB). The research hypothesized that volume anomalies (Z-Score > 2.0) could filter false signals in the non-stationary 2025 market. While the volume signal showed significant promise during the 2024 calibration period (improving Profit Factor from 0.90 to 1.79), the strategy failed to maintain profitability during out-of-sample validation (-8.65% return). An adaptive HMM architecture was introduced to mitigate these losses, successfully reducing maximum drawdown usage by 98.7% but failing to achieve positive returns (-1.30%). These results suggest that while volume anomalies capture meaningful microstructure events, these signals are not consistently tradeable using static execution parameters in high-volatility regimes. The primary contribution of this research is the empirical demonstration of the failure of static parameters to generalize out-of-sample, limiting the scope of the study to variance reduction rather than wealth generation. --- ## System Architecture The project evolved through two distinct phases: ### Phase 1: Static VEBB (Baseline) - **Logic:** Traditional Mean-Reversion using Bollinger Bands + Volume Z-Score + On-Balance Volume (OBV). - **Implementation:** Pine Script v6 (TradingView). - **Performance:** Suffered -20.4% capital loss during the 2025 liquidity crisis due to chronic overtrading in trending markets. ### Phase 2: Adaptive HMM VEBB (Proposed Solution) - **Logic:** Unsupervised regime classification using Gaussian Hidden Markov Models. - **Features:** Garman-Klass Volatility, Hurst Exponent, Volume Flow. - **Mechanism:** A "Circuit Breaker" that actively disables trading during detected "Crisis Regimes" (State 0). - **Performance:** Achieved -1.3% drawdown (Survival) vs -20.4% baseline loss. Validated that variance reduction is the primary benefit of regime-switching models in crypto. --- ## Repository Structure ### /Latex Contains the full thesis manuscript and build files. - `sp.pdf`: The final compiled thesis document (73 pages). - `chapters/`: Source LaTeX files for each chapter. - `sp.tex`: Main document controller. ### /Code - `reactive_vebb.py`: The core Python backtesting engine implementing the HMM logic and walk-forward validation. - `regime_features.py`: Feature engineering module for Garman-Klass and Hurst calculations. ### /Data - Historical BTCUSDT 15-minute data (2023-2025) sourced from Binance via TradingView. --- ## Key Findings & Methodology 1. **Non-Stationarity:** Static parameters optimized for 2024 failed in 2025, proving the "Stationarity Trap" hypothesis. 2. **Volume Anomalies:** Volume Z-Scores > 2.0 served as reliable filters for 50th-percentile volatility regimes but failed during liquidity cascades. 3. **Survival Metric:** The primary metric of success was shifted from "Profit Maximization" to "Drawdown Mitigation" after the HMM demonstrated a 92% reduction in trade frequency during crash periods. 4. **Statistical Integrity:** The study acknowledges that while the regime-filtered configuration showed a Profit Factor of 1.50, the sample size (N=24) is insufficient for statistical significance, positioning the result as anecdotal evidence for future research rather than a production-ready strategy. ## Authors - [Author Names Redacted for Repository Privacy] - Department of Computer Science - Ateneo de Naga University