Commit Graph

3 Commits

Author SHA1 Message Date
TPTBusiness 827f80ce2e test: 343 deep hypothesis property-based tests across engine, DB, risk, ground truth, robustness, CV
- Backtest engine: 68 tests (IC symmetry, Sharpe formula, MaxDD bounds, cost monotonicity)
- Results DB: 78 tests (add_factor idempotence, metric roundtrip, sorting, persistence)
- Risk management: 71 tests (correlation PSD, MV weights, RP convergence, threshold checks)
- Ground truth: 44 tests (Sharpe sign, MaxDD, win_rate, signal invariants)
- Robustness: 44 tests (slippage, latency, MC reshuffle, OOS stress, random data)
- Cross-validation: 38 tests (IC ∈ [-1,1], scaling invariance, multi-instrument)
2026-05-10 23:42:46 +02:00
TPTBusiness 22e638af86 feat: unified backtest engine, LLM error handling, strategy refactor
- Add vbt_backtest.py as single source of truth for all metric formulas
  (Sharpe, drawdown, IC, transaction costs) — backtest_engine.py and
  strategy_orchestrator.py now delegate to it
- Add LLMUnavailableError to exception.py; rd_loop.py catches it at the
  proposal stage and raises LoopResumeError to avoid corrupting trace
  history with None hypotheses
- Guard record() against None exp/hypothesis so loop resets leave
  trace.hist in a consistent state
- Refactor strategy_orchestrator and optuna_optimizer to use unified
  backtest path; remove duplicate metric calculation code
- Add predix_rebacktest_unified.py script for offline re-evaluation
- Update tests and README

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-17 22:52:07 +02:00
TPTBusiness 953fb2d278 test: Add backtesting tests with 98.77% coverage
New test infrastructure:

1. pytest + pytest-cov installed
   - requirements.txt updated
   - pytest.ini configured
   - .coveragerc for coverage

2. Test suite created (97 tests):
   - test_backtest_engine.py (32 tests)
     * BacktestMetrics: IC, Sharpe, Drawdown, Win Rate
     * FactorBacktester: run_backtest, JSON export
     * Edge cases: NaN, empty, insufficient data

   - test_results_db.py (33 tests)
     * ResultsDatabase: CRUD operations
     * Queries: get_top_factors, get_aggregate_stats
     * Database cleanup

   - test_risk_management.py (32 tests)
     * CorrelationAnalyzer: Matrix, uncorrelated factors
     * PortfolioOptimizer: Mean-Variance, Risk Parity
     * AdvancedRiskManager: Limit checks

3. Fixtures (conftest.py):
   - 22 reusable test fixtures
   - Mock data for all scenarios
   - Sample factors, returns, equity curves

4. Coverage: 98.77% (target: >80%)
   - BacktestMetrics: 100%
   - FactorBacktester: 100%
   - ResultsDatabase: 95.92%
   - CorrelationAnalyzer: 100%
   - PortfolioOptimizer: 100%
   - AdvancedRiskManager: 100%

5. Documentation:
   - test/backtesting/README.md
   - How to run tests
   - Generate coverage reports

Run tests:
  pytest test/backtesting/ -v

Coverage report:
  pytest test/backtesting/ --cov=rdagent/components/backtesting --cov-report=html
2026-04-02 19:24:38 +02:00