This directory contains a complete implementation of the Log-Periodic Power Law Singularity (LPPLS) model for Bitcoin bubble detection and prediction, as described in LPPLS-model.md.
lppls_backtest.py - Main LPPLS model implementation with backtesting frameworklppls_usage_guide.py - Complete usage guide with examples and explanationslppls_comprehensive_demo.py - Comprehensive demonstration across different time periodsdemo_lppls.py - Simple demonstration scripttest_lppls.py - Basic functionality tests
from lppls_backtest import LPPLSBacktest
# Initialize the system
lppls = LPPLSBacktest()
# Run backtest on recent data
results = lppls.run_backtest(
start_date='2024-01-01',
end_date='2024-11-30',
window=10, # Days for slope calculation
tc_threshold=5, # Days before critical time for signals
slope_threshold=0.001 # Signal sensitivity
)
# Get future predictions
future_pred = lppls.predict_future(days_ahead=30)
The LPPLS model identifies financial bubbles by fitting price data to:
p(t) = A + B(tc - t)^m (1 + C * cos(ω * log(tc - t) + φ))
Where:
A: Final price level after bubbleB: Amplitude of power-law decaytc: Critical time (bubble peak/crash)m: Power-law exponent (0 < m < 1)C: Oscillation amplitudeω: Angular frequencyφ: Phase✅ LPPLS Model Fitting - Uses differential evolution optimization for robust parameter estimation
✅ Local Slopes Analysis - Calculates trend slopes over moving windows to enhance signal quality
✅ Signal Generation - Generates buy/sell signals when approaching critical times with favorable trends
✅ Backtesting Framework - Complete portfolio simulation with performance metrics
✅ Future Prediction - Extrapolates model to predict future prices and critical events
✅ Flexible Data Sources - Supports both yfinance API and local CSV data
✅ Comprehensive Analysis - Includes Sharpe ratio, max drawdown, and trade analysis
python lppls_usage_guide.py
python lppls_comprehensive_demo.py
python demo_lppls.py
🔴 CRITICAL: Extreme Window Sensitivity Detected
The LPPLS model exhibits 100%+ prediction variance depending on training window size. A comprehensive sensitivity analysis (see full report) revealed:
⚠️ DO NOT use single LPPLS predictions for investment decisions!
Recommended approach:
See also:
⚠️ Best for Bubble Detection: Model designed for bubble periods, not general prediction
⚠️ Historical Data Required: Needs 100+ days for reliable fitting
⚠️ Parameter Sensitivity: Results depend on parameter choices (window size is the most critical)
⚠️ No Guarantees: Statistical model, not deterministic prediction
⚠️ Research Tool: Use for analysis, not standalone trading
Based on the work of:
scipy.optimize.differential_evolution for global optimizationPotential improvements:
For detailed technical information, see the original research documentation in LPPLS-model.md.