|
|
@ -142,6 +142,8 @@ export class TWRPortfolioCalculator extends PortfolioCalculator { |
|
|
|
let grossPerformanceAtStartDateWithCurrencyEffect = new Big(0); |
|
|
|
let grossPerformanceFromSells = new Big(0); |
|
|
|
let grossPerformanceFromSellsWithCurrencyEffect = new Big(0); |
|
|
|
let grossPerformanceFromDividends = new Big(0); |
|
|
|
let grossPerformanceFromDividendsWithCurrencyEffect = new Big(0); |
|
|
|
let initialValue: Big; |
|
|
|
let initialValueWithCurrencyEffect: Big; |
|
|
|
let investmentAtStartDate: Big; |
|
|
@ -559,28 +561,27 @@ export class TWRPortfolioCalculator extends PortfolioCalculator { |
|
|
|
order.unitPriceInBaseCurrencyWithCurrencyEffect |
|
|
|
); |
|
|
|
|
|
|
|
const grossPerformanceFromSell = |
|
|
|
order.type === 'SELL' |
|
|
|
? order.unitPriceInBaseCurrency |
|
|
|
.minus(lastAveragePrice) |
|
|
|
.mul(order.quantity) |
|
|
|
: new Big(0); |
|
|
|
|
|
|
|
const grossPerformanceFromSellWithCurrencyEffect = |
|
|
|
order.type === 'SELL' |
|
|
|
? order.unitPriceInBaseCurrencyWithCurrencyEffect |
|
|
|
.minus(lastAveragePriceWithCurrencyEffect) |
|
|
|
.mul(order.quantity) |
|
|
|
: new Big(0); |
|
|
|
|
|
|
|
grossPerformanceFromSells = grossPerformanceFromSells.plus( |
|
|
|
grossPerformanceFromSell |
|
|
|
); |
|
|
|
|
|
|
|
grossPerformanceFromSellsWithCurrencyEffect = |
|
|
|
grossPerformanceFromSellsWithCurrencyEffect.plus( |
|
|
|
grossPerformanceFromSellWithCurrencyEffect |
|
|
|
); |
|
|
|
({ |
|
|
|
grossPerformanceFromSells, |
|
|
|
grossPerformanceFromSellsWithCurrencyEffect |
|
|
|
} = this.handleSellOrder( |
|
|
|
order, |
|
|
|
lastAveragePrice, |
|
|
|
lastAveragePriceWithCurrencyEffect, |
|
|
|
grossPerformanceFromSells, |
|
|
|
grossPerformanceFromSellsWithCurrencyEffect |
|
|
|
)); |
|
|
|
|
|
|
|
({ |
|
|
|
grossPerformanceFromDividends, |
|
|
|
grossPerformanceFromDividendsWithCurrencyEffect |
|
|
|
} = this.handleDividend( |
|
|
|
order, |
|
|
|
grossPerformanceFromDividends, |
|
|
|
grossPerformanceFromDividendsWithCurrencyEffect, |
|
|
|
currentExchangeRate, |
|
|
|
exchangeRateAtOrderDate |
|
|
|
)); |
|
|
|
|
|
|
|
lastAveragePrice = totalQuantityFromBuyTransactions.eq(0) |
|
|
|
? new Big(0) |
|
|
@ -602,19 +603,21 @@ export class TWRPortfolioCalculator extends PortfolioCalculator { |
|
|
|
grossPerformanceFromSells.toNumber() |
|
|
|
); |
|
|
|
console.log( |
|
|
|
'grossPerformanceFromSellWithCurrencyEffect', |
|
|
|
grossPerformanceFromSellWithCurrencyEffect.toNumber() |
|
|
|
'grossPerformanceFromSellsWithCurrencyEffect', |
|
|
|
grossPerformanceFromSellsWithCurrencyEffect.toNumber() |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
const newGrossPerformance = valueOfInvestment |
|
|
|
.minus(totalInvestment) |
|
|
|
.plus(grossPerformanceFromSells); |
|
|
|
.plus(grossPerformanceFromSells) |
|
|
|
.plus(grossPerformanceFromDividends); |
|
|
|
|
|
|
|
const newGrossPerformanceWithCurrencyEffect = |
|
|
|
valueOfInvestmentWithCurrencyEffect |
|
|
|
.minus(totalInvestmentWithCurrencyEffect) |
|
|
|
.plus(grossPerformanceFromSellsWithCurrencyEffect); |
|
|
|
.plus(grossPerformanceFromSellsWithCurrencyEffect) |
|
|
|
.plus(grossPerformanceFromDividendsWithCurrencyEffect); |
|
|
|
|
|
|
|
grossPerformance = newGrossPerformance; |
|
|
|
|
|
|
@ -966,4 +969,67 @@ export class TWRPortfolioCalculator extends PortfolioCalculator { |
|
|
|
timeWeightedAverageInvestmentBetweenStartAndEndDateWithCurrencyEffect |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
private handleSellOrder( |
|
|
|
order: PortfolioOrderItem, |
|
|
|
lastAveragePrice, |
|
|
|
lastAveragePriceWithCurrencyEffect, |
|
|
|
grossPerformanceFromSells, |
|
|
|
grossPerformanceFromSellsWithCurrencyEffect |
|
|
|
) { |
|
|
|
if (order.type === 'SELL') { |
|
|
|
const grossPerformanceFromSell = order.unitPriceInBaseCurrency |
|
|
|
.minus(lastAveragePrice) |
|
|
|
.mul(order.quantity); |
|
|
|
|
|
|
|
const grossPerformanceFromSellWithCurrencyEffect = |
|
|
|
order.unitPriceInBaseCurrencyWithCurrencyEffect |
|
|
|
.minus(lastAveragePriceWithCurrencyEffect) |
|
|
|
.mul(order.quantity); |
|
|
|
|
|
|
|
grossPerformanceFromSells = grossPerformanceFromSells.plus( |
|
|
|
grossPerformanceFromSell |
|
|
|
); |
|
|
|
|
|
|
|
grossPerformanceFromSellsWithCurrencyEffect = |
|
|
|
grossPerformanceFromSellsWithCurrencyEffect.plus( |
|
|
|
grossPerformanceFromSellWithCurrencyEffect |
|
|
|
); |
|
|
|
} |
|
|
|
return { |
|
|
|
grossPerformanceFromSells, |
|
|
|
grossPerformanceFromSellsWithCurrencyEffect |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
private handleDividend( |
|
|
|
order: PortfolioOrderItem, |
|
|
|
grossPerformanceFromDividends, |
|
|
|
grossPerformanceFromDividendsWithCurrencyEffect, |
|
|
|
currentExchangeRate: number, |
|
|
|
exchangeRateAtDateOfOrder: number |
|
|
|
) { |
|
|
|
if (order.type === 'DIVIDEND') { |
|
|
|
const grossPerformanceFromDividend = order.unitPrice |
|
|
|
.mul(currentExchangeRate) |
|
|
|
.mul(order.quantity); |
|
|
|
|
|
|
|
const grossPerformanceFromDividendWithCurrencyEffect = order.unitPrice |
|
|
|
.mul(exchangeRateAtDateOfOrder) |
|
|
|
.mul(order.quantity); |
|
|
|
|
|
|
|
grossPerformanceFromDividends = grossPerformanceFromDividends.plus( |
|
|
|
grossPerformanceFromDividend |
|
|
|
); |
|
|
|
|
|
|
|
grossPerformanceFromDividendsWithCurrencyEffect = |
|
|
|
grossPerformanceFromDividendsWithCurrencyEffect.plus( |
|
|
|
grossPerformanceFromDividendWithCurrencyEffect |
|
|
|
); |
|
|
|
} |
|
|
|
return { |
|
|
|
grossPerformanceFromDividends, |
|
|
|
grossPerformanceFromDividendsWithCurrencyEffect |
|
|
|
}; |
|
|
|
} |
|
|
|
} |
|
|
|