diff --git a/apps/api/src/app/portfolio/calculator/portfolio-calculator.ts b/apps/api/src/app/portfolio/calculator/portfolio-calculator.ts index 7eef8b469..d04d9b715 100644 --- a/apps/api/src/app/portfolio/calculator/portfolio-calculator.ts +++ b/apps/api/src/app/portfolio/calculator/portfolio-calculator.ts @@ -159,16 +159,8 @@ export abstract class PortfolioCalculator { if (!transactionPoints.length) { return { currentValueInBaseCurrency: new Big(0), - grossPerformance: new Big(0), - grossPerformancePercentage: new Big(0), - grossPerformancePercentageWithCurrencyEffect: new Big(0), - grossPerformanceWithCurrencyEffect: new Big(0), hasErrors: false, historicalData: [], - netPerformance: new Big(0), - netPerformancePercentage: new Big(0), - netPerformancePercentageWithCurrencyEffect: new Big(0), - netPerformanceWithCurrencyEffect: new Big(0), positions: [], totalFeesWithCurrencyEffect: new Big(0), totalInterestWithCurrencyEffect: new Big(0), diff --git a/apps/api/src/app/portfolio/calculator/twr/portfolio-calculator.ts b/apps/api/src/app/portfolio/calculator/twr/portfolio-calculator.ts index 54155790f..562173d6b 100644 --- a/apps/api/src/app/portfolio/calculator/twr/portfolio-calculator.ts +++ b/apps/api/src/app/portfolio/calculator/twr/portfolio-calculator.ts @@ -106,35 +106,13 @@ export class TWRPortfolioCalculator extends PortfolioCalculator { return { currentValueInBaseCurrency, - grossPerformance, - grossPerformanceWithCurrencyEffect, hasErrors, - netPerformance, - netPerformanceWithCurrencyEffect, positions, totalFeesWithCurrencyEffect, totalInterestWithCurrencyEffect, totalInvestment, totalInvestmentWithCurrencyEffect, historicalData: [], - netPerformancePercentage: totalTimeWeightedInvestment.eq(0) - ? new Big(0) - : netPerformance.div(totalTimeWeightedInvestment), - netPerformancePercentageWithCurrencyEffect: - totalTimeWeightedInvestmentWithCurrencyEffect.eq(0) - ? new Big(0) - : netPerformanceWithCurrencyEffect.div( - totalTimeWeightedInvestmentWithCurrencyEffect - ), - grossPerformancePercentage: totalTimeWeightedInvestment.eq(0) - ? new Big(0) - : grossPerformance.div(totalTimeWeightedInvestment), - grossPerformancePercentageWithCurrencyEffect: - totalTimeWeightedInvestmentWithCurrencyEffect.eq(0) - ? new Big(0) - : grossPerformanceWithCurrencyEffect.div( - totalTimeWeightedInvestmentWithCurrencyEffect - ), totalLiabilitiesWithCurrencyEffect: new Big(0), totalValuablesWithCurrencyEffect: new Big(0) }; diff --git a/apps/api/src/app/portfolio/portfolio.service.ts b/apps/api/src/app/portfolio/portfolio.service.ts index 9a0d57314..6b7fd18e5 100644 --- a/apps/api/src/app/portfolio/portfolio.service.ts +++ b/apps/api/src/app/portfolio/portfolio.service.ts @@ -1588,18 +1588,27 @@ export class PortfolioService { } } + const { currentValueInBaseCurrency, totalInvestment } = + await portfolioCalculator.getSnapshot(); + + const { performance } = await this.getPerformance({ + impersonationId, + userId + }); + + console.log(performance); + const { - currentValueInBaseCurrency, - grossPerformance, - grossPerformancePercentage, - grossPerformancePercentageWithCurrencyEffect, - grossPerformanceWithCurrencyEffect, + // TODO + // grossPerformance, + // grossPerformancePercentage, + // grossPerformancePercentageWithCurrencyEffect, + // grossPerformanceWithCurrencyEffect, netPerformance, netPerformancePercentage, netPerformancePercentageWithCurrencyEffect, - netPerformanceWithCurrencyEffect, - totalInvestment - } = await portfolioCalculator.getSnapshot(); + netPerformanceWithCurrencyEffect + } = performance; const dividendInBaseCurrency = await portfolioCalculator.getDividendInBaseCurrency(); @@ -1696,6 +1705,10 @@ export class PortfolioService { cash, excludedAccountsAndActivities, firstOrderDate, + netPerformance, + netPerformancePercentage, + netPerformancePercentageWithCurrencyEffect, + netPerformanceWithCurrencyEffect, totalBuy, totalSell, committedFunds: committedFunds.toNumber(), @@ -1716,21 +1729,14 @@ export class PortfolioService { fireWealth: new Big(currentValueInBaseCurrency) .minus(emergencyFundPositionsValueInBaseCurrency) .toNumber(), - grossPerformance: grossPerformance.toNumber(), - grossPerformancePercentage: grossPerformancePercentage.toNumber(), - grossPerformancePercentageWithCurrencyEffect: - grossPerformancePercentageWithCurrencyEffect.toNumber(), - grossPerformanceWithCurrencyEffect: - grossPerformanceWithCurrencyEffect.toNumber(), + // TODO + grossPerformance: 0, + grossPerformancePercentage: 0, + grossPerformancePercentageWithCurrencyEffect: 0, + grossPerformanceWithCurrencyEffect: 0, interest: interest.toNumber(), items: valuables.toNumber(), liabilities: liabilities.toNumber(), - netPerformance: netPerformance.toNumber(), - netPerformancePercentage: netPerformancePercentage.toNumber(), - netPerformancePercentageWithCurrencyEffect: - netPerformancePercentageWithCurrencyEffect.toNumber(), - netPerformanceWithCurrencyEffect: - netPerformanceWithCurrencyEffect.toNumber(), ordersCount: activities.filter(({ type }) => { return ['BUY', 'SELL'].includes(type); }).length, diff --git a/libs/common/src/lib/models/portfolio-snapshot.ts b/libs/common/src/lib/models/portfolio-snapshot.ts index 0fe15405c..e51931711 100644 --- a/libs/common/src/lib/models/portfolio-snapshot.ts +++ b/libs/common/src/lib/models/portfolio-snapshot.ts @@ -15,50 +15,10 @@ export class PortfolioSnapshot { errors?: AssetProfileIdentifier[]; - @Transform(transformToBig, { toClassOnly: true }) - @Type(() => Big) - grossPerformance: Big; - - @Transform(transformToBig, { toClassOnly: true }) - @Type(() => Big) - grossPerformanceWithCurrencyEffect: Big; - - @Transform(transformToBig, { toClassOnly: true }) - @Type(() => Big) - grossPerformancePercentage: Big; - - @Transform(transformToBig, { toClassOnly: true }) - @Type(() => Big) - grossPerformancePercentageWithCurrencyEffect: Big; - hasErrors: boolean; historicalData: HistoricalDataItem[]; - @Transform(transformToBig, { toClassOnly: true }) - @Type(() => Big) - netAnnualizedPerformance?: Big; - - @Transform(transformToBig, { toClassOnly: true }) - @Type(() => Big) - netAnnualizedPerformanceWithCurrencyEffect?: Big; - - @Transform(transformToBig, { toClassOnly: true }) - @Type(() => Big) - netPerformance: Big; - - @Transform(transformToBig, { toClassOnly: true }) - @Type(() => Big) - netPerformanceWithCurrencyEffect: Big; - - @Transform(transformToBig, { toClassOnly: true }) - @Type(() => Big) - netPerformancePercentage: Big; - - @Transform(transformToBig, { toClassOnly: true }) - @Type(() => Big) - netPerformancePercentageWithCurrencyEffect: Big; - @Type(() => TimelinePosition) positions: TimelinePosition[];