|
@ -767,14 +767,19 @@ export class RoaiPortfolioCalculator extends PortfolioCalculator { |
|
|
) |
|
|
) |
|
|
: new Big(0); |
|
|
: new Big(0); |
|
|
|
|
|
|
|
|
const grossPerformancePercentage = totalInvestment.gt(0) |
|
|
const grossPerformancePercentage = |
|
|
? totalGrossPerformance.div(totalInvestment) |
|
|
timeWeightedAverageInvestmentBetweenStartAndEndDate.gt(0) |
|
|
|
|
|
? totalGrossPerformance.div( |
|
|
|
|
|
timeWeightedAverageInvestmentBetweenStartAndEndDate |
|
|
|
|
|
) |
|
|
: new Big(0); |
|
|
: new Big(0); |
|
|
|
|
|
|
|
|
const grossPerformancePercentageWithCurrencyEffect = |
|
|
const grossPerformancePercentageWithCurrencyEffect = |
|
|
totalInvestmentWithCurrencyEffect.gt(0) |
|
|
timeWeightedAverageInvestmentBetweenStartAndEndDateWithCurrencyEffect.gt( |
|
|
|
|
|
0 |
|
|
|
|
|
) |
|
|
? totalGrossPerformanceWithCurrencyEffect.div( |
|
|
? totalGrossPerformanceWithCurrencyEffect.div( |
|
|
totalInvestmentWithCurrencyEffect |
|
|
timeWeightedAverageInvestmentBetweenStartAndEndDateWithCurrencyEffect |
|
|
) |
|
|
) |
|
|
: new Big(0); |
|
|
: new Big(0); |
|
|
|
|
|
|
|
@ -788,8 +793,11 @@ export class RoaiPortfolioCalculator extends PortfolioCalculator { |
|
|
.div(totalUnits) |
|
|
.div(totalUnits) |
|
|
: new Big(0); |
|
|
: new Big(0); |
|
|
|
|
|
|
|
|
const netPerformancePercentage = totalInvestment.gt(0) |
|
|
const netPerformancePercentage = |
|
|
? totalNetPerformance.div(totalInvestment) |
|
|
timeWeightedAverageInvestmentBetweenStartAndEndDate.gt(0) |
|
|
|
|
|
? totalNetPerformance.div( |
|
|
|
|
|
timeWeightedAverageInvestmentBetweenStartAndEndDate |
|
|
|
|
|
) |
|
|
: new Big(0); |
|
|
: new Big(0); |
|
|
|
|
|
|
|
|
const netPerformancePercentageWithCurrencyEffectMap: { |
|
|
const netPerformancePercentageWithCurrencyEffectMap: { |
|
@ -802,9 +810,6 @@ export class RoaiPortfolioCalculator extends PortfolioCalculator { |
|
|
|
|
|
|
|
|
for (const dateRange of [ |
|
|
for (const dateRange of [ |
|
|
'1d', |
|
|
'1d', |
|
|
'1w', |
|
|
|
|
|
'1m', |
|
|
|
|
|
'3m', |
|
|
|
|
|
'1y', |
|
|
'1y', |
|
|
'5y', |
|
|
'5y', |
|
|
'max', |
|
|
'max', |
|
@ -831,6 +836,48 @@ export class RoaiPortfolioCalculator extends PortfolioCalculator { |
|
|
const rangeEndDateString = format(endDate, DATE_FORMAT); |
|
|
const rangeEndDateString = format(endDate, DATE_FORMAT); |
|
|
const rangeStartDateString = format(startDate, DATE_FORMAT); |
|
|
const rangeStartDateString = format(startDate, DATE_FORMAT); |
|
|
|
|
|
|
|
|
|
|
|
const currentValuesAtDateRangeStartWithCurrencyEffect = |
|
|
|
|
|
currentValuesWithCurrencyEffect[rangeStartDateString] ?? new Big(0); |
|
|
|
|
|
|
|
|
|
|
|
const investmentValuesAccumulatedAtStartDateWithCurrencyEffect = |
|
|
|
|
|
investmentValuesAccumulatedWithCurrencyEffect[rangeStartDateString] ?? |
|
|
|
|
|
new Big(0); |
|
|
|
|
|
|
|
|
|
|
|
const grossPerformanceAtDateRangeStartWithCurrencyEffect = |
|
|
|
|
|
currentValuesAtDateRangeStartWithCurrencyEffect.minus( |
|
|
|
|
|
investmentValuesAccumulatedAtStartDateWithCurrencyEffect |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
let average = new Big(0); |
|
|
|
|
|
let dayCount = 0; |
|
|
|
|
|
|
|
|
|
|
|
for (let i = this.chartDates.length - 1; i >= 0; i -= 1) { |
|
|
|
|
|
const date = this.chartDates[i]; |
|
|
|
|
|
|
|
|
|
|
|
if (date > rangeEndDateString) { |
|
|
|
|
|
continue; |
|
|
|
|
|
} else if (date < rangeStartDateString) { |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if ( |
|
|
|
|
|
investmentValuesAccumulatedWithCurrencyEffect[date] instanceof Big && |
|
|
|
|
|
investmentValuesAccumulatedWithCurrencyEffect[date].gt(0) |
|
|
|
|
|
) { |
|
|
|
|
|
average = average.add( |
|
|
|
|
|
investmentValuesAccumulatedWithCurrencyEffect[date].add( |
|
|
|
|
|
grossPerformanceAtDateRangeStartWithCurrencyEffect |
|
|
|
|
|
) |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
dayCount++; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (dayCount > 0) { |
|
|
|
|
|
average = average.div(dayCount); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
netPerformanceWithCurrencyEffectMap[dateRange] = |
|
|
netPerformanceWithCurrencyEffectMap[dateRange] = |
|
|
netPerformanceValuesWithCurrencyEffect[rangeEndDateString]?.minus( |
|
|
netPerformanceValuesWithCurrencyEffect[rangeEndDateString]?.minus( |
|
|
// If the date range is 'max', take 0 as a start value. Otherwise,
|
|
|
// If the date range is 'max', take 0 as a start value. Otherwise,
|
|
@ -842,11 +889,8 @@ export class RoaiPortfolioCalculator extends PortfolioCalculator { |
|
|
new Big(0)) |
|
|
new Big(0)) |
|
|
) ?? new Big(0); |
|
|
) ?? new Big(0); |
|
|
|
|
|
|
|
|
netPerformancePercentageWithCurrencyEffectMap[dateRange] = |
|
|
netPerformancePercentageWithCurrencyEffectMap[dateRange] = average.gt(0) |
|
|
investmentValuesAccumulatedWithCurrencyEffect[rangeEndDateString]?.gt(0) |
|
|
? netPerformanceWithCurrencyEffectMap[dateRange].div(average) |
|
|
? netPerformanceWithCurrencyEffectMap[dateRange].div( |
|
|
|
|
|
investmentValuesAccumulatedWithCurrencyEffect[rangeEndDateString] |
|
|
|
|
|
) |
|
|
|
|
|
: new Big(0); |
|
|
: new Big(0); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|