Browse Source

Refactoring

pull/3366/head
Thomas Kaul 1 year ago
parent
commit
c6f38e2451
  1. 30
      apps/api/src/app/portfolio/portfolio.controller.ts
  2. 72
      apps/api/src/app/portfolio/portfolio.service.ts
  3. 6
      apps/client/src/app/components/portfolio-performance/portfolio-performance.component.html
  4. 9
      apps/client/src/app/components/portfolio-performance/portfolio-performance.component.ts
  5. 14
      apps/client/src/app/components/portfolio-summary/portfolio-summary.component.html
  6. 20
      apps/client/src/app/pages/portfolio/analysis/analysis-page.html
  7. 18
      libs/common/src/lib/interfaces/portfolio-performance.interface.ts

30
apps/api/src/app/portfolio/portfolio.controller.ts

@ -165,21 +165,21 @@ export class PortfolioController {
portfolioSummary = nullifyValuesInObject(summary, [ portfolioSummary = nullifyValuesInObject(summary, [
'cash', 'cash',
'committedFunds', 'committedFunds',
'currentGrossPerformance',
'currentGrossPerformanceWithCurrencyEffect',
'currentNetPerformance',
'currentNetPerformanceWithCurrencyEffect',
'currentNetWorth', 'currentNetWorth',
'currentValue', 'currentValueInBaseCurrency',
'dividendInBaseCurrency', 'dividendInBaseCurrency',
'emergencyFund', 'emergencyFund',
'excludedAccountsAndActivities', 'excludedAccountsAndActivities',
'fees', 'fees',
'filteredValueInBaseCurrency', 'filteredValueInBaseCurrency',
'fireWealth', 'fireWealth',
'grossPerformance',
'grossPerformanceWithCurrencyEffect',
'interest', 'interest',
'items', 'items',
'liabilities', 'liabilities',
'netPerformance',
'netPerformanceWithCurrencyEffect',
'totalBuy', 'totalBuy',
'totalInvestment', 'totalInvestment',
'totalSell', 'totalSell',
@ -449,10 +449,14 @@ export class PortfolioController {
.div(performanceInformation.performance.totalInvestment) .div(performanceInformation.performance.totalInvestment)
.toNumber(), .toNumber(),
valueInPercentage: valueInPercentage:
performanceInformation.performance.currentValue === 0 performanceInformation.performance.currentValueInBaseCurrency ===
0
? 0 ? 0
: new Big(value) : new Big(value)
.div(performanceInformation.performance.currentValue) .div(
performanceInformation.performance
.currentValueInBaseCurrency
)
.toNumber() .toNumber()
}; };
} }
@ -461,12 +465,12 @@ export class PortfolioController {
performanceInformation.performance = nullifyValuesInObject( performanceInformation.performance = nullifyValuesInObject(
performanceInformation.performance, performanceInformation.performance,
[ [
'currentGrossPerformance',
'currentGrossPerformanceWithCurrencyEffect',
'currentNetPerformance',
'currentNetPerformanceWithCurrencyEffect',
'currentNetWorth', 'currentNetWorth',
'currentValue', 'currentValueInBaseCurrency',
'grossPerformance',
'grossPerformanceWithCurrencyEffect',
'netPerformance',
'netPerformanceWithCurrencyEffect',
'totalInvestment' 'totalInvestment'
] ]
); );
@ -483,7 +487,7 @@ export class PortfolioController {
); );
performanceInformation.performance = nullifyValuesInObject( performanceInformation.performance = nullifyValuesInObject(
performanceInformation.performance, performanceInformation.performance,
['currentNetPerformance', 'currentNetPerformancePercent'] ['netPerformance']
); );
} }

72
apps/api/src/app/portfolio/portfolio.service.ts

@ -1108,16 +1108,16 @@ export class PortfolioService {
firstOrderDate: undefined, firstOrderDate: undefined,
hasErrors: false, hasErrors: false,
performance: { performance: {
currentGrossPerformance: 0,
currentGrossPerformancePercent: 0,
currentGrossPerformancePercentWithCurrencyEffect: 0,
currentGrossPerformanceWithCurrencyEffect: 0,
currentNetPerformance: 0,
currentNetPerformancePercent: 0,
currentNetPerformancePercentWithCurrencyEffect: 0,
currentNetPerformanceWithCurrencyEffect: 0,
currentNetWorth: 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 totalInvestment: 0
} }
}; };
@ -1152,9 +1152,9 @@ export class PortfolioService {
let currentNetPerformance = netPerformance; let currentNetPerformance = netPerformance;
let currentNetPerformancePercent = netPerformancePercentage; let currentNetPerformancePercentage = netPerformancePercentage;
let currentNetPerformancePercentWithCurrencyEffect = let currentNetPerformancePercentageWithCurrencyEffect =
netPerformancePercentageWithCurrencyEffect; netPerformancePercentageWithCurrencyEffect;
let currentNetPerformanceWithCurrencyEffect = let currentNetPerformanceWithCurrencyEffect =
@ -1173,11 +1173,11 @@ export class PortfolioService {
if (itemOfToday) { if (itemOfToday) {
currentNetPerformance = new Big(itemOfToday.netPerformance); currentNetPerformance = new Big(itemOfToday.netPerformance);
currentNetPerformancePercent = new Big( currentNetPerformancePercentage = new Big(
itemOfToday.netPerformanceInPercentage itemOfToday.netPerformanceInPercentage
).div(100); ).div(100);
currentNetPerformancePercentWithCurrencyEffect = new Big( currentNetPerformancePercentageWithCurrencyEffect = new Big(
itemOfToday.netPerformanceInPercentageWithCurrencyEffect itemOfToday.netPerformanceInPercentageWithCurrencyEffect
).div(100); ).div(100);
@ -1195,19 +1195,19 @@ export class PortfolioService {
firstOrderDate: parseDate(items[0]?.date), firstOrderDate: parseDate(items[0]?.date),
performance: { performance: {
currentNetWorth, currentNetWorth,
currentGrossPerformance: grossPerformance.toNumber(), currentValueInBaseCurrency: currentValueInBaseCurrency.toNumber(),
currentGrossPerformancePercent: grossPerformancePercentage.toNumber(), grossPerformance: grossPerformance.toNumber(),
currentGrossPerformancePercentWithCurrencyEffect: grossPerformancePercentage: grossPerformancePercentage.toNumber(),
grossPerformancePercentageWithCurrencyEffect:
grossPerformancePercentageWithCurrencyEffect.toNumber(), grossPerformancePercentageWithCurrencyEffect.toNumber(),
currentGrossPerformanceWithCurrencyEffect: grossPerformanceWithCurrencyEffect:
grossPerformanceWithCurrencyEffect.toNumber(), grossPerformanceWithCurrencyEffect.toNumber(),
currentNetPerformance: currentNetPerformance.toNumber(), netPerformance: currentNetPerformance.toNumber(),
currentNetPerformancePercent: currentNetPerformancePercent.toNumber(), netPerformancePercentage: currentNetPerformancePercentage.toNumber(),
currentNetPerformancePercentWithCurrencyEffect: netPerformancePercentageWithCurrencyEffect:
currentNetPerformancePercentWithCurrencyEffect.toNumber(), currentNetPerformancePercentageWithCurrencyEffect.toNumber(),
currentNetPerformanceWithCurrencyEffect: netPerformanceWithCurrencyEffect:
currentNetPerformanceWithCurrencyEffect.toNumber(), currentNetPerformanceWithCurrencyEffect.toNumber(),
currentValue: currentValueInBaseCurrency.toNumber(),
totalInvestment: totalInvestment.toNumber() totalInvestment: totalInvestment.toNumber()
} }
}; };
@ -1732,19 +1732,7 @@ export class PortfolioService {
totalBuy, totalBuy,
totalSell, totalSell,
committedFunds: committedFunds.toNumber(), committedFunds: committedFunds.toNumber(),
currentGrossPerformance: grossPerformance.toNumber(), currentValueInBaseCurrency: currentValueInBaseCurrency.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(),
dividendInBaseCurrency: dividendInBaseCurrency.toNumber(), dividendInBaseCurrency: dividendInBaseCurrency.toNumber(),
emergencyFund: { emergencyFund: {
assets: emergencyFundPositionsValueInBaseCurrency, assets: emergencyFundPositionsValueInBaseCurrency,
@ -1761,9 +1749,21 @@ export class PortfolioService {
fireWealth: new Big(currentValueInBaseCurrency) fireWealth: new Big(currentValueInBaseCurrency)
.minus(emergencyFundPositionsValueInBaseCurrency) .minus(emergencyFundPositionsValueInBaseCurrency)
.toNumber(), .toNumber(),
grossPerformance: grossPerformance.toNumber(),
grossPerformancePercentage: grossPerformancePercentage.toNumber(),
grossPerformancePercentageWithCurrencyEffect:
grossPerformancePercentageWithCurrencyEffect.toNumber(),
grossPerformanceWithCurrencyEffect:
grossPerformanceWithCurrencyEffect.toNumber(),
interest: interest.toNumber(), interest: interest.toNumber(),
items: valuables.toNumber(), items: valuables.toNumber(),
liabilities: liabilities.toNumber(), liabilities: liabilities.toNumber(),
netPerformance: netPerformance.toNumber(),
netPerformancePercentage: netPerformancePercentage.toNumber(),
netPerformancePercentageWithCurrencyEffect:
netPerformancePercentageWithCurrencyEffect.toNumber(),
netPerformanceWithCurrencyEffect:
netPerformanceWithCurrencyEffect.toNumber(),
ordersCount: activities.filter(({ type }) => { ordersCount: activities.filter(({ type }) => {
return ['BUY', 'SELL'].includes(type); return ['BUY', 'SELL'].includes(type);
}).length, }).length,

6
apps/client/src/app/components/portfolio-performance/portfolio-performance.component.html

@ -41,9 +41,7 @@
[isCurrency]="true" [isCurrency]="true"
[locale]="locale" [locale]="locale"
[value]=" [value]="
isLoading isLoading ? undefined : performance?.netPerformanceWithCurrencyEffect
? undefined
: performance?.currentNetPerformanceWithCurrencyEffect
" "
/> />
</div> </div>
@ -55,7 +53,7 @@
[value]=" [value]="
isLoading isLoading
? undefined ? undefined
: performance?.currentNetPerformancePercentWithCurrencyEffect : performance?.netPerformancePercentageWithCurrencyEffect
" "
/> />
</div> </div>

9
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 = ''; this.value.nativeElement.innerHTML = '';
} }
} else { } else {
if (isNumber(this.performance?.currentValue)) { if (isNumber(this.performance?.currentValueInBaseCurrency)) {
new CountUp('value', this.performance?.currentValue, { new CountUp('value', this.performance?.currentValueInBaseCurrency, {
decimal: getNumberFormatDecimal(this.locale), decimal: getNumberFormatDecimal(this.locale),
decimalPlaces: decimalPlaces:
this.deviceType === 'mobile' && this.deviceType === 'mobile' &&
this.performance?.currentValue >= 100000 this.performance?.currentValueInBaseCurrency >= 100000
? 0 ? 0
: 2, : 2,
duration: 1, duration: 1,
@ -63,8 +63,7 @@ export class PortfolioPerformanceComponent implements OnChanges, OnInit {
} else if (this.showDetails === false) { } else if (this.showDetails === false) {
new CountUp( new CountUp(
'value', 'value',
this.performance?.currentNetPerformancePercentWithCurrencyEffect * this.performance?.netPerformancePercentageWithCurrencyEffect * 100,
100,
{ {
decimal: getNumberFormatDecimal(this.locale), decimal: getNumberFormatDecimal(this.locale),
decimalPlaces: 2, decimalPlaces: 2,

14
apps/client/src/app/components/portfolio-summary/portfolio-summary.component.html

@ -75,9 +75,7 @@
[locale]="locale" [locale]="locale"
[unit]="baseCurrency" [unit]="baseCurrency"
[value]=" [value]="
isLoading isLoading ? undefined : summary?.grossPerformanceWithCurrencyEffect
? undefined
: summary?.currentGrossPerformanceWithCurrencyEffect
" "
/> />
</div> </div>
@ -101,7 +99,7 @@
[value]=" [value]="
isLoading isLoading
? undefined ? undefined
: summary?.currentGrossPerformancePercentWithCurrencyEffect : summary?.grossPerformancePercentageWithCurrencyEffect
" "
/> />
</div> </div>
@ -131,9 +129,7 @@
[locale]="locale" [locale]="locale"
[unit]="baseCurrency" [unit]="baseCurrency"
[value]=" [value]="
isLoading isLoading ? undefined : summary?.netPerformanceWithCurrencyEffect
? undefined
: summary?.currentNetPerformanceWithCurrencyEffect
" "
/> />
</div> </div>
@ -157,7 +153,7 @@
[value]=" [value]="
isLoading isLoading
? undefined ? undefined
: summary?.currentNetPerformancePercentWithCurrencyEffect : summary?.netPerformancePercentageWithCurrencyEffect
" "
/> />
</div> </div>
@ -174,7 +170,7 @@
[isCurrency]="true" [isCurrency]="true"
[locale]="locale" [locale]="locale"
[unit]="baseCurrency" [unit]="baseCurrency"
[value]="isLoading ? undefined : summary?.currentValue" [value]="isLoading ? undefined : summary?.currentValueInBaseCurrency"
/> />
</div> </div>
</div> </div>

20
apps/client/src/app/pages/portfolio/analysis/analysis-page.html

@ -42,7 +42,7 @@
[value]=" [value]="
isLoadingInvestmentChart isLoadingInvestmentChart
? undefined ? undefined
: performance?.currentNetPerformance : performance?.netPerformance
" "
/> />
</div> </div>
@ -61,7 +61,7 @@
[value]=" [value]="
isLoadingInvestmentChart isLoadingInvestmentChart
? undefined ? undefined
: performance?.currentNetPerformancePercent : performance?.netPerformancePercentage
" "
/> />
</div> </div>
@ -86,10 +86,10 @@
[value]=" [value]="
isLoadingInvestmentChart isLoadingInvestmentChart
? undefined ? undefined
: performance?.currentNetPerformance === null : performance?.netPerformance === null
? null ? null
: performance?.currentNetPerformanceWithCurrencyEffect - : performance?.netPerformanceWithCurrencyEffect -
performance?.currentNetPerformance performance?.netPerformance
" "
/> />
</div> </div>
@ -108,10 +108,10 @@
[value]=" [value]="
isLoadingInvestmentChart isLoadingInvestmentChart
? undefined ? undefined
: performance?.currentNetPerformancePercent === null : performance?.netPerformancePercentage === null
? null ? null
: performance?.currentNetPerformancePercentWithCurrencyEffect - : performance?.netPerformancePercentageWithCurrencyEffect -
performance?.currentNetPerformancePercent performance?.netPerformancePercentage
" "
/> />
</div> </div>
@ -131,7 +131,7 @@
[value]=" [value]="
isLoadingInvestmentChart isLoadingInvestmentChart
? undefined ? undefined
: performance?.currentNetPerformanceWithCurrencyEffect : performance?.netPerformanceWithCurrencyEffect
" "
/> />
</div> </div>
@ -150,7 +150,7 @@
[value]=" [value]="
isLoadingInvestmentChart isLoadingInvestmentChart
? undefined ? undefined
: performance?.currentNetPerformancePercentWithCurrencyEffect : performance?.netPerformancePercentageWithCurrencyEffect
" "
/> />
</div> </div>

18
libs/common/src/lib/interfaces/portfolio-performance.interface.ts

@ -1,14 +1,14 @@
export interface PortfolioPerformance { export interface PortfolioPerformance {
annualizedPerformancePercent?: number; annualizedPerformancePercent?: number;
currentGrossPerformance: number;
currentGrossPerformancePercent: number;
currentGrossPerformancePercentWithCurrencyEffect: number;
currentGrossPerformanceWithCurrencyEffect: number;
currentNetPerformance: number;
currentNetPerformancePercent: number;
currentNetPerformancePercentWithCurrencyEffect: number;
currentNetPerformanceWithCurrencyEffect: number;
currentNetWorth?: 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; totalInvestment: number;
} }

Loading…
Cancel
Save