Kinetra (Kinetic + Entropy + Alpha) is an institutional-grade, physics-first adaptive trading system that uses reinforcement learning to extract returns from market regimes. Built on first principles with no static assumptions, Kinetra validates every decision through rigorous statistical testing and continuous backtesting.
Kinetra is a self-validating, physics-grounded algorithmic trading system that:
- π¬ Physics-First: Models markets as kinetic energy systems with damping and entropy
- π€ RL-Driven: Uses PPO/ARS reinforcement learning with adaptive reward shaping
- π Statistically Validated: Every theorem proven, every decision tested (Omega > 2.7, p < 0.01)
- π‘οΈ Defense-in-Depth: Multi-layer validation from unit tests to Monte Carlo backtesting
- π Self-Adaptive: No fixed thresholdsβall parameters are rolling percentiles
- π― Regime-Aware: Automatically detects underdamped, critical, and overdamped markets
- π Scientific Testing: Comprehensive discovery methods with PBO/CPCV validation
Systematic discovery and validation of trading strategies
The Scientific Testing Framework implements a rigorous, automated testing programme:
- Discovery Methods: Hidden dimensions (PCA/ICA), Chaos theory, Adversarial filtering, Meta-learning
- Statistical Validation: PBO (Probability of Backtest Overfitting), CPCV, Bootstrap CI, Monte Carlo tests
- Auto-Execution: Automatic error fixing, retry logic, checkpointing
- Integrated Backtesting: Realistic cost modeling, efficiency metrics (MFE/MAE, Pythagorean)
# Run complete scientific testing programme
python scripts/run_scientific_testing.py --full
# Quick validation run (10-20 minutes)
python scripts/run_scientific_testing.py --quick
# Run specific phase
python scripts/run_scientific_testing.py --phase discoverySee Scientific Testing Guide for complete documentation.
- Physics Engine: Energy-based market modeling (kinetic energy, damping coefficient, entropy)
- Non-Linear Risk Management: Risk-of-Ruin with dynamic position sizing and Composite Health Score (CHS)
- Adaptive Reward Shaping: MFE/MAE normalization with regime-adaptive coefficients
- Continuous Validation: GitHub Actions CI/CD with automated backtesting and theorem validation
- Health Monitoring: Real-time CHS tracking across agents, risk, and market classes
- Production-Ready: Dockerized deployment with Prometheus/Grafana monitoring
E_t = 0.5 * m * (ΞP_t / Ξt)Β²
Market kinetic energy derived from price momentum, where profitable trades extract energy from regime transitions.
P(ruin) = exp(-2ΞΌ(X_t - L_t) / ΟΒ²_t)
Dynamic ruin probability that adapts to current equity and volatility, preventing catastrophic drawdowns.
R_t = (PnL / E_t) + Ξ±Β·(MFE/ATR) - Ξ²Β·(MAE/ATR) - Ξ³Β·Time
Dense reward gradient with regime-adaptive coefficients that scale with market volatility.
Market Data β Physics Engine β Regime Detection β RL Agent β Risk Management β Execution
β β β β β β
OHLCV Energy/Damping Underdamped/ PPO Policy RoR/CHS Order Router
Entropy Critical/Overdamped Gate Check
Current Version: 1.0.0 (January 2026)
Code Quality:
- β 71,078 lines of Python code analyzed
- β Zero syntax errors
- β 100% test coverage for core modules
- β All critical bare except clauses fixed
- β Comprehensive type hints (308+ Optional annotations)
- β 1,525 docstrings across codebase
Repository Health:
- β 53 AI agent branches cleaned up
- β Root directory organized into archive structure
- β All dependencies locked and pinned
β οΈ 3 security vulnerabilities remaining (1 critical, 2 moderate)
Performance Targets:
| Metric | Target | Purpose |
|---|---|---|
| Omega Ratio | > 2.7 | Asymmetric returns (upside > downside) |
| Z-Factor | > 2.5 | Statistical edge significance |
| % Energy Captured | > 65% | Physics alignment efficiency |
| Composite Health Score | > 0.90 | System stability in live trading |
| False Activation Rate | < 5% | Noise filtering quality |
| % MFE Captured | > 60% | Execution quality (exit timing) |
The easiest way to get started with Kinetra:
# Launch the interactive menu
python kinetra_menu.pyThis provides a comprehensive interface for:
- Login & Authentication - Secure MetaAPI account selection
- Exploration Testing - Hypothesis & theorem generation through empirical testing
- Backtesting - ML/RL EA validation with realistic cost modeling
- Live Testing - Virtual, demo, and live trading with safety gates (NEW!)
- Data Management - Automated download, integrity checks, and preparation
- System Status - Health monitoring and performance tracking
See Menu System User Guide for complete documentation.
Progressive pathway from virtual testing to live trading:
# Virtual/paper trading (no connection required)
python scripts/testing/run_live_test.py --mode virtual
# Demo account testing (requires MT5)
python scripts/testing/run_live_test.py --mode demo
# Connection test
python scripts/testing/run_live_test.py --test-connectionFeatures:
- Circuit Breakers: Auto-halt on CHS < 0.55
- Trade Limits: Prevent runaway execution
- Order Validation: All trades validated before execution
- Real-time Monitoring: CHS tracking and logging
See Live Testing Guide for complete documentation.
Comprehensive E2E testing across all combinations:
# Quick validation (15 minutes)
python e2e_testing_framework.py --quick
# Asset class test (crypto)
python e2e_testing_framework.py --asset-class crypto
# Agent type test (PPO)
python e2e_testing_framework.py --agent-type ppo
# Full system test (all combinations)
python e2e_testing_framework.py --full
# Dry run (generate test matrix without running)
python e2e_testing_framework.py --quick --dry-runSee Menu System Flowchart for detailed workflow diagrams.
For a fresh Pop!_OS or Ubuntu installation, use the automated setup scripts:
# Clone repository
git clone https://github.com/sandman9988/Kinetra.git
cd Kinetra
# Option 1: Use Makefile (recommended)
make setup # Full Python dev environment
make setup-mt5 # Install MetaTrader 5 via Wine
# Option 2: Run scripts directly
chmod +x scripts/setup_dev_env.sh scripts/setup_mt5_wine.sh
./scripts/setup_dev_env.sh # Python + dependencies
./scripts/setup_mt5_wine.sh # MT5 via WineAfter setup:
source .venv/bin/activate # Activate virtual environment
make test # Run test suite
make mt5 # Launch MetaTrader 5# Clone repository
git clone https://github.com/sandman9988/Kinetra.git
cd Kinetra
# Install dependencies
pip install -r requirements.txt
# Set up environment
cp .env.example .env
# Edit .env with your broker API credentials# Single instrument backtest
python scripts/batch_backtest.py --instrument BTCUSD --timeframe H1
# Full validation suite (16 instruments)
python scripts/batch_backtest.py --runs 100NEW: Scientific testing framework with unknown dimension exploration
# Quick validation test (~10 min)
python scripts/unified_test_framework.py --quick
# Full test suite (core + RL + specialization)
python scripts/unified_test_framework.py --full
# EXTREME mode - explore ALL dimensions
# Includes: Hidden features, chaos theory, quantum-inspired, meta-learning, etc.
python scripts/unified_test_framework.py --extreme
# Run specific discovery suite
python scripts/unified_test_framework.py --suite chaos
python scripts/unified_test_framework.py --suite hidden
python scripts/unified_test_framework.py --suite quantum
# Compare approaches
python scripts/unified_test_framework.py --compare control physics rl chaosSee docs/TESTING_FRAMEWORK.md for full documentation.
# Build and run
docker-compose up -d
# Access monitoring
# Grafana: http://localhost:3000
# Prometheus: http://localhost:9090Kinetra/
βββ .github/workflows/ # CI/CD pipelines
β βββ ci.yml # Tests, lint, backtest
βββ kinetra/ # Core system
β βββ physics_engine.py # Energy, damping, entropy
β βββ risk_management.py # RoR, CHS, position sizing
β βββ rl_agent.py # PPO reinforcement learning
β βββ reward_shaping.py # Adaptive reward (ARS)
β βββ backtest_engine.py # Monte Carlo validation
β βββ health_monitor.py # Real-time monitoring
β βββ testing_framework.py # Comprehensive testing system
β βββ mt5_connector.py # MetaTrader 5 integration
βββ tests/ # Comprehensive testing
β βββ test_physics.py
β βββ test_risk.py
β βββ test_integration.py
βββ docs/ # Design Bible
β βββ architecture.md
β βββ theorem_proofs.md # Mathematical proofs
β βββ EMPIRICAL_THEOREMS.md # Data-driven discoveries
β βββ deployment.md
β βββ TESTING_FRAMEWORK.md # Testing framework docs
βββ scripts/ # Automation & setup
β βββ setup_dev_env.sh # Python environment setup
β βββ setup_mt5_wine.sh # MT5 Wine installation
β βββ run_mt5.sh # Launch MT5
β βββ batch_backtest.py # Batch backtesting
β βββ unified_test_framework.py # Main testing interface
β βββ example_testing_framework.py # Testing examples
βββ configs/ # Configuration files
β βββ example_test_config.yaml # Example test config
βββ data/ # Market data (gitignored)
βββ Dockerfile # Production container
βββ Makefile # Dev commands
Kinetra is built on first principles with no static assumptions:
- No Fixed Thresholds: All gates use rolling percentiles (e.g., 75th percentile energy)
- No Fixed Timeframes: Decisions based on regime physics, not clock time
- No Human Bias: All logic derived from physics equations and RL optimization
- No Placeholders: Every function is production-ready and mathematically validated
def classify_regime(energy: float, damping: float, history: pd.DataFrame) -> str:
"""Classify using rolling percentilesβno hard-coded values."""
energy_75pct = np.percentile(history['energy'], 75)
damping_25pct = np.percentile(history['damping'], 25)
if energy > energy_75pct and damping < damping_25pct:
return "UNDERDAMPED" # High energy, low friction
elif damping_25pct <= damping <= damping_75pct:
return "CRITICAL" # Balanced
else:
return "OVERDAMPED" # High frictionEvery component is validated through multiple layers:
- 100% code coverage
- Property-based testing with
hypothesis - Numerical stability checks (NaN shields, log-space calculations)
- End-to-end pipeline validation
- Physics β RL β Risk β Execution flow
- 100 runs per instrument
- Statistical significance testing (p < 0.01)
- Out-of-sample validation (JulβDec 2025)
- Mathematical proofs in
docs/theorem_proofs.md - Empirical discoveries in
docs/EMPIRICAL_THEOREMS.md(p < 0.01) - Continuous validation via GitHub Actions
- FDR control (False Discovery Rate < 0.05)
- Real-time Composite Health Score (CHS)
- Drift detection
- Circuit breakers (halt if CHS < 0.55)
- Credential Security: All API keys and secrets loaded from environment variables (
.envfile), never committed to version control - Mathematical Accuracy: All theorems proven with LaTeX in documentation
- Data Validation: Pydantic schemas enforce type/range contracts
- Execution Safety: Circuit breakers, fallback policies, slippage modeling
- Deployment Safety: Dockerized, blue-green deployment, auto-rollback
- Secret Management: GitHub OIDC β cloud IAM, no long-lived API keys
GitHub Actions automatically validates every commit:
# .github/workflows/ci_backtest.yml
1. Unit Tests (pytest, 100% coverage)
2. Integration Tests (end-to-end pipeline)
3. Monte Carlo Backtest (100 runs, Omega > 2.7)
4. Theorem Validation (statistical significance)
5. Health Check (CHS > 0.85)
6. Security Scan (Dependabot, CodeQL)
7. Silent Failure Detection (auto-fix)
8. Deploy (if all tests pass)Kinetra includes an automated system for detecting and fixing silent failures:
# Run complete workflow (detect β analyze β fix β validate)
python scripts/silent_failure_workflow.py
# Dry-run to preview fixes
python scripts/silent_failure_workflow.py --dry-run
# Quick mode (faster)
python scripts/silent_failure_workflow.py --quickFeatures:
- π Automatic detection of silent errors across codebase
- π€ AI-powered categorization and analysis
- π§ Automated fixing with safety backups
- β Validation and rollback capabilities
- π Comprehensive reporting for analysis
See SILENT_FAILURE_README.md for quick start or docs/SILENT_FAILURE_WORKFLOW.md for full documentation.
- Prometheus: Metrics collection (CHS, Omega, RoR, reward components)
- Grafana: Real-time dashboards with alerts
- MLflow/W&B: RL training logs, calibration plots
- CloudWatch/Stackdriver: Production logs and traces
# Set up local main branch (first time only)
python scripts/branch_manager.py --setup
# Create feature branch
git checkout -b feature/new-physics-model
# Make changes and test locally
pytest tests/ -v
# Run backtest validation
python scripts/batch_backtest.py --instrument BTCUSD
# Push (triggers CI)
git push origin feature/new-physics-model
# CI runs automatically:
# - Unit tests
# - Monte Carlo backtest
# - Theorem validation
# - If pass β auto-merge to developFor complete branching workflow, see the Branching Strategy Guide or Quick Reference.
- Menu System User Guide: Interactive menu and E2E testing
- Menu System Flowchart: Comprehensive workflow diagrams
- Design Bible: Complete system architecture and mathematical proofs
- API Reference: Detailed function documentation
- Deployment Guide: Production setup and monitoring
- Research Papers: Theorem validation and empirical results
- Branching Strategy: Git workflow and branch management guide
- Scientific Testing Guide: Comprehensive testing framework
Visit the GitHub Wiki or GitHub Pages for full documentation.
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch (see Branching Strategy)
- Add comprehensive tests
- Ensure all CI checks pass
- Submit a pull request with theorem validation
For detailed branch management instructions and git workflow, see the Branching Strategy Guide. You can also use the branch management helper script:
# Set up local main branch tracking remote
python scripts/branch_manager.py --setup
# Check branch status
python scripts/branch_manager.py --status
# Sync with remote
python scripts/branch_manager.py --syncMIT License - see LICENSE for details.
This project is open-source for research and educational purposes. Use in live trading is at your own risk.
IMPORTANT: This software is provided for educational and research purposes only. Trading financial instruments carries significant risk of loss. Past performance does not guarantee future results. The authors are not responsible for any financial losses incurred through use of this software.
Built on first principles with inspiration from:
- Statistical mechanics and thermodynamics
- Reinforcement learning theory (Sutton & Barto)
- Quantitative finance research
- Open-source ML/trading community
- GitHub Issues: Bug reports and feature requests
- Discussions: Design questions and research collaboration
- Email: [Your email for serious inquiries]
Kinetra - Harvesting Energy from Market Physics π