From 35a591f6fec7bae119fc8db33541a6e93701f509 Mon Sep 17 00:00:00 2001 From: Reto Kaul Date: Thu, 22 Aug 2024 14:48:03 +0200 Subject: [PATCH] Improvements --- .../calculator/portfolio-calculator.ts | 29 +++--- .../src/app/portfolio/portfolio.service.ts | 4 +- .../benchmark-comparator.component.ts | 2 +- .../holding-detail-dialog.html | 88 ++++++++----------- 4 files changed, 56 insertions(+), 67 deletions(-) diff --git a/apps/api/src/app/portfolio/calculator/portfolio-calculator.ts b/apps/api/src/app/portfolio/calculator/portfolio-calculator.ts index bd97e0dcc..fe389ba19 100644 --- a/apps/api/src/app/portfolio/calculator/portfolio-calculator.ts +++ b/apps/api/src/app/portfolio/calculator/portfolio-calculator.ts @@ -10,7 +10,12 @@ import { ExchangeRateDataService } from '@ghostfolio/api/services/exchange-rate- import { IDataGatheringItem } from '@ghostfolio/api/services/interfaces/interfaces'; import { getIntervalFromDateRange } from '@ghostfolio/common/calculation-helper'; import { MAX_CHART_ITEMS } from '@ghostfolio/common/config'; -import { DATE_FORMAT, getSum, parseDate } from '@ghostfolio/common/helper'; +import { + DATE_FORMAT, + getSum, + parseDate, + resetHours +} from '@ghostfolio/common/helper'; import { AssetProfileIdentifier, DataProviderInfo, @@ -32,7 +37,6 @@ import { format, isAfter, isBefore, - max, min, subDays } from 'date-fns'; @@ -398,7 +402,7 @@ export abstract class PortfolioCalculator { ? (netPerformancePercentage ?? null) : null, netPerformancePercentageWithCurrencyEffect: !hasErrors - ? (netPerformancePercentageWithCurrencyEffect ?? null) + ? (netPerformancePercentageWithCurrencyEffectMap['max'] ?? null) : null, netPerformancePercentageWithCurrencyEffectMap: !hasErrors ? (netPerformancePercentageWithCurrencyEffectMap ?? null) @@ -554,7 +558,6 @@ export abstract class PortfolioCalculator { ? 0 : totalNetPerformanceValue .div(totalTimeWeightedInvestmentValue) - .mul(100) .toNumber(); const netPerformanceInPercentageWithCurrencyEffect = @@ -562,7 +565,6 @@ export abstract class PortfolioCalculator { ? 0 : totalNetPerformanceValueWithCurrencyEffect .div(totalTimeWeightedInvestmentValueWithCurrencyEffect) - .mul(100) .toNumber(); return { @@ -692,10 +694,9 @@ export abstract class PortfolioCalculator { let totalInvestmentValuesWithCurrencyEffect: number[] = []; for (let historicalDataItem of historicalData) { - if ( - !isBefore(parseDate(historicalDataItem.date), subDays(start, 1)) && - !isAfter(parseDate(historicalDataItem.date), end) - ) { + const date = resetHours(parseDate(historicalDataItem.date)); + + if (!isBefore(date, start) && !isAfter(date, end)) { if (!isNumber(netPerformanceAtStartDate)) { netPerformanceAtStartDate = historicalDataItem.netPerformance; @@ -706,6 +707,9 @@ export abstract class PortfolioCalculator { historicalDataItem.netPerformanceInPercentageWithCurrencyEffect; } + const netPerformanceSinceStartDate = + historicalDataItem.netPerformance - netPerformanceAtStartDate; + const netPerformanceWithCurrencyEffectSinceStartDate = historicalDataItem.netPerformanceWithCurrencyEffect - netPerformanceWithCurrencyEffectAtStartDate; @@ -730,10 +734,11 @@ export abstract class PortfolioCalculator { historicalDataItem.netPerformance - netPerformanceAtStartDate, netPerformanceWithCurrencyEffect: netPerformanceWithCurrencyEffectSinceStartDate, + netPerformanceInPercentage: + netPerformanceSinceStartDate / timeWeightedInvestmentValue, netPerformanceInPercentageWithCurrencyEffect: - (netPerformanceWithCurrencyEffectSinceStartDate / - timeWeightedInvestmentValue) * - 100, + netPerformanceWithCurrencyEffectSinceStartDate / + timeWeightedInvestmentValue, // TODO: Add net worth with valuables // netWorth: totalCurrentValueWithCurrencyEffect // .plus(totalAccountBalanceWithCurrencyEffect) diff --git a/apps/api/src/app/portfolio/portfolio.service.ts b/apps/api/src/app/portfolio/portfolio.service.ts index 7ac6d4b34..ac0008241 100644 --- a/apps/api/src/app/portfolio/portfolio.service.ts +++ b/apps/api/src/app/portfolio/portfolio.service.ts @@ -1171,9 +1171,9 @@ export class PortfolioService { totalInvestment, currentNetWorth: netWorth, currentValueInBaseCurrency: valueWithCurrencyEffect, - netPerformancePercentage: netPerformanceInPercentage / 100, // TODO + netPerformancePercentage: netPerformanceInPercentage, netPerformancePercentageWithCurrencyEffect: - netPerformanceInPercentageWithCurrencyEffect / 100 // TODO + netPerformanceInPercentageWithCurrencyEffect } }; } diff --git a/apps/client/src/app/components/benchmark-comparator/benchmark-comparator.component.ts b/apps/client/src/app/components/benchmark-comparator/benchmark-comparator.component.ts index 8b2d59754..a59515969 100644 --- a/apps/client/src/app/components/benchmark-comparator/benchmark-comparator.component.ts +++ b/apps/client/src/app/components/benchmark-comparator/benchmark-comparator.component.ts @@ -111,7 +111,7 @@ export class BenchmarkComparatorComponent implements OnChanges, OnDestroy { borderColor: `rgb(${primaryColorRgb.r}, ${primaryColorRgb.g}, ${primaryColorRgb.b})`, borderWidth: 2, data: this.performanceDataItems.map(({ date, value }) => { - return { x: parseDate(date).getTime(), y: value }; + return { x: parseDate(date).getTime(), y: value * 100 }; }), label: $localize`Portfolio` }, diff --git a/apps/client/src/app/components/holding-detail-dialog/holding-detail-dialog.html b/apps/client/src/app/components/holding-detail-dialog/holding-detail-dialog.html index 04770837a..fab5bc452 100644 --- a/apps/client/src/app/components/holding-detail-dialog/holding-detail-dialog.html +++ b/apps/client/src/app/components/holding-detail-dialog/holding-detail-dialog.html @@ -37,60 +37,44 @@
- @if ( - SymbolProfile?.currency && - data.baseCurrency !== SymbolProfile?.currency - ) { - Change with currency effect - } @else { - Change - } + + @if ( + SymbolProfile?.currency && + data.baseCurrency !== SymbolProfile?.currency + ) { + Change with currency effect + } @else { + Change + } +
- @if ( - SymbolProfile?.currency && - data.baseCurrency !== SymbolProfile?.currency - ) { - Performance with currency effect - } @else { - Performance - } + + @if ( + SymbolProfile?.currency && + data.baseCurrency !== SymbolProfile?.currency + ) { + Performance with currency effect + } @else { + Performance + } +