Browse Source

Refactoring

pull/2948/head
Thomas Kaul 2 years ago
parent
commit
90c4779ff3
  1. 4
      apps/api/src/app/portfolio/portfolio-calculator-novn-buy-and-sell.spec.ts
  2. 19
      apps/api/src/app/portfolio/portfolio-calculator.ts
  3. 1
      libs/common/src/lib/interfaces/historical-data-item.interface.ts

4
apps/api/src/app/portfolio/portfolio-calculator-novn-buy-and-sell.spec.ts

@ -85,7 +85,7 @@ describe('PortfolioCalculator', () => {
expect(chartData[0]).toEqual({
date: '2022-03-07',
investment: 151.6,
investmentValueWithCurrencyEffect: 151.6,
netPerformance: 0,
netPerformanceInPercentage: 0,
netPerformanceInPercentageWithCurrencyEffect: 0,
@ -98,7 +98,7 @@ describe('PortfolioCalculator', () => {
expect(chartData[chartData.length - 1]).toEqual({
date: '2022-04-11',
investment: 0,
investmentValueWithCurrencyEffect: 0,
netPerformance: 19.86,
netPerformanceInPercentage: 13.100263852242744,
netPerformanceInPercentageWithCurrencyEffect: 13.100263852242744,

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

@ -3,6 +3,7 @@ import { IDataGatheringItem } from '@ghostfolio/api/services/interfaces/interfac
import { DATE_FORMAT, parseDate, resetHours } from '@ghostfolio/common/helper';
import {
DataProviderInfo,
HistoricalDataItem,
ResponseError,
SymbolMetrics,
TimelinePosition
@ -173,7 +174,11 @@ export class PortfolioCalculator {
this.transactionPoints = transactionPoints;
}
public async getChartData(start: Date, end = new Date(Date.now()), step = 1) {
public async getChartData(
start: Date,
end = new Date(Date.now()),
step = 1
): Promise<HistoricalDataItem[]> {
const symbols: { [symbol: string]: boolean } = {};
const transactionPointsBeforeEndDate =
@ -242,7 +247,7 @@ export class PortfolioCalculator {
const accumulatedValuesByDate: {
[date: string]: {
investmentValue: Big;
investmentValueWithCurrencyEffect: Big;
totalCurrentValue: Big;
totalCurrentValueWithCurrencyEffect: Big;
totalInvestmentValue: Big;
@ -344,8 +349,9 @@ export class PortfolioCalculator {
] ?? new Big(0);
accumulatedValuesByDate[dateString] = {
investmentValue: (
accumulatedValuesByDate[dateString]?.investmentValue ?? new Big(0)
investmentValueWithCurrencyEffect: (
accumulatedValuesByDate[dateString]
?.investmentValueWithCurrencyEffect ?? new Big(0)
).add(investmentValueWithCurrencyEffect),
totalCurrentValue: (
accumulatedValuesByDate[dateString]?.totalCurrentValue ?? new Big(0)
@ -384,7 +390,7 @@ export class PortfolioCalculator {
return Object.entries(accumulatedValuesByDate).map(([date, values]) => {
const {
investmentValue,
investmentValueWithCurrencyEffect,
totalCurrentValue,
totalCurrentValueWithCurrencyEffect,
totalInvestmentValue,
@ -414,7 +420,8 @@ export class PortfolioCalculator {
date,
netPerformanceInPercentage,
netPerformanceInPercentageWithCurrencyEffect,
investment: investmentValue.toNumber(),
investmentValueWithCurrencyEffect:
investmentValueWithCurrencyEffect.toNumber(),
netPerformance: totalNetPerformanceValue.toNumber(),
netPerformanceWithCurrencyEffect:
totalNetPerformanceValueWithCurrencyEffect.toNumber(),

1
libs/common/src/lib/interfaces/historical-data-item.interface.ts

@ -2,6 +2,7 @@ export interface HistoricalDataItem {
averagePrice?: number;
date: string;
grossPerformancePercent?: number;
investmentValueWithCurrencyEffect?: number;
marketPrice?: number;
netPerformance?: number;
netPerformanceInPercentage?: number;

Loading…
Cancel
Save