Browse Source

Introduce type (#2885)

pull/2886/head
Thomas Kaul 9 months ago
committed by GitHub
parent
commit
7b45a8b3fc
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 35
      apps/api/src/app/portfolio/portfolio-calculator.ts
  2. 2
      libs/common/src/lib/interfaces/index.ts
  3. 41
      libs/common/src/lib/interfaces/symbol-metrics.interface.ts

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

@ -1,11 +1,11 @@
import { TimelineInfoInterface } from '@ghostfolio/api/app/portfolio/interfaces/timeline-info.interface'; import { TimelineInfoInterface } from '@ghostfolio/api/app/portfolio/interfaces/timeline-info.interface';
import { ExchangeRateDataService } from '@ghostfolio/api/services/exchange-rate-data/exchange-rate-data.service'; import { ExchangeRateDataService } from '@ghostfolio/api/services/exchange-rate-data/exchange-rate-data.service';
import { IDataGatheringItem } from '@ghostfolio/api/services/interfaces/interfaces'; import { IDataGatheringItem } from '@ghostfolio/api/services/interfaces/interfaces';
import { DEFAULT_CURRENCY } from '@ghostfolio/common/config';
import { DATE_FORMAT, parseDate, resetHours } from '@ghostfolio/common/helper'; import { DATE_FORMAT, parseDate, resetHours } from '@ghostfolio/common/helper';
import { import {
DataProviderInfo, DataProviderInfo,
ResponseError, ResponseError,
SymbolMetrics,
TimelinePosition TimelinePosition
} from '@ghostfolio/common/interfaces'; } from '@ghostfolio/common/interfaces';
import { GroupBy } from '@ghostfolio/common/types'; import { GroupBy } from '@ghostfolio/common/types';
@ -1143,7 +1143,7 @@ export class PortfolioCalculator {
start: Date; start: Date;
step?: number; step?: number;
symbol: string; symbol: string;
}) { }): SymbolMetrics {
const currentExchangeRate = exchangeRates[format(new Date(), DATE_FORMAT)]; const currentExchangeRate = exchangeRates[format(new Date(), DATE_FORMAT)];
const currentValues: { [date: string]: Big } = {}; const currentValues: { [date: string]: Big } = {};
const currentValuesWithCurrencyEffect: { [date: string]: Big } = {}; const currentValuesWithCurrencyEffect: { [date: string]: Big } = {};
@ -1195,18 +1195,28 @@ export class PortfolioCalculator {
if (orders.length <= 0) { if (orders.length <= 0) {
return { return {
currentValues: {}, currentValues: {},
currentValuesWithCurrencyEffect: {},
grossPerformance: new Big(0), grossPerformance: new Big(0),
grossPerformancePercentage: new Big(0), grossPerformancePercentage: new Big(0),
grossPerformancePercentageWithCurrencyEffect: new Big(0),
grossPerformanceWithCurrencyEffect: new Big(0), grossPerformanceWithCurrencyEffect: new Big(0),
grossPerformanceWithCurrencyEffectPercentage: new Big(0),
hasErrors: false, hasErrors: false,
initialValue: new Big(0), initialValue: new Big(0),
initialValueWithCurrencyEffect: new Big(0),
investmentValues: {}, investmentValues: {},
investmentValuesWithCurrencyEffect: {},
netPerformance: new Big(0), netPerformance: new Big(0),
netPerformancePercentage: new Big(0), netPerformancePercentage: new Big(0),
netPerformancePercentageWithCurrencyEffect: new Big(0),
netPerformanceValues: {}, netPerformanceValues: {},
netPerformanceValuesWithCurrencyEffect: {},
netPerformanceWithCurrencyEffect: new Big(0), netPerformanceWithCurrencyEffect: new Big(0),
netPerformanceWithCurrencyEffectPercentage: new Big(0) timeWeightedInvestment: new Big(0),
timeWeightedInvestmentValues: {},
timeWeightedInvestmentValuesWithCurrencyEffect: {},
timeWeightedInvestmentWithCurrencyEffect: new Big(0),
totalInvestment: new Big(0),
totalInvestmentWithCurrencyEffect: new Big(0)
}; };
} }
@ -1223,16 +1233,29 @@ export class PortfolioCalculator {
(!unitPriceAtStartDate && isBefore(dateOfFirstTransaction, start)) (!unitPriceAtStartDate && isBefore(dateOfFirstTransaction, start))
) { ) {
return { return {
currentValues: {},
currentValuesWithCurrencyEffect: {},
grossPerformance: new Big(0), grossPerformance: new Big(0),
grossPerformancePercentage: new Big(0), grossPerformancePercentage: new Big(0),
grossPerformancePercentageWithCurrencyEffect: new Big(0),
grossPerformanceWithCurrencyEffect: new Big(0), grossPerformanceWithCurrencyEffect: new Big(0),
grossPerformanceWithCurrencyEffectPercentage: new Big(0),
hasErrors: true, hasErrors: true,
initialValue: new Big(0), initialValue: new Big(0),
initialValueWithCurrencyEffect: new Big(0),
investmentValues: {},
investmentValuesWithCurrencyEffect: {},
netPerformance: new Big(0), netPerformance: new Big(0),
netPerformancePercentage: new Big(0), netPerformancePercentage: new Big(0),
netPerformancePercentageWithCurrencyEffect: new Big(0),
netPerformanceValues: {},
netPerformanceValuesWithCurrencyEffect: {},
netPerformanceWithCurrencyEffect: new Big(0), netPerformanceWithCurrencyEffect: new Big(0),
netPerformanceWithCurrencyEffectPercentage: new Big(0) timeWeightedInvestment: new Big(0),
timeWeightedInvestmentValues: {},
timeWeightedInvestmentValuesWithCurrencyEffect: {},
timeWeightedInvestmentWithCurrencyEffect: new Big(0),
totalInvestment: new Big(0),
totalInvestmentWithCurrencyEffect: new Big(0)
}; };
} }

2
libs/common/src/lib/interfaces/index.ts

@ -43,6 +43,7 @@ import type { PortfolioPerformanceResponse } from './responses/portfolio-perform
import type { ScraperConfiguration } from './scraper-configuration.interface'; import type { ScraperConfiguration } from './scraper-configuration.interface';
import type { Statistics } from './statistics.interface'; import type { Statistics } from './statistics.interface';
import type { Subscription } from './subscription.interface'; import type { Subscription } from './subscription.interface';
import type { SymbolMetrics } from './symbol-metrics.interface';
import type { SystemMessage } from './system-message.interface'; import type { SystemMessage } from './system-message.interface';
import type { TabConfiguration } from './tab-configuration.interface'; import type { TabConfiguration } from './tab-configuration.interface';
import type { TimelinePosition } from './timeline-position.interface'; import type { TimelinePosition } from './timeline-position.interface';
@ -95,6 +96,7 @@ export {
Statistics, Statistics,
SystemMessage, SystemMessage,
Subscription, Subscription,
SymbolMetrics,
TabConfiguration, TabConfiguration,
TimelinePosition, TimelinePosition,
UniqueAsset, UniqueAsset,

41
libs/common/src/lib/interfaces/symbol-metrics.interface.ts

@ -0,0 +1,41 @@
import Big from 'big.js';
export interface SymbolMetrics {
currentValues: {
[date: string]: Big;
};
currentValuesWithCurrencyEffect: {
[date: string]: Big;
};
grossPerformance: Big;
grossPerformancePercentage: Big;
grossPerformancePercentageWithCurrencyEffect: Big;
grossPerformanceWithCurrencyEffect: Big;
hasErrors: boolean;
initialValue: Big;
initialValueWithCurrencyEffect: Big;
investmentValues: {
[date: string]: Big;
};
investmentValuesWithCurrencyEffect: {
[date: string]: Big;
};
netPerformance: Big;
netPerformancePercentage: Big;
netPerformancePercentageWithCurrencyEffect: Big;
netPerformanceValues: {
[date: string]: Big;
};
netPerformanceValuesWithCurrencyEffect: { [date: string]: Big };
netPerformanceWithCurrencyEffect: Big;
timeWeightedInvestment: Big;
timeWeightedInvestmentValues: {
[date: string]: Big;
};
timeWeightedInvestmentValuesWithCurrencyEffect: {
[date: string]: Big;
};
timeWeightedInvestmentWithCurrencyEffect: Big;
totalInvestment: Big;
totalInvestmentWithCurrencyEffect: Big;
}
Loading…
Cancel
Save