You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Adds benchmark-relative Information Ratio analytics to the Strategy V2 backtest service.
The implementation calculates benchmark-relative metrics from the existing portfolio and benchmark curves. CDI data ingestion is intentionally excluded from this first scoped implementation.
Align portfolio and benchmark returns over identical start and end timestamps.
Report annualized portfolio, benchmark, and active returns.
Calculate annualized tracking error using sample standard deviation (ddof=1).
Calculate and classify the Information Ratio.
Report status, observation count, frequency, and annualization factor.
Require at least two aligned return observations to calculate tracking error and Information Ratio.
Exclude invalid, non-finite, and non-positive curve observations.
Handle insufficient history and zero tracking error explicitly.
Preserve negative Information Ratios.
Add deterministic unit tests and Strategy V2 integration coverage.
Document interval-alignment, annualization, edge-case behavior, and CDI benchmark suitability.
Annualization uses the existing Strategy V2 convention: 252 trading days for non-crypto markets, 365.25 days for crypto markets, corresponding session lengths for intraday frequencies, and 52 periods for weekly data.
CDI ingestion, the canonical CDI benchmark identifier, and Brazilian business-calendar behavior are intentionally deferred to a follow-up design.
Test plan
Tested locally with docker compose up -d --build
Backend logs show no errors
Relevant pytest tests pass
Results:
Docker Compose stack started successfully.
All long-running Compose services reported healthy.
Database migration completed successfully with exit code 0.
Updated docs/agent/agent-openapi.json if /api/agent/v1 routes changed
Breaking API changes called out below (oasdiff will fail CI otherwise)
No routes or declared OpenAPI schemas were changed. This PR additively includes benchmarkRelativeMetrics in the existing Strategy V2 backtest result payload.
No /api/agent/v1 routes were changed, and there are no breaking API changes.
Screenshots (if UI change)
Not applicable — no UI changes.
Roadmap contribution (if applicable)
A maintainer confirmed the claimed scope before implementation
This PR implements one reviewable slice rather than an entire epic
User-facing behavior and compatibility notes are documented
The issue author confirmed that the metric-only scope is acceptable and invited a draft PR. Maintainer feedback on the concrete API and test coverage remains welcome.
Thank you for the scoped implementation and test coverage. We reviewed the calculation path and found that computing from the forward-filled display benchmarkCurve can create artificial tracking error when a long intraday backtest fetches the benchmark at a coarser frequency.
An alternative implementation has now landed directly on main in commit 87cfeeb. It calculates at the benchmark's native frequency, samples portfolio equity at the same timestamps, uses the matching annualization factor, and filters invalid market-calendar gaps. The relevant Strategy V2 and metric suite passes with 237 tests.
Closing this draft unmerged because the replacement is already on main. Issue #179 remains open for CDI ingestion, the canonical CDI identifier, and the remaining Brazil-specific data/calendar design.
Thank you for the review and for explaining the native-frequency issue.
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
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
Adds benchmark-relative Information Ratio analytics to the Strategy V2 backtest service.
The implementation calculates benchmark-relative metrics from the existing portfolio and benchmark curves. CDI data ingestion is intentionally excluded from this first scoped implementation.
Related issue
Changes
ddof=1).Annualization uses the existing Strategy V2 convention: 252 trading days for non-crypto markets, 365.25 days for crypto markets, corresponding session lengths for intraday frequencies, and 52 periods for weekly data.
CDI ingestion, the canonical CDI benchmark identifier, and Brazilian business-calendar behavior are intentionally deferred to a follow-up design.
Test plan
docker compose up -d --buildResults:
24 passed.git diff --checkpassed.API documentation (if routes/schemas changed)
docs/api/openapi.yaml(cd backend_api_python && python scripts/export_openapi.py)docs/agent/agent-openapi.jsonif/api/agent/v1routes changedNo routes or declared OpenAPI schemas were changed. This PR additively includes
benchmarkRelativeMetricsin the existing Strategy V2 backtest result payload.No
/api/agent/v1routes were changed, and there are no breaking API changes.Screenshots (if UI change)
Not applicable — no UI changes.
Roadmap contribution (if applicable)
The issue author confirmed that the metric-only scope is acceptable and invited a draft PR. Maintainer feedback on the concrete API and test coverage remains welcome.