|
|
@ -803,6 +803,29 @@ export class PortfolioCalculator { |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
public getInvestmentsByGroup({ |
|
|
|
data, |
|
|
|
groupBy |
|
|
|
}: { |
|
|
|
data: HistoricalDataItem[]; |
|
|
|
groupBy: GroupBy; |
|
|
|
}): InvestmentItem[] { |
|
|
|
const groupedData: { [dateGroup: string]: Big } = {}; |
|
|
|
|
|
|
|
for (const { date, investmentValueWithCurrencyEffect } of data) { |
|
|
|
const dateGroup = |
|
|
|
groupBy === 'month' ? date.substring(0, 7) : date.substring(0, 4); |
|
|
|
groupedData[dateGroup] = (groupedData[dateGroup] ?? new Big(0)).plus( |
|
|
|
investmentValueWithCurrencyEffect |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
return Object.keys(groupedData).map((dateGroup) => ({ |
|
|
|
date: groupBy === 'month' ? `${dateGroup}-01` : `${dateGroup}-01-01`, |
|
|
|
investment: groupedData[dateGroup].toNumber() |
|
|
|
})); |
|
|
|
} |
|
|
|
|
|
|
|
private calculateOverallPerformance(positions: TimelinePosition[]) { |
|
|
|
let currentValue = new Big(0); |
|
|
|
let grossPerformance = new Big(0); |
|
|
|