Implement portfolio performance calculation (ROI, period returns, drawdown) - #336
Merged
OthmanImam merged 1 commit intoJun 21, 2026
Conversation
8 tasks
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
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
PerformanceAnalyticsServiceand surfaces each of them through dedicated controller endpoints.Changes
src/portfolio/services/performance-analytics.service.tscalculateROI,calculateCurrentDrawdown,calculatePeriodReturns,getAllocationBreakdown.recordMetricsnow enriches each persisted snapshot with YTD/1Y/3Y/5Y returns and the current drawdown.getPerformanceSummarynow also returnsroi,currentDrawdown,allocationBreakdown, andperiodReturnsalongside the existing risk-adjusted metrics (additive, backward compatible).calculateROIderives current value fromquantity * currentPricerather than the persistedvaluecolumn, which can lag untilupdatePortfolioAllocationruns.src/portfolio/portfolio.controller.tsGETendpoints under each portfolio:metrics/roi,metrics/drawdown,metrics/periods,metrics/allocation.src/portfolio/services/performance-analytics.service.spec.tsTesting
npx jest src/portfolio/services/performance-analytics.service.spec.ts— 57 / 57 passing.npx eslinton the three changed files — clean; only a pre-existing unused-import warning inportfolio.controller.ts, unrelated to this change.src/portfolio/test suite re-verified end-to-end for regressions in the touched area.Closes #326