|
@ -172,12 +172,12 @@ export class PortfolioCalculator { |
|
|
start: Date, |
|
|
start: Date, |
|
|
end = new Date(Date.now()) |
|
|
end = new Date(Date.now()) |
|
|
): Promise<CurrentPositions> { |
|
|
): Promise<CurrentPositions> { |
|
|
const transactionPointsUntilEndDate = |
|
|
const transactionPointsBeforeEndDate = |
|
|
this.transactionPoints?.filter((transactionPoint) => { |
|
|
this.transactionPoints?.filter((transactionPoint) => { |
|
|
return isBefore(parseDate(transactionPoint.date), end); |
|
|
return isBefore(parseDate(transactionPoint.date), end); |
|
|
}) ?? []; |
|
|
}) ?? []; |
|
|
|
|
|
|
|
|
if (!transactionPointsUntilEndDate.length) { |
|
|
if (!transactionPointsBeforeEndDate.length) { |
|
|
return { |
|
|
return { |
|
|
currentValue: new Big(0), |
|
|
currentValue: new Big(0), |
|
|
grossPerformance: new Big(0), |
|
|
grossPerformance: new Big(0), |
|
@ -191,33 +191,33 @@ export class PortfolioCalculator { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
const lastTransactionPoint = |
|
|
const lastTransactionPoint = |
|
|
transactionPointsUntilEndDate[transactionPointsUntilEndDate.length - 1]; |
|
|
transactionPointsBeforeEndDate[transactionPointsBeforeEndDate.length - 1]; |
|
|
|
|
|
|
|
|
let firstTransactionPoint: TransactionPoint = null; |
|
|
let firstTransactionPoint: TransactionPoint = null; |
|
|
let firstIndex = transactionPointsUntilEndDate.length; |
|
|
let firstIndex = transactionPointsBeforeEndDate.length; |
|
|
const dates = []; |
|
|
const dates = []; |
|
|
const dataGatheringItems: IDataGatheringItem[] = []; |
|
|
const dataGatheringItems: IDataGatheringItem[] = []; |
|
|
const currencies: { [symbol: string]: string } = {}; |
|
|
const currencies: { [symbol: string]: string } = {}; |
|
|
|
|
|
|
|
|
dates.push(resetHours(start)); |
|
|
dates.push(resetHours(start)); |
|
|
for (const item of transactionPointsUntilEndDate[firstIndex - 1].items) { |
|
|
for (const item of transactionPointsBeforeEndDate[firstIndex - 1].items) { |
|
|
dataGatheringItems.push({ |
|
|
dataGatheringItems.push({ |
|
|
dataSource: item.dataSource, |
|
|
dataSource: item.dataSource, |
|
|
symbol: item.symbol |
|
|
symbol: item.symbol |
|
|
}); |
|
|
}); |
|
|
currencies[item.symbol] = item.currency; |
|
|
currencies[item.symbol] = item.currency; |
|
|
} |
|
|
} |
|
|
for (let i = 0; i < transactionPointsUntilEndDate.length; i++) { |
|
|
for (let i = 0; i < transactionPointsBeforeEndDate.length; i++) { |
|
|
if ( |
|
|
if ( |
|
|
!isBefore(parseDate(transactionPointsUntilEndDate[i].date), start) && |
|
|
!isBefore(parseDate(transactionPointsBeforeEndDate[i].date), start) && |
|
|
firstTransactionPoint === null |
|
|
firstTransactionPoint === null |
|
|
) { |
|
|
) { |
|
|
firstTransactionPoint = transactionPointsUntilEndDate[i]; |
|
|
firstTransactionPoint = transactionPointsBeforeEndDate[i]; |
|
|
firstIndex = i; |
|
|
firstIndex = i; |
|
|
} |
|
|
} |
|
|
if (firstTransactionPoint !== null) { |
|
|
if (firstTransactionPoint !== null) { |
|
|
dates.push( |
|
|
dates.push( |
|
|
resetHours(parseDate(transactionPointsUntilEndDate[i].date)) |
|
|
resetHours(parseDate(transactionPointsBeforeEndDate[i].date)) |
|
|
); |
|
|
); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|