diff --git a/apps/api/src/app/portfolio/calculator/portfolio-calculator.ts b/apps/api/src/app/portfolio/calculator/portfolio-calculator.ts index ca440c6d2a..0ac2f6ecf6 100644 --- a/apps/api/src/app/portfolio/calculator/portfolio-calculator.ts +++ b/apps/api/src/app/portfolio/calculator/portfolio-calculator.ts @@ -1428,10 +1428,8 @@ export abstract class PortfolioCalculator { // Take the values at the start date from the first day of the date // range if (historicalDataItemsOfDateRange.length === 0) { - // TODO: Remove the fallback to 0 with the next release, when each - // cached portfolio snapshot contains the dividend dividendInBaseCurrencyAtStartDate = - historicalDataItem.dividendInBaseCurrency ?? 0; + historicalDataItem.dividendInBaseCurrency; netPerformanceAtStartDate = historicalDataItem.netPerformance; @@ -1441,10 +1439,8 @@ export abstract class PortfolioCalculator { historicalDataItemsOfDateRange.push({ ...historicalDataItem, - // TODO: Remove the fallback to 0 with the next release, when each - // cached portfolio snapshot contains the dividend dividendInBaseCurrency: - (historicalDataItem.dividendInBaseCurrency ?? 0) - + historicalDataItem.dividendInBaseCurrency - dividendInBaseCurrencyAtStartDate, netPerformance: historicalDataItem.netPerformance - netPerformanceAtStartDate, diff --git a/apps/api/src/app/portfolio/portfolio.service.ts b/apps/api/src/app/portfolio/portfolio.service.ts index 00de213d08..d7f04ff882 100644 --- a/apps/api/src/app/portfolio/portfolio.service.ts +++ b/apps/api/src/app/portfolio/portfolio.service.ts @@ -990,15 +990,12 @@ export class PortfolioService { const { activitiesCount, - averageInvestment, - averageInvestmentWithCurrencyEffect, averagePrice, currency, dateOfFirstActivity, dividendInBaseCurrency, - dividendYieldPercent: dividendYieldPercentOfSnapshot, - dividendYieldPercentWithCurrencyEffect: - dividendYieldPercentWithCurrencyEffectOfSnapshot, + dividendYieldPercent, + dividendYieldPercentWithCurrencyEffect, feeInBaseCurrency, grossPerformance, grossPerformancePercentage, @@ -1014,34 +1011,6 @@ export class PortfolioService { tags } = holding; - // TODO: Remove the block below with the next release, when each cached - // portfolio snapshot contains the dividend yield. Then take - // dividendYieldPercent and dividendYieldPercentWithCurrencyEffect - // directly from the holding and remove averageInvestment and - // averageInvestmentWithCurrencyEffect from the properties above - const daysInMarket = differenceInDays( - new Date(), - parseDate(dateOfFirstActivity) - ); - - const dividendYieldPercent = - dividendYieldPercentOfSnapshot ?? - getAnnualizedPerformancePercent({ - daysInMarket, - netPerformancePercentage: averageInvestment.eq(0) - ? new Big(0) - : dividendInBaseCurrency.div(averageInvestment) - }); - - const dividendYieldPercentWithCurrencyEffect = - dividendYieldPercentWithCurrencyEffectOfSnapshot ?? - getAnnualizedPerformancePercent({ - daysInMarket, - netPerformancePercentage: averageInvestmentWithCurrencyEffect.eq(0) - ? new Big(0) - : dividendInBaseCurrency.div(averageInvestmentWithCurrencyEffect) - }); - const activitiesOfHolding = activities.filter((activity) => { return ( activity.assetProfile.dataSource === dataSource && @@ -2247,11 +2216,9 @@ export class PortfolioService { activityCount: activities.filter(({ type }) => { return ['BUY', 'SELL'].includes(type); }).length, - // TODO: Remove the fallback to 0 with the next release, when each - // cached portfolio snapshot contains the dividend yield - dividendYieldPercent: dividendYieldPercent?.toNumber() ?? 0, + dividendYieldPercent: dividendYieldPercent.toNumber(), dividendYieldPercentWithCurrencyEffect: - dividendYieldPercentWithCurrencyEffect?.toNumber() ?? 0, + dividendYieldPercentWithCurrencyEffect.toNumber(), emergencyFund: { assets: emergencyFundHoldingsValueInBaseCurrency, cash: totalEmergencyFund diff --git a/libs/common/src/lib/models/portfolio-snapshot-holding.ts b/libs/common/src/lib/models/portfolio-snapshot-holding.ts index 9b440b9782..e248cd997d 100644 --- a/libs/common/src/lib/models/portfolio-snapshot-holding.ts +++ b/libs/common/src/lib/models/portfolio-snapshot-holding.ts @@ -7,41 +7,16 @@ import type { Tag } from '@ghostfolio/prisma/browser'; import { DataSource } from '@ghostfolio/prisma/enums'; import { Big } from 'big.js'; -import { Expose, Transform, Type } from 'class-transformer'; - -/** - * @deprecated Backward compatibility to read the portfolio snapshots which - * have been cached with the former name of the property - * - * TODO: Remove the fallback with the next release, together with the - * `@Expose()` decorators of `averageInvestment` and - * `averageInvestmentWithCurrencyEffect` - */ -function transformToBigWithFallback(formerKey: string) { - return ({ obj, value }: { obj: Record; value: string }) => { - const valueOrFallback = value ?? obj[formerKey]; - - return valueOrFallback === undefined - ? undefined - : transformToBig({ value: valueOrFallback }); - }; -} +import { Transform, Type } from 'class-transformer'; export class PortfolioSnapshotHolding { activitiesCount: number; - @Expose() - @Transform(transformToBigWithFallback('timeWeightedInvestment'), { - toClassOnly: true - }) + @Transform(transformToBig, { toClassOnly: true }) @Type(() => Big) averageInvestment: Big; - @Expose() - @Transform( - transformToBigWithFallback('timeWeightedInvestmentWithCurrencyEffect'), - { toClassOnly: true } - ) + @Transform(transformToBig, { toClassOnly: true }) @Type(() => Big) averageInvestmentWithCurrencyEffect: Big;