Browse Source

Generalize get performance method

pull/5027/head
Dan 2 months ago
parent
commit
997fbb7b01
  1. 27
      apps/api/src/app/portfolio/calculator/portfolio-calculator.ts
  2. 13
      apps/api/src/app/portfolio/portfolio.service.ts

27
apps/api/src/app/portfolio/calculator/portfolio-calculator.ts

@ -774,7 +774,16 @@ export abstract class PortfolioCalculator {
} }
@LogPerformance @LogPerformance
public async getPerformance({ end, start }) { public async getPerformance({ end, start }): Promise<{
chart: HistoricalDataItem[];
netPerformance: number;
netPerformanceInPercentage: number;
netPerformanceWithCurrencyEffect: number;
netPerformanceInPercentageWithCurrencyEffect: number;
netWorth: number;
totalInvestment: number;
valueWithCurrencyEffect: number;
}> {
await this.snapshotPromise; await this.snapshotPromise;
const { historicalData } = this.snapshot; const { historicalData } = this.snapshot;
@ -815,6 +824,7 @@ export abstract class PortfolioCalculator {
totalInvestmentValuesWithCurrencyEffect.length totalInvestmentValuesWithCurrencyEffect.length
: 0; : 0;
//TODO : Extract in abstractFunction and use timeweighted for ROI + Handle total values separately
chart.push({ chart.push({
...historicalDataItem, ...historicalDataItem,
netPerformance: netPerformance:
@ -839,7 +849,20 @@ export abstract class PortfolioCalculator {
} }
} }
return { chart }; const last = chart.at(-1);
return {
chart,
netPerformance: last?.netPerformance ?? 0,
netPerformanceInPercentage: last?.netPerformanceInPercentage ?? 0,
netPerformanceWithCurrencyEffect:
last?.netPerformanceWithCurrencyEffect ?? 0,
netPerformanceInPercentageWithCurrencyEffect:
last?.netPerformanceInPercentageWithCurrencyEffect ?? 0,
netWorth: last?.netWorth ?? 0,
totalInvestment: last?.totalInvestment ?? 0,
valueWithCurrencyEffect: last?.valueWithCurrencyEffect ?? 0
};
} }
public getStartDate() { public getStartDate() {

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

@ -1155,9 +1155,8 @@ export class PortfolioService {
const { endDate, startDate } = getIntervalFromDateRange(dateRange); const { endDate, startDate } = getIntervalFromDateRange(dateRange);
const range = { end: endDate, start: startDate }; const range = { end: endDate, start: startDate };
const { chart } = await portfolioCalculator.getPerformance(range);
const { const {
chart,
netPerformance, netPerformance,
netPerformanceInPercentage, netPerformanceInPercentage,
netPerformanceInPercentageWithCurrencyEffect, netPerformanceInPercentageWithCurrencyEffect,
@ -1165,15 +1164,7 @@ export class PortfolioService {
netWorth, netWorth,
totalInvestment, totalInvestment,
valueWithCurrencyEffect valueWithCurrencyEffect
} = chart?.at(-1) ?? { } = await portfolioCalculator.getPerformance(range);
netPerformance: 0,
netPerformanceInPercentage: 0,
netPerformanceInPercentageWithCurrencyEffect: 0,
netPerformanceWithCurrencyEffect: 0,
netWorth: 0,
totalInvestment: 0,
valueWithCurrencyEffect: 0
};
return { return {
chart, chart,

Loading…
Cancel
Save