diff --git a/apps/api/src/app/portfolio/portfolio-calculator.ts b/apps/api/src/app/portfolio/portfolio-calculator.ts index 0f6667949..e7295d89a 100644 --- a/apps/api/src/app/portfolio/portfolio-calculator.ts +++ b/apps/api/src/app/portfolio/portfolio-calculator.ts @@ -1,11 +1,11 @@ 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 { IDataGatheringItem } from '@ghostfolio/api/services/interfaces/interfaces'; -import { DEFAULT_CURRENCY } from '@ghostfolio/common/config'; import { DATE_FORMAT, parseDate, resetHours } from '@ghostfolio/common/helper'; import { DataProviderInfo, ResponseError, + SymbolMetrics, TimelinePosition } from '@ghostfolio/common/interfaces'; import { GroupBy } from '@ghostfolio/common/types'; @@ -1143,7 +1143,7 @@ export class PortfolioCalculator { start: Date; step?: number; symbol: string; - }) { + }): SymbolMetrics { const currentExchangeRate = exchangeRates[format(new Date(), DATE_FORMAT)]; const currentValues: { [date: string]: Big } = {}; const currentValuesWithCurrencyEffect: { [date: string]: Big } = {}; @@ -1195,18 +1195,28 @@ export class PortfolioCalculator { if (orders.length <= 0) { return { currentValues: {}, + currentValuesWithCurrencyEffect: {}, grossPerformance: new Big(0), grossPerformancePercentage: new Big(0), + grossPerformancePercentageWithCurrencyEffect: new Big(0), grossPerformanceWithCurrencyEffect: new Big(0), - grossPerformanceWithCurrencyEffectPercentage: new Big(0), hasErrors: false, initialValue: new Big(0), + initialValueWithCurrencyEffect: new Big(0), investmentValues: {}, + investmentValuesWithCurrencyEffect: {}, netPerformance: new Big(0), netPerformancePercentage: new Big(0), + netPerformancePercentageWithCurrencyEffect: new Big(0), netPerformanceValues: {}, + netPerformanceValuesWithCurrencyEffect: {}, 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)) ) { return { + currentValues: {}, + currentValuesWithCurrencyEffect: {}, grossPerformance: new Big(0), grossPerformancePercentage: new Big(0), + grossPerformancePercentageWithCurrencyEffect: new Big(0), grossPerformanceWithCurrencyEffect: new Big(0), - grossPerformanceWithCurrencyEffectPercentage: new Big(0), hasErrors: true, initialValue: new Big(0), + initialValueWithCurrencyEffect: new Big(0), + investmentValues: {}, + investmentValuesWithCurrencyEffect: {}, netPerformance: new Big(0), netPerformancePercentage: new Big(0), + netPerformancePercentageWithCurrencyEffect: new Big(0), + netPerformanceValues: {}, + netPerformanceValuesWithCurrencyEffect: {}, 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) }; } diff --git a/libs/common/src/lib/interfaces/index.ts b/libs/common/src/lib/interfaces/index.ts index 2875cb305..491870191 100644 --- a/libs/common/src/lib/interfaces/index.ts +++ b/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 { Statistics } from './statistics.interface'; import type { Subscription } from './subscription.interface'; +import type { SymbolMetrics } from './symbol-metrics.interface'; import type { SystemMessage } from './system-message.interface'; import type { TabConfiguration } from './tab-configuration.interface'; import type { TimelinePosition } from './timeline-position.interface'; @@ -95,6 +96,7 @@ export { Statistics, SystemMessage, Subscription, + SymbolMetrics, TabConfiguration, TimelinePosition, UniqueAsset, diff --git a/libs/common/src/lib/interfaces/symbol-metrics.interface.ts b/libs/common/src/lib/interfaces/symbol-metrics.interface.ts new file mode 100644 index 000000000..71cec81b2 --- /dev/null +++ b/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; +}