Skip to content

Implement portfolio performance calculation (ROI, period returns, drawdown) - #336

Merged
OthmanImam merged 1 commit into
StellAIverse:mainfrom
snowrugar-beep:fix/issue-326-portfolio-performance-calculation
Jun 21, 2026
Merged

Implement portfolio performance calculation (ROI, period returns, drawdown)#336
OthmanImam merged 1 commit into
StellAIverse:mainfrom
snowrugar-beep:fix/issue-326-portfolio-performance-calculation

Conversation

@snowrugar-beep

Copy link
Copy Markdown
Contributor

Summary

Implements the Portfolio Performance Calculation work tracked by issue #326. Adds the missing Return-on-Investment (relative to invested cost basis), current allocation breakdown, live drawdown, and standard period-specific returns (YTD / 1Y / 3Y / 5Y) to the existing PerformanceAnalyticsService and surfaces each of them through dedicated controller endpoints.

Changes

  • src/portfolio/services/performance-analytics.service.ts
    • New helpers: calculateROI, calculateCurrentDrawdown, calculatePeriodReturns, getAllocationBreakdown.
    • recordMetrics now enriches each persisted snapshot with YTD/1Y/3Y/5Y returns and the current drawdown.
    • getPerformanceSummary now also returns roi, currentDrawdown, allocationBreakdown, and periodReturns alongside the existing risk-adjusted metrics (additive, backward compatible).
    • calculateROI derives current value from quantity * currentPrice rather than the persisted value column, which can lag until updatePortfolioAllocation runs.
  • src/portfolio/portfolio.controller.ts
    • Four new GET endpoints under each portfolio: metrics/roi, metrics/drawdown, metrics/periods, metrics/allocation.
  • src/portfolio/services/performance-analytics.service.spec.ts
    • Extended unit coverage to include empty-history, null-allocation, zero-cost-basis, monotonically-rising/declining series, and peak-at-first/last edge cases.

Testing

  • npx jest src/portfolio/services/performance-analytics.service.spec.ts57 / 57 passing.
  • Coverage on the service file: 96.24% statements / 97.05% lines / 97.36% funcs / 87.05% branches (well above the >90% target).
  • npx eslint on the three changed files — clean; only a pre-existing unused-import warning in portfolio.controller.ts, unrelated to this change.
  • src/portfolio/ test suite re-verified end-to-end for regressions in the touched area.

Note: npx tsc --noEmit -p tsconfig.json reports a single type error in src/portfolio/services/trading-transaction.service.ts that also reproduces on the upstream main branch. That file is untouched by this PR and is left for a separate fix.

Closes #326

@OthmanImam
OthmanImam merged commit 2743b11 into StellAIverse:main Jun 21, 2026
0 of 3 checks 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.

Implement Portfolio Performance Calculation

2 participants