backtest: implement metrics and vectorized backtester#10
Merged
marwinsteiner merged 5 commits intomainfrom Feb 22, 2026
Merged
Conversation
Create src/sysls/backtest/ and tests/backtest/ packages in preparation for metrics and vectorized backtester modules.
Pure, stateless metric functions operating on numpy arrays: - compute_returns / compute_log_returns - sharpe_ratio, sortino_ratio, calmar_ratio - max_drawdown, drawdown_series - total_return, annualized_return, annualized_volatility - win_rate, profit_factor Also defines TradeRecord and BacktestResult Pydantic models, plus summarize_backtest convenience function.
60 tests covering all metric functions with known inputs/outputs, edge cases (empty arrays, single element, all zeros, division by zero), Pydantic model construction, immutability, and JSON serialization round-trips.
profit_factor now returns float('inf') for all-winners (was incorrectly
0.0). Added ConfigDict(ser_json_inf_nan='constants') for JSON round-trip.
Added tests: total-loss annualized return, empty equity summarize.
Updated Sortino docstring to document population-based convention.
vectorbt-inspired backtester operating on numpy arrays: signal conventions (1=long, -1=short, 0=flat), equity curve computation, per-trade PnL extraction, commission and slippage models. run_vectorized_backtest() returns BacktestResult via summarize_backtest. 35 tests covering long/short, commissions, slippage, edge cases.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
summarize_backtest()convenience builder.TradeRecordandBacktestResultfrozen Pydantic models.run_vectorized_backtest()→BacktestResult.profit_factorreturnsfloat('inf')for all-winners (was incorrectly 0.0). AddedConfigDict(ser_json_inf_nan='constants')for JSON round-trip. Sortino docstring documents population-based convention. Added total-loss and empty-equity edge-case tests.Stats
Test plan