Browse Source

Fix net performance percentage of date ranges

pull/7911/head
Thomas Kaul 4 weeks ago
parent
commit
3971f010b2
  1. 21
      apps/api/src/app/portfolio/calculator/portfolio-calculator.ts

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

@ -822,8 +822,10 @@ export abstract class PortfolioCalculator {
netPerformanceWithCurrencyEffectAtStartDate; netPerformanceWithCurrencyEffectAtStartDate;
if (historicalDataItem.totalInvestmentValueWithCurrencyEffect > 0) { if (historicalDataItem.totalInvestmentValueWithCurrencyEffect > 0) {
// The invested capital in the date range is the value at its start // Add the gross performance at the start date of the range to the
// date: the investment plus the gross performance up to that date // investment of each day. Thus the range starts with the value of
// its first day, and subsequent buy and sell activities stay
// included.
timeWeightedInvestmentValuesWithCurrencyEffect.push( timeWeightedInvestmentValuesWithCurrencyEffect.push(
historicalDataItem.totalInvestmentValueWithCurrencyEffect + historicalDataItem.totalInvestmentValueWithCurrencyEffect +
grossPerformanceWithCurrencyEffectAtStartDate grossPerformanceWithCurrencyEffectAtStartDate
@ -838,19 +840,18 @@ export abstract class PortfolioCalculator {
chart.push({ chart.push({
...historicalDataItem, ...historicalDataItem,
netPerformance: netPerformance: netPerformanceSinceStartDate,
historicalDataItem.netPerformance - netPerformanceAtStartDate,
netPerformanceWithCurrencyEffect: netPerformanceWithCurrencyEffect:
netPerformanceWithCurrencyEffectSinceStartDate, netPerformanceWithCurrencyEffectSinceStartDate,
netPerformanceInPercentage: netPerformanceInPercentage:
timeWeightedInvestmentValue === 0 timeWeightedInvestmentValue > 0
? 0 ? netPerformanceSinceStartDate / timeWeightedInvestmentValue
: netPerformanceSinceStartDate / timeWeightedInvestmentValue, : 0,
netPerformanceInPercentageWithCurrencyEffect: netPerformanceInPercentageWithCurrencyEffect:
timeWeightedInvestmentValue === 0 timeWeightedInvestmentValue > 0
? 0 ? netPerformanceWithCurrencyEffectSinceStartDate /
: netPerformanceWithCurrencyEffectSinceStartDate /
timeWeightedInvestmentValue timeWeightedInvestmentValue
: 0
}); });
} }
} }

Loading…
Cancel
Save