|
@ -456,12 +456,19 @@ export class RoaiPortfolioCalculator extends PortfolioCalculator { |
|
|
); |
|
|
); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const marketPriceInBaseCurrency = |
|
|
|
|
|
order.unitPriceFromMarketData?.mul(currentExchangeRate ?? 1) ?? |
|
|
|
|
|
new Big(0); |
|
|
|
|
|
const marketPriceInBaseCurrencyWithCurrencyEffect = |
|
|
|
|
|
order.unitPriceFromMarketData?.mul(exchangeRateAtOrderDate ?? 1) ?? |
|
|
|
|
|
new Big(0); |
|
|
|
|
|
|
|
|
const valueOfInvestmentBeforeTransaction = totalUnits.mul( |
|
|
const valueOfInvestmentBeforeTransaction = totalUnits.mul( |
|
|
order.unitPriceInBaseCurrency |
|
|
marketPriceInBaseCurrency |
|
|
); |
|
|
); |
|
|
|
|
|
|
|
|
const valueOfInvestmentBeforeTransactionWithCurrencyEffect = |
|
|
const valueOfInvestmentBeforeTransactionWithCurrencyEffect = |
|
|
totalUnits.mul(order.unitPriceInBaseCurrencyWithCurrencyEffect); |
|
|
totalUnits.mul(marketPriceInBaseCurrencyWithCurrencyEffect); |
|
|
|
|
|
|
|
|
if (!investmentAtStartDate && i >= indexOfStartOrder) { |
|
|
if (!investmentAtStartDate && i >= indexOfStartOrder) { |
|
|
investmentAtStartDate = totalInvestment ?? new Big(0); |
|
|
investmentAtStartDate = totalInvestment ?? new Big(0); |
|
@ -558,10 +565,10 @@ export class RoaiPortfolioCalculator extends PortfolioCalculator { |
|
|
|
|
|
|
|
|
totalUnits = totalUnits.plus(order.quantity.mul(getFactor(order.type))); |
|
|
totalUnits = totalUnits.plus(order.quantity.mul(getFactor(order.type))); |
|
|
|
|
|
|
|
|
const valueOfInvestment = totalUnits.mul(order.unitPriceInBaseCurrency); |
|
|
const valueOfInvestment = totalUnits.mul(marketPriceInBaseCurrency); |
|
|
|
|
|
|
|
|
const valueOfInvestmentWithCurrencyEffect = totalUnits.mul( |
|
|
const valueOfInvestmentWithCurrencyEffect = totalUnits.mul( |
|
|
order.unitPriceInBaseCurrencyWithCurrencyEffect |
|
|
marketPriceInBaseCurrencyWithCurrencyEffect |
|
|
); |
|
|
); |
|
|
|
|
|
|
|
|
const grossPerformanceFromSell = |
|
|
const grossPerformanceFromSell = |
|
@ -701,17 +708,23 @@ export class RoaiPortfolioCalculator extends PortfolioCalculator { |
|
|
investmentValuesWithCurrencyEffect[order.date] ?? new Big(0) |
|
|
investmentValuesWithCurrencyEffect[order.date] ?? new Big(0) |
|
|
).add(transactionInvestmentWithCurrencyEffect); |
|
|
).add(transactionInvestmentWithCurrencyEffect); |
|
|
|
|
|
|
|
|
|
|
|
// If duration is effectively zero (first day), use the actual investment as the base.
|
|
|
|
|
|
// Otherwise, use the calculated time-weighted average.
|
|
|
timeWeightedInvestmentValues[order.date] = |
|
|
timeWeightedInvestmentValues[order.date] = |
|
|
totalInvestmentDays > 0 |
|
|
totalInvestmentDays > Number.EPSILON |
|
|
? sumOfTimeWeightedInvestments.div(totalInvestmentDays) |
|
|
? sumOfTimeWeightedInvestments.div(totalInvestmentDays) |
|
|
: new Big(0); |
|
|
: totalInvestment.gt(0) |
|
|
|
|
|
? totalInvestment |
|
|
|
|
|
: new Big(0); |
|
|
|
|
|
|
|
|
timeWeightedInvestmentValuesWithCurrencyEffect[order.date] = |
|
|
timeWeightedInvestmentValuesWithCurrencyEffect[order.date] = |
|
|
totalInvestmentDays > 0 |
|
|
totalInvestmentDays > Number.EPSILON |
|
|
? sumOfTimeWeightedInvestmentsWithCurrencyEffect.div( |
|
|
? sumOfTimeWeightedInvestmentsWithCurrencyEffect.div( |
|
|
totalInvestmentDays |
|
|
totalInvestmentDays |
|
|
) |
|
|
) |
|
|
: new Big(0); |
|
|
: totalInvestmentWithCurrencyEffect.gt(0) |
|
|
|
|
|
? totalInvestmentWithCurrencyEffect |
|
|
|
|
|
: new Big(0); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (PortfolioCalculator.ENABLE_LOGGING) { |
|
|
if (PortfolioCalculator.ENABLE_LOGGING) { |
|
|