feat: add reusable performance report helpers - #18
Merged
Merged
Conversation
Lift the strategy-agnostic pieces of get_performance.py from the algorithmic-trading-project repo into this library so any strategy can produce snapshot + PDF performance reports with one call. New public API: - brokers.alpaca.performance_ops.get_portfolio_equity_series() Wraps get_portfolio_history() into a date-indexed pd.Series. - common.portfolio_ops.fetch_normalized_benchmark(portfolio_equity, date_start) Fetches S&P 500, intersects to common dates, and rescales the benchmark so its first value equals the portfolio's first value (units mismatch between index points and dollars). - common.viz_ops.build_performance_figures(viz, show, mask_benchmark_on) Expands create_all_plots() with per-plot benchmark masking. Defaults to hiding the benchmark line on the dollar-scale plots (cumulative_returns, equity_curve) where the raw S&P index has no meaningful comparison. - common.report_ops.write_performance_pdf(pdf_path, title, metrics, figs, period_text) Multi-page PDF: cover with monospace metrics block + one chart per page. - brokers.alpaca.performance_ops.generate_performance_report(...) End-to-end orchestrator returning (snapshot_path, pdf_path, metrics). Tests: - New tests/test_report_ops.py covering PDF cover + figure pages, empty metrics, zero figures, and string-vs-Path inputs. - Tests for fetch_normalized_benchmark covering normalisation, common-date intersection, and date_start forwarding. - Tests for build_performance_figures covering default masking, restoration of viz.benchmark, full-benchmark mode, and alpha/beta skipping. - Tests for get_portfolio_equity_series and generate_performance_report (snapshot + PDF + metrics; benchmark-disabled path). All 202 tests pass (sentiment_ops collection error pre-existing on main). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
Lift the strategy-agnostic pieces of get_performance.py from the algorithmic-trading-project repo into this library so any strategy can produce snapshot + PDF performance reports with one call.
New public API:
brokers.alpaca.performance_ops.get_portfolio_equity_series() Wraps get_portfolio_history() into a date-indexed pd.Series.
common.portfolio_ops.fetch_normalized_benchmark(portfolio_equity, date_start) Fetches S&P 500, intersects to common dates, and rescales the benchmark so its first value equals the portfolio's first value (units mismatch between index points and dollars).
common.viz_ops.build_performance_figures(viz, show, mask_benchmark_on) Expands create_all_plots() with per-plot benchmark masking. Defaults to hiding the benchmark line on the dollar-scale plots (cumulative_returns, equity_curve) where the raw S&P index has no meaningful comparison.
common.report_ops.write_performance_pdf(pdf_path, title, metrics, figs, period_text) Multi-page PDF: cover with monospace metrics block + one chart per page.
brokers.alpaca.performance_ops.generate_performance_report(...) End-to-end orchestrator returning (snapshot_path, pdf_path, metrics).
Tests:
All 202 tests pass (sentiment_ops collection error pre-existing on main).