From c6f38e245130fccc662f7686a609536c783ed49b Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Sat, 4 May 2024 09:48:54 +0200 Subject: [PATCH] Refactoring --- .../src/app/portfolio/portfolio.controller.ts | 30 ++++---- .../src/app/portfolio/portfolio.service.ts | 72 +++++++++---------- .../portfolio-performance.component.html | 6 +- .../portfolio-performance.component.ts | 9 ++- .../portfolio-summary.component.html | 14 ++-- .../portfolio/analysis/analysis-page.html | 20 +++--- .../portfolio-performance.interface.ts | 18 ++--- 7 files changed, 83 insertions(+), 86 deletions(-) diff --git a/apps/api/src/app/portfolio/portfolio.controller.ts b/apps/api/src/app/portfolio/portfolio.controller.ts index 7aa8e9159..4a07cd65b 100644 --- a/apps/api/src/app/portfolio/portfolio.controller.ts +++ b/apps/api/src/app/portfolio/portfolio.controller.ts @@ -165,21 +165,21 @@ export class PortfolioController { portfolioSummary = nullifyValuesInObject(summary, [ 'cash', 'committedFunds', - 'currentGrossPerformance', - 'currentGrossPerformanceWithCurrencyEffect', - 'currentNetPerformance', - 'currentNetPerformanceWithCurrencyEffect', 'currentNetWorth', - 'currentValue', + 'currentValueInBaseCurrency', 'dividendInBaseCurrency', 'emergencyFund', 'excludedAccountsAndActivities', 'fees', 'filteredValueInBaseCurrency', 'fireWealth', + 'grossPerformance', + 'grossPerformanceWithCurrencyEffect', 'interest', 'items', 'liabilities', + 'netPerformance', + 'netPerformanceWithCurrencyEffect', 'totalBuy', 'totalInvestment', 'totalSell', @@ -449,10 +449,14 @@ export class PortfolioController { .div(performanceInformation.performance.totalInvestment) .toNumber(), valueInPercentage: - performanceInformation.performance.currentValue === 0 + performanceInformation.performance.currentValueInBaseCurrency === + 0 ? 0 : new Big(value) - .div(performanceInformation.performance.currentValue) + .div( + performanceInformation.performance + .currentValueInBaseCurrency + ) .toNumber() }; } @@ -461,12 +465,12 @@ export class PortfolioController { performanceInformation.performance = nullifyValuesInObject( performanceInformation.performance, [ - 'currentGrossPerformance', - 'currentGrossPerformanceWithCurrencyEffect', - 'currentNetPerformance', - 'currentNetPerformanceWithCurrencyEffect', 'currentNetWorth', - 'currentValue', + 'currentValueInBaseCurrency', + 'grossPerformance', + 'grossPerformanceWithCurrencyEffect', + 'netPerformance', + 'netPerformanceWithCurrencyEffect', 'totalInvestment' ] ); @@ -483,7 +487,7 @@ export class PortfolioController { ); performanceInformation.performance = nullifyValuesInObject( performanceInformation.performance, - ['currentNetPerformance', 'currentNetPerformancePercent'] + ['netPerformance'] ); } diff --git a/apps/api/src/app/portfolio/portfolio.service.ts b/apps/api/src/app/portfolio/portfolio.service.ts index d15bb45a0..e53727bca 100644 --- a/apps/api/src/app/portfolio/portfolio.service.ts +++ b/apps/api/src/app/portfolio/portfolio.service.ts @@ -1108,16 +1108,16 @@ export class PortfolioService { firstOrderDate: undefined, hasErrors: false, performance: { - currentGrossPerformance: 0, - currentGrossPerformancePercent: 0, - currentGrossPerformancePercentWithCurrencyEffect: 0, - currentGrossPerformanceWithCurrencyEffect: 0, - currentNetPerformance: 0, - currentNetPerformancePercent: 0, - currentNetPerformancePercentWithCurrencyEffect: 0, - currentNetPerformanceWithCurrencyEffect: 0, currentNetWorth: 0, - currentValue: 0, + currentValueInBaseCurrency: 0, + grossPerformance: 0, + grossPerformancePercentage: 0, + grossPerformancePercentageWithCurrencyEffect: 0, + grossPerformanceWithCurrencyEffect: 0, + netPerformance: 0, + netPerformancePercentage: 0, + netPerformancePercentageWithCurrencyEffect: 0, + netPerformanceWithCurrencyEffect: 0, totalInvestment: 0 } }; @@ -1152,9 +1152,9 @@ export class PortfolioService { let currentNetPerformance = netPerformance; - let currentNetPerformancePercent = netPerformancePercentage; + let currentNetPerformancePercentage = netPerformancePercentage; - let currentNetPerformancePercentWithCurrencyEffect = + let currentNetPerformancePercentageWithCurrencyEffect = netPerformancePercentageWithCurrencyEffect; let currentNetPerformanceWithCurrencyEffect = @@ -1173,11 +1173,11 @@ export class PortfolioService { if (itemOfToday) { currentNetPerformance = new Big(itemOfToday.netPerformance); - currentNetPerformancePercent = new Big( + currentNetPerformancePercentage = new Big( itemOfToday.netPerformanceInPercentage ).div(100); - currentNetPerformancePercentWithCurrencyEffect = new Big( + currentNetPerformancePercentageWithCurrencyEffect = new Big( itemOfToday.netPerformanceInPercentageWithCurrencyEffect ).div(100); @@ -1195,19 +1195,19 @@ export class PortfolioService { firstOrderDate: parseDate(items[0]?.date), performance: { currentNetWorth, - currentGrossPerformance: grossPerformance.toNumber(), - currentGrossPerformancePercent: grossPerformancePercentage.toNumber(), - currentGrossPerformancePercentWithCurrencyEffect: + currentValueInBaseCurrency: currentValueInBaseCurrency.toNumber(), + grossPerformance: grossPerformance.toNumber(), + grossPerformancePercentage: grossPerformancePercentage.toNumber(), + grossPerformancePercentageWithCurrencyEffect: grossPerformancePercentageWithCurrencyEffect.toNumber(), - currentGrossPerformanceWithCurrencyEffect: + grossPerformanceWithCurrencyEffect: grossPerformanceWithCurrencyEffect.toNumber(), - currentNetPerformance: currentNetPerformance.toNumber(), - currentNetPerformancePercent: currentNetPerformancePercent.toNumber(), - currentNetPerformancePercentWithCurrencyEffect: - currentNetPerformancePercentWithCurrencyEffect.toNumber(), - currentNetPerformanceWithCurrencyEffect: + netPerformance: currentNetPerformance.toNumber(), + netPerformancePercentage: currentNetPerformancePercentage.toNumber(), + netPerformancePercentageWithCurrencyEffect: + currentNetPerformancePercentageWithCurrencyEffect.toNumber(), + netPerformanceWithCurrencyEffect: currentNetPerformanceWithCurrencyEffect.toNumber(), - currentValue: currentValueInBaseCurrency.toNumber(), totalInvestment: totalInvestment.toNumber() } }; @@ -1732,19 +1732,7 @@ export class PortfolioService { totalBuy, totalSell, committedFunds: committedFunds.toNumber(), - currentGrossPerformance: grossPerformance.toNumber(), - currentGrossPerformancePercent: grossPerformancePercentage.toNumber(), - currentGrossPerformancePercentWithCurrencyEffect: - grossPerformancePercentageWithCurrencyEffect.toNumber(), - currentGrossPerformanceWithCurrencyEffect: - grossPerformanceWithCurrencyEffect.toNumber(), - currentNetPerformance: netPerformance.toNumber(), - currentNetPerformancePercent: netPerformancePercentage.toNumber(), - currentNetPerformancePercentWithCurrencyEffect: - netPerformancePercentageWithCurrencyEffect.toNumber(), - currentNetPerformanceWithCurrencyEffect: - netPerformanceWithCurrencyEffect.toNumber(), - currentValue: currentValueInBaseCurrency.toNumber(), + currentValueInBaseCurrency: currentValueInBaseCurrency.toNumber(), dividendInBaseCurrency: dividendInBaseCurrency.toNumber(), emergencyFund: { assets: emergencyFundPositionsValueInBaseCurrency, @@ -1761,9 +1749,21 @@ export class PortfolioService { fireWealth: new Big(currentValueInBaseCurrency) .minus(emergencyFundPositionsValueInBaseCurrency) .toNumber(), + grossPerformance: grossPerformance.toNumber(), + grossPerformancePercentage: grossPerformancePercentage.toNumber(), + grossPerformancePercentageWithCurrencyEffect: + grossPerformancePercentageWithCurrencyEffect.toNumber(), + grossPerformanceWithCurrencyEffect: + grossPerformanceWithCurrencyEffect.toNumber(), 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/apps/client/src/app/components/portfolio-performance/portfolio-performance.component.html b/apps/client/src/app/components/portfolio-performance/portfolio-performance.component.html index 68d191b5c..3ef55f800 100644 --- a/apps/client/src/app/components/portfolio-performance/portfolio-performance.component.html +++ b/apps/client/src/app/components/portfolio-performance/portfolio-performance.component.html @@ -41,9 +41,7 @@ [isCurrency]="true" [locale]="locale" [value]=" - isLoading - ? undefined - : performance?.currentNetPerformanceWithCurrencyEffect + isLoading ? undefined : performance?.netPerformanceWithCurrencyEffect " /> @@ -55,7 +53,7 @@ [value]=" isLoading ? undefined - : performance?.currentNetPerformancePercentWithCurrencyEffect + : performance?.netPerformancePercentageWithCurrencyEffect " /> diff --git a/apps/client/src/app/components/portfolio-performance/portfolio-performance.component.ts b/apps/client/src/app/components/portfolio-performance/portfolio-performance.component.ts index b76ecb004..4d205b761 100644 --- a/apps/client/src/app/components/portfolio-performance/portfolio-performance.component.ts +++ b/apps/client/src/app/components/portfolio-performance/portfolio-performance.component.ts @@ -49,12 +49,12 @@ export class PortfolioPerformanceComponent implements OnChanges, OnInit { this.value.nativeElement.innerHTML = ''; } } else { - if (isNumber(this.performance?.currentValue)) { - new CountUp('value', this.performance?.currentValue, { + if (isNumber(this.performance?.currentValueInBaseCurrency)) { + new CountUp('value', this.performance?.currentValueInBaseCurrency, { decimal: getNumberFormatDecimal(this.locale), decimalPlaces: this.deviceType === 'mobile' && - this.performance?.currentValue >= 100000 + this.performance?.currentValueInBaseCurrency >= 100000 ? 0 : 2, duration: 1, @@ -63,8 +63,7 @@ export class PortfolioPerformanceComponent implements OnChanges, OnInit { } else if (this.showDetails === false) { new CountUp( 'value', - this.performance?.currentNetPerformancePercentWithCurrencyEffect * - 100, + this.performance?.netPerformancePercentageWithCurrencyEffect * 100, { decimal: getNumberFormatDecimal(this.locale), decimalPlaces: 2, diff --git a/apps/client/src/app/components/portfolio-summary/portfolio-summary.component.html b/apps/client/src/app/components/portfolio-summary/portfolio-summary.component.html index c0a0da4da..6b80e87b6 100644 --- a/apps/client/src/app/components/portfolio-summary/portfolio-summary.component.html +++ b/apps/client/src/app/components/portfolio-summary/portfolio-summary.component.html @@ -75,9 +75,7 @@ [locale]="locale" [unit]="baseCurrency" [value]=" - isLoading - ? undefined - : summary?.currentGrossPerformanceWithCurrencyEffect + isLoading ? undefined : summary?.grossPerformanceWithCurrencyEffect " /> @@ -101,7 +99,7 @@ [value]=" isLoading ? undefined - : summary?.currentGrossPerformancePercentWithCurrencyEffect + : summary?.grossPerformancePercentageWithCurrencyEffect " /> @@ -131,9 +129,7 @@ [locale]="locale" [unit]="baseCurrency" [value]=" - isLoading - ? undefined - : summary?.currentNetPerformanceWithCurrencyEffect + isLoading ? undefined : summary?.netPerformanceWithCurrencyEffect " /> @@ -157,7 +153,7 @@ [value]=" isLoading ? undefined - : summary?.currentNetPerformancePercentWithCurrencyEffect + : summary?.netPerformancePercentageWithCurrencyEffect " /> @@ -174,7 +170,7 @@ [isCurrency]="true" [locale]="locale" [unit]="baseCurrency" - [value]="isLoading ? undefined : summary?.currentValue" + [value]="isLoading ? undefined : summary?.currentValueInBaseCurrency" /> diff --git a/apps/client/src/app/pages/portfolio/analysis/analysis-page.html b/apps/client/src/app/pages/portfolio/analysis/analysis-page.html index 5f6acdbe2..191dca06f 100644 --- a/apps/client/src/app/pages/portfolio/analysis/analysis-page.html +++ b/apps/client/src/app/pages/portfolio/analysis/analysis-page.html @@ -42,7 +42,7 @@ [value]=" isLoadingInvestmentChart ? undefined - : performance?.currentNetPerformance + : performance?.netPerformance " /> @@ -61,7 +61,7 @@ [value]=" isLoadingInvestmentChart ? undefined - : performance?.currentNetPerformancePercent + : performance?.netPerformancePercentage " /> @@ -86,10 +86,10 @@ [value]=" isLoadingInvestmentChart ? undefined - : performance?.currentNetPerformance === null + : performance?.netPerformance === null ? null - : performance?.currentNetPerformanceWithCurrencyEffect - - performance?.currentNetPerformance + : performance?.netPerformanceWithCurrencyEffect - + performance?.netPerformance " /> @@ -108,10 +108,10 @@ [value]=" isLoadingInvestmentChart ? undefined - : performance?.currentNetPerformancePercent === null + : performance?.netPerformancePercentage === null ? null - : performance?.currentNetPerformancePercentWithCurrencyEffect - - performance?.currentNetPerformancePercent + : performance?.netPerformancePercentageWithCurrencyEffect - + performance?.netPerformancePercentage " /> @@ -131,7 +131,7 @@ [value]=" isLoadingInvestmentChart ? undefined - : performance?.currentNetPerformanceWithCurrencyEffect + : performance?.netPerformanceWithCurrencyEffect " /> @@ -150,7 +150,7 @@ [value]=" isLoadingInvestmentChart ? undefined - : performance?.currentNetPerformancePercentWithCurrencyEffect + : performance?.netPerformancePercentageWithCurrencyEffect " /> diff --git a/libs/common/src/lib/interfaces/portfolio-performance.interface.ts b/libs/common/src/lib/interfaces/portfolio-performance.interface.ts index 79b96321b..9d4ac5fab 100644 --- a/libs/common/src/lib/interfaces/portfolio-performance.interface.ts +++ b/libs/common/src/lib/interfaces/portfolio-performance.interface.ts @@ -1,14 +1,14 @@ export interface PortfolioPerformance { annualizedPerformancePercent?: number; - currentGrossPerformance: number; - currentGrossPerformancePercent: number; - currentGrossPerformancePercentWithCurrencyEffect: number; - currentGrossPerformanceWithCurrencyEffect: number; - currentNetPerformance: number; - currentNetPerformancePercent: number; - currentNetPerformancePercentWithCurrencyEffect: number; - currentNetPerformanceWithCurrencyEffect: number; currentNetWorth?: number; - currentValue: number; + currentValueInBaseCurrency: number; + grossPerformance: number; + grossPerformancePercentage: number; + grossPerformancePercentageWithCurrencyEffect: number; + grossPerformanceWithCurrencyEffect: number; + netPerformance: number; + netPerformancePercentage: number; + netPerformancePercentageWithCurrencyEffect: number; + netPerformanceWithCurrencyEffect: number; totalInvestment: number; }