|
@ -10,7 +10,12 @@ import { ExchangeRateDataService } from '@ghostfolio/api/services/exchange-rate- |
|
|
import { IDataGatheringItem } from '@ghostfolio/api/services/interfaces/interfaces'; |
|
|
import { IDataGatheringItem } from '@ghostfolio/api/services/interfaces/interfaces'; |
|
|
import { getIntervalFromDateRange } from '@ghostfolio/common/calculation-helper'; |
|
|
import { getIntervalFromDateRange } from '@ghostfolio/common/calculation-helper'; |
|
|
import { MAX_CHART_ITEMS } from '@ghostfolio/common/config'; |
|
|
import { MAX_CHART_ITEMS } from '@ghostfolio/common/config'; |
|
|
import { DATE_FORMAT, getSum, parseDate } from '@ghostfolio/common/helper'; |
|
|
import { |
|
|
|
|
|
DATE_FORMAT, |
|
|
|
|
|
getSum, |
|
|
|
|
|
parseDate, |
|
|
|
|
|
resetHours |
|
|
|
|
|
} from '@ghostfolio/common/helper'; |
|
|
import { |
|
|
import { |
|
|
AssetProfileIdentifier, |
|
|
AssetProfileIdentifier, |
|
|
DataProviderInfo, |
|
|
DataProviderInfo, |
|
@ -32,7 +37,6 @@ import { |
|
|
format, |
|
|
format, |
|
|
isAfter, |
|
|
isAfter, |
|
|
isBefore, |
|
|
isBefore, |
|
|
max, |
|
|
|
|
|
min, |
|
|
min, |
|
|
subDays |
|
|
subDays |
|
|
} from 'date-fns'; |
|
|
} from 'date-fns'; |
|
@ -398,7 +402,7 @@ export abstract class PortfolioCalculator { |
|
|
? (netPerformancePercentage ?? null) |
|
|
? (netPerformancePercentage ?? null) |
|
|
: null, |
|
|
: null, |
|
|
netPerformancePercentageWithCurrencyEffect: !hasErrors |
|
|
netPerformancePercentageWithCurrencyEffect: !hasErrors |
|
|
? (netPerformancePercentageWithCurrencyEffect ?? null) |
|
|
? (netPerformancePercentageWithCurrencyEffectMap['max'] ?? null) |
|
|
: null, |
|
|
: null, |
|
|
netPerformancePercentageWithCurrencyEffectMap: !hasErrors |
|
|
netPerformancePercentageWithCurrencyEffectMap: !hasErrors |
|
|
? (netPerformancePercentageWithCurrencyEffectMap ?? null) |
|
|
? (netPerformancePercentageWithCurrencyEffectMap ?? null) |
|
@ -554,7 +558,6 @@ export abstract class PortfolioCalculator { |
|
|
? 0 |
|
|
? 0 |
|
|
: totalNetPerformanceValue |
|
|
: totalNetPerformanceValue |
|
|
.div(totalTimeWeightedInvestmentValue) |
|
|
.div(totalTimeWeightedInvestmentValue) |
|
|
.mul(100) |
|
|
|
|
|
.toNumber(); |
|
|
.toNumber(); |
|
|
|
|
|
|
|
|
const netPerformanceInPercentageWithCurrencyEffect = |
|
|
const netPerformanceInPercentageWithCurrencyEffect = |
|
@ -562,7 +565,6 @@ export abstract class PortfolioCalculator { |
|
|
? 0 |
|
|
? 0 |
|
|
: totalNetPerformanceValueWithCurrencyEffect |
|
|
: totalNetPerformanceValueWithCurrencyEffect |
|
|
.div(totalTimeWeightedInvestmentValueWithCurrencyEffect) |
|
|
.div(totalTimeWeightedInvestmentValueWithCurrencyEffect) |
|
|
.mul(100) |
|
|
|
|
|
.toNumber(); |
|
|
.toNumber(); |
|
|
|
|
|
|
|
|
return { |
|
|
return { |
|
@ -692,10 +694,9 @@ export abstract class PortfolioCalculator { |
|
|
let totalInvestmentValuesWithCurrencyEffect: number[] = []; |
|
|
let totalInvestmentValuesWithCurrencyEffect: number[] = []; |
|
|
|
|
|
|
|
|
for (let historicalDataItem of historicalData) { |
|
|
for (let historicalDataItem of historicalData) { |
|
|
if ( |
|
|
const date = resetHours(parseDate(historicalDataItem.date)); |
|
|
!isBefore(parseDate(historicalDataItem.date), subDays(start, 1)) && |
|
|
|
|
|
!isAfter(parseDate(historicalDataItem.date), end) |
|
|
if (!isBefore(date, start) && !isAfter(date, end)) { |
|
|
) { |
|
|
|
|
|
if (!isNumber(netPerformanceAtStartDate)) { |
|
|
if (!isNumber(netPerformanceAtStartDate)) { |
|
|
netPerformanceAtStartDate = historicalDataItem.netPerformance; |
|
|
netPerformanceAtStartDate = historicalDataItem.netPerformance; |
|
|
|
|
|
|
|
@ -706,6 +707,9 @@ export abstract class PortfolioCalculator { |
|
|
historicalDataItem.netPerformanceInPercentageWithCurrencyEffect; |
|
|
historicalDataItem.netPerformanceInPercentageWithCurrencyEffect; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const netPerformanceSinceStartDate = |
|
|
|
|
|
historicalDataItem.netPerformance - netPerformanceAtStartDate; |
|
|
|
|
|
|
|
|
const netPerformanceWithCurrencyEffectSinceStartDate = |
|
|
const netPerformanceWithCurrencyEffectSinceStartDate = |
|
|
historicalDataItem.netPerformanceWithCurrencyEffect - |
|
|
historicalDataItem.netPerformanceWithCurrencyEffect - |
|
|
netPerformanceWithCurrencyEffectAtStartDate; |
|
|
netPerformanceWithCurrencyEffectAtStartDate; |
|
@ -730,10 +734,11 @@ export abstract class PortfolioCalculator { |
|
|
historicalDataItem.netPerformance - netPerformanceAtStartDate, |
|
|
historicalDataItem.netPerformance - netPerformanceAtStartDate, |
|
|
netPerformanceWithCurrencyEffect: |
|
|
netPerformanceWithCurrencyEffect: |
|
|
netPerformanceWithCurrencyEffectSinceStartDate, |
|
|
netPerformanceWithCurrencyEffectSinceStartDate, |
|
|
|
|
|
netPerformanceInPercentage: |
|
|
|
|
|
netPerformanceSinceStartDate / timeWeightedInvestmentValue, |
|
|
netPerformanceInPercentageWithCurrencyEffect: |
|
|
netPerformanceInPercentageWithCurrencyEffect: |
|
|
(netPerformanceWithCurrencyEffectSinceStartDate / |
|
|
netPerformanceWithCurrencyEffectSinceStartDate / |
|
|
timeWeightedInvestmentValue) * |
|
|
timeWeightedInvestmentValue, |
|
|
100, |
|
|
|
|
|
// TODO: Add net worth with valuables
|
|
|
// TODO: Add net worth with valuables
|
|
|
// netWorth: totalCurrentValueWithCurrencyEffect
|
|
|
// netWorth: totalCurrentValueWithCurrencyEffect
|
|
|
// .plus(totalAccountBalanceWithCurrencyEffect)
|
|
|
// .plus(totalAccountBalanceWithCurrencyEffect)
|
|
|