diff --git a/src/portfolios/domain/portfolio-states.service.spec.ts b/src/portfolios/domain/portfolio-states.service.spec.ts index 6d66c15c..f2f3bbf8 100644 --- a/src/portfolios/domain/portfolio-states.service.spec.ts +++ b/src/portfolios/domain/portfolio-states.service.spec.ts @@ -25,7 +25,10 @@ describe('PortfolioStatesService', () => { positionFactory(), positionFactory(), ]; - const totalValueEUR = positions.reduce((sum, pos) => sum + pos.value, 0); + const totalValueEUR = positions.reduce( + (sum, pos) => sum + pos.value, + portfolio.cash, + ); const sumWeights = positions.reduce( (acc, pos) => acc + pos.targetWeight, 0, @@ -41,8 +44,7 @@ describe('PortfolioStatesService', () => { totalValueEUR, cash: portfolio.cash, roicEUR: - totalValueEUR + - portfolio.cash - + totalValueEUR - portfolio.contributions.reduce((sum, i) => sum + i.amountEUR, 0), }), ); diff --git a/src/portfolios/domain/portfolio-states.service.ts b/src/portfolios/domain/portfolio-states.service.ts index 5cfb3629..ff524c98 100644 --- a/src/portfolios/domain/portfolio-states.service.ts +++ b/src/portfolios/domain/portfolio-states.service.ts @@ -14,8 +14,8 @@ export class PortfolioStatesService { async createPortfolioState(portfolio: Portfolio, positions: Position[]) { const sumWeights = positions.reduce((acc, p) => acc + p.targetWeight, 0); - const totalValueEUR = positions.reduce((sum, pos) => sum + pos.value, 0); const cash = portfolio.cash ?? 0; + const totalValueEUR = positions.reduce((sum, pos) => sum + pos.value, cash); const contributionsAmount = portfolio.contributions ? portfolio.contributions.reduce( (sum, contribution) => sum + contribution.amountEUR, @@ -31,7 +31,7 @@ export class PortfolioStatesService { sumWeights, cash, totalValueEUR, - roicEUR: totalValueEUR + cash - contributionsAmount, + roicEUR: totalValueEUR - contributionsAmount, }); }