Skip to content

feat: add reusable performance report helpers - #18

Merged
konradbachusz merged 2 commits into
mainfrom
feat/performance-report-helpers
Apr 26, 2026
Merged

konradbachusz merged 2 commits into
mainfrom
feat/performance-report-helpers

Conversation

@konradbachusz

Copy link
Copy Markdown
Owner

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).

konradbachusz and others added 2 commits April 26, 2026 09:46
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>
@konradbachusz
konradbachusz merged commit f086aa7 into main Apr 26, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant