diff --git a/apps/api/src/app/portfolio/calculator/roai/portfolio-calculator.ts b/apps/api/src/app/portfolio/calculator/roai/portfolio-calculator.ts index d9da465f9..eddd938b6 100644 --- a/apps/api/src/app/portfolio/calculator/roai/portfolio-calculator.ts +++ b/apps/api/src/app/portfolio/calculator/roai/portfolio-calculator.ts @@ -554,6 +554,16 @@ export class RoaiPortfolioCalculator extends PortfolioCalculator { initialValueWithCurrencyEffect = transactionInvestmentWithCurrencyEffect; + } else if ( + order.quantity.gt(0) && + ['BUY', 'SELL'].includes(order.type) && + !order.itemType + ) { + initialValue = order.quantity.mul(marketPriceInBaseCurrency); + + initialValueWithCurrencyEffect = order.quantity.mul( + marketPriceInBaseCurrencyWithCurrencyEffect + ); } } @@ -783,7 +793,9 @@ export class RoaiPortfolioCalculator extends PortfolioCalculator { ? totalGrossPerformance.div( timeWeightedAverageInvestmentBetweenStartAndEndDate ) - : new Big(0); + : totalGrossPerformance + ? new Big(1) + : new Big(0); const grossPerformancePercentageWithCurrencyEffect = timeWeightedAverageInvestmentBetweenStartAndEndDateWithCurrencyEffect.gt( @@ -792,7 +804,9 @@ export class RoaiPortfolioCalculator extends PortfolioCalculator { ? totalGrossPerformanceWithCurrencyEffect.div( timeWeightedAverageInvestmentBetweenStartAndEndDateWithCurrencyEffect ) - : new Big(0); + : totalGrossPerformanceWithCurrencyEffect + ? new Big(1) + : new Big(0); const feesPerUnit = totalUnits.gt(0) ? fees.minus(feesAtStartDate).div(totalUnits) @@ -809,7 +823,9 @@ export class RoaiPortfolioCalculator extends PortfolioCalculator { ? totalNetPerformance.div( timeWeightedAverageInvestmentBetweenStartAndEndDate ) - : new Big(0); + : totalNetPerformance + ? new Big(1) + : new Big(0); const netPerformancePercentageWithCurrencyEffectMap: { [key: DateRange]: Big; @@ -902,7 +918,9 @@ export class RoaiPortfolioCalculator extends PortfolioCalculator { netPerformancePercentageWithCurrencyEffectMap[dateRange] = average.gt(0) ? netPerformanceWithCurrencyEffectMap[dateRange].div(average) - : new Big(0); + : netPerformanceWithCurrencyEffectMap[dateRange] + ? new Big(1) + : new Big(0); } if (PortfolioCalculator.ENABLE_LOGGING) { @@ -938,9 +956,11 @@ export class RoaiPortfolioCalculator extends PortfolioCalculator { Net performance: ${totalNetPerformance.toFixed( 2 )} / ${netPerformancePercentage.mul(100).toFixed(2)}% - Net performance with currency effect: ${netPerformancePercentageWithCurrencyEffectMap[ - 'max' - ].toFixed(2)}%` + Net performance with currency effect: ${netPerformanceValuesWithCurrencyEffect[ + endDateString + ].toFixed(2)} / ${netPerformancePercentageWithCurrencyEffectMap['max'] + .mul(100) + .toFixed(2)}%` ); } diff --git a/apps/api/src/app/portfolio/portfolio.service.ts b/apps/api/src/app/portfolio/portfolio.service.ts index 623a94f97..3d348511c 100644 --- a/apps/api/src/app/portfolio/portfolio.service.ts +++ b/apps/api/src/app/portfolio/portfolio.service.ts @@ -798,10 +798,7 @@ export class PortfolioService { historicalDataArray.push({ date, averagePrice: currentAveragePrice, - marketPrice: - historicalDataArray.length > 0 - ? marketPrice - : currentAveragePrice, + marketPrice, quantity: currentQuantity }); diff --git a/apps/client/src/app/components/holding-detail-dialog/holding-detail-dialog.component.ts b/apps/client/src/app/components/holding-detail-dialog/holding-detail-dialog.component.ts index a90c36c3d..3335d8de1 100644 --- a/apps/client/src/app/components/holding-detail-dialog/holding-detail-dialog.component.ts +++ b/apps/client/src/app/components/holding-detail-dialog/holding-detail-dialog.component.ts @@ -275,11 +275,13 @@ export class GfHoldingDetailDialogComponent implements OnDestroy, OnInit { SymbolProfile?.userId === this.user?.id; this.historicalDataItems = historicalData.map( - ({ averagePrice, date, marketPrice }) => { - this.benchmarkDataItems.push({ - date, - value: averagePrice - }); + ({ averagePrice, date, marketPrice, quantity }) => { + if (quantity) { + this.benchmarkDataItems.push({ + date, + value: averagePrice + }); + } return { date, @@ -429,15 +431,6 @@ export class GfHoldingDetailDialogComponent implements OnDestroy, OnInit { this.benchmarkDataItems[0].value = this.averagePrice; } - this.benchmarkDataItems = this.benchmarkDataItems.map( - ({ date, value }) => { - return { - date, - value: value === 0 ? null : value - }; - } - ); - if (this.hasPermissionToReadMarketDataOfOwnAssetProfile) { this.fetchMarketData(); }