|
@ -31,7 +31,6 @@ export class TWRPortfolioCalculator extends PortfolioCalculator { |
|
|
let grossPerformanceWithCurrencyEffect = new Big(0); |
|
|
let grossPerformanceWithCurrencyEffect = new Big(0); |
|
|
let hasErrors = false; |
|
|
let hasErrors = false; |
|
|
let netPerformance = new Big(0); |
|
|
let netPerformance = new Big(0); |
|
|
let netPerformanceWithCurrencyEffect = new Big(0); |
|
|
|
|
|
let totalFeesWithCurrencyEffect = new Big(0); |
|
|
let totalFeesWithCurrencyEffect = new Big(0); |
|
|
let totalInterestWithCurrencyEffect = new Big(0); |
|
|
let totalInterestWithCurrencyEffect = new Big(0); |
|
|
let totalInvestment = new Big(0); |
|
|
let totalInvestment = new Big(0); |
|
@ -76,11 +75,6 @@ export class TWRPortfolioCalculator extends PortfolioCalculator { |
|
|
); |
|
|
); |
|
|
|
|
|
|
|
|
netPerformance = netPerformance.plus(currentPosition.netPerformance); |
|
|
netPerformance = netPerformance.plus(currentPosition.netPerformance); |
|
|
|
|
|
|
|
|
netPerformanceWithCurrencyEffect = |
|
|
|
|
|
netPerformanceWithCurrencyEffect.plus( |
|
|
|
|
|
currentPosition.netPerformancePercentageWithCurrencyEffectMap['max'] |
|
|
|
|
|
); |
|
|
|
|
|
} else if (!currentPosition.quantity.eq(0)) { |
|
|
} else if (!currentPosition.quantity.eq(0)) { |
|
|
hasErrors = true; |
|
|
hasErrors = true; |
|
|
} |
|
|
} |
|
@ -123,7 +117,6 @@ export class TWRPortfolioCalculator extends PortfolioCalculator { |
|
|
dataSource, |
|
|
dataSource, |
|
|
end, |
|
|
end, |
|
|
exchangeRates, |
|
|
exchangeRates, |
|
|
isChartMode = false, |
|
|
|
|
|
marketSymbolMap, |
|
|
marketSymbolMap, |
|
|
start, |
|
|
start, |
|
|
symbol |
|
|
symbol |
|
@ -131,7 +124,6 @@ export class TWRPortfolioCalculator extends PortfolioCalculator { |
|
|
chartDateMap?: { [date: string]: boolean }; |
|
|
chartDateMap?: { [date: string]: boolean }; |
|
|
end: Date; |
|
|
end: Date; |
|
|
exchangeRates: { [dateString: string]: number }; |
|
|
exchangeRates: { [dateString: string]: number }; |
|
|
isChartMode?: boolean; |
|
|
|
|
|
marketSymbolMap: { |
|
|
marketSymbolMap: { |
|
|
[date: string]: { [symbol: string]: Big }; |
|
|
[date: string]: { [symbol: string]: Big }; |
|
|
}; |
|
|
}; |
|
@ -211,11 +203,9 @@ export class TWRPortfolioCalculator extends PortfolioCalculator { |
|
|
investmentValuesWithCurrencyEffect: {}, |
|
|
investmentValuesWithCurrencyEffect: {}, |
|
|
netPerformance: new Big(0), |
|
|
netPerformance: new Big(0), |
|
|
netPerformancePercentage: new Big(0), |
|
|
netPerformancePercentage: new Big(0), |
|
|
netPerformancePercentageWithCurrencyEffect: new Big(0), |
|
|
|
|
|
netPerformancePercentageWithCurrencyEffectMap: {}, |
|
|
netPerformancePercentageWithCurrencyEffectMap: {}, |
|
|
netPerformanceValues: {}, |
|
|
netPerformanceValues: {}, |
|
|
netPerformanceValuesWithCurrencyEffect: {}, |
|
|
netPerformanceValuesWithCurrencyEffect: {}, |
|
|
netPerformanceWithCurrencyEffect: new Big(0), |
|
|
|
|
|
netPerformanceWithCurrencyEffectMap: {}, |
|
|
netPerformanceWithCurrencyEffectMap: {}, |
|
|
timeWeightedInvestment: new Big(0), |
|
|
timeWeightedInvestment: new Big(0), |
|
|
timeWeightedInvestmentValues: {}, |
|
|
timeWeightedInvestmentValues: {}, |
|
@ -263,12 +253,10 @@ export class TWRPortfolioCalculator extends PortfolioCalculator { |
|
|
investmentValuesWithCurrencyEffect: {}, |
|
|
investmentValuesWithCurrencyEffect: {}, |
|
|
netPerformance: new Big(0), |
|
|
netPerformance: new Big(0), |
|
|
netPerformancePercentage: new Big(0), |
|
|
netPerformancePercentage: new Big(0), |
|
|
netPerformancePercentageWithCurrencyEffect: new Big(0), |
|
|
|
|
|
netPerformancePercentageWithCurrencyEffectMap: {}, |
|
|
netPerformancePercentageWithCurrencyEffectMap: {}, |
|
|
netPerformanceWithCurrencyEffectMap: {}, |
|
|
netPerformanceWithCurrencyEffectMap: {}, |
|
|
netPerformanceValues: {}, |
|
|
netPerformanceValues: {}, |
|
|
netPerformanceValuesWithCurrencyEffect: {}, |
|
|
netPerformanceValuesWithCurrencyEffect: {}, |
|
|
netPerformanceWithCurrencyEffect: new Big(0), |
|
|
|
|
|
timeWeightedInvestment: new Big(0), |
|
|
timeWeightedInvestment: new Big(0), |
|
|
timeWeightedInvestmentValues: {}, |
|
|
timeWeightedInvestmentValues: {}, |
|
|
timeWeightedInvestmentValuesWithCurrencyEffect: {}, |
|
|
timeWeightedInvestmentValuesWithCurrencyEffect: {}, |
|
@ -319,7 +307,6 @@ export class TWRPortfolioCalculator extends PortfolioCalculator { |
|
|
let day = start; |
|
|
let day = start; |
|
|
let lastUnitPrice: Big; |
|
|
let lastUnitPrice: Big; |
|
|
|
|
|
|
|
|
if (isChartMode) { |
|
|
|
|
|
const ordersByDate: { [date: string]: PortfolioOrderItem[] } = {}; |
|
|
const ordersByDate: { [date: string]: PortfolioOrderItem[] } = {}; |
|
|
|
|
|
|
|
|
for (const order of orders) { |
|
|
for (const order of orders) { |
|
@ -354,12 +341,10 @@ export class TWRPortfolioCalculator extends PortfolioCalculator { |
|
|
|
|
|
|
|
|
const lastOrder = last(orders); |
|
|
const lastOrder = last(orders); |
|
|
|
|
|
|
|
|
lastUnitPrice = |
|
|
lastUnitPrice = lastOrder.unitPriceFromMarketData ?? lastOrder.unitPrice; |
|
|
lastOrder.unitPriceFromMarketData ?? lastOrder.unitPrice; |
|
|
|
|
|
|
|
|
|
|
|
day = addDays(day, 1); |
|
|
day = addDays(day, 1); |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Sort orders so that the start and end placeholder order are at the correct
|
|
|
// Sort orders so that the start and end placeholder order are at the correct
|
|
|
// position
|
|
|
// position
|
|
@ -681,7 +666,6 @@ export class TWRPortfolioCalculator extends PortfolioCalculator { |
|
|
); |
|
|
); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (isChartMode) { |
|
|
|
|
|
currentValues[order.date] = valueOfInvestment; |
|
|
currentValues[order.date] = valueOfInvestment; |
|
|
|
|
|
|
|
|
currentValuesWithCurrencyEffect[order.date] = |
|
|
currentValuesWithCurrencyEffect[order.date] = |
|
@ -719,7 +703,6 @@ export class TWRPortfolioCalculator extends PortfolioCalculator { |
|
|
) |
|
|
) |
|
|
: new Big(0); |
|
|
: new Big(0); |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (PortfolioCalculator.ENABLE_LOGGING) { |
|
|
if (PortfolioCalculator.ENABLE_LOGGING) { |
|
|
console.log('totalInvestment', totalInvestment.toNumber()); |
|
|
console.log('totalInvestment', totalInvestment.toNumber()); |
|
@ -760,11 +743,6 @@ export class TWRPortfolioCalculator extends PortfolioCalculator { |
|
|
.minus(grossPerformanceAtStartDate) |
|
|
.minus(grossPerformanceAtStartDate) |
|
|
.minus(fees.minus(feesAtStartDate)); |
|
|
.minus(fees.minus(feesAtStartDate)); |
|
|
|
|
|
|
|
|
const totalNetPerformanceWithCurrencyEffect = |
|
|
|
|
|
grossPerformanceWithCurrencyEffect |
|
|
|
|
|
.minus(grossPerformanceAtStartDateWithCurrencyEffect) |
|
|
|
|
|
.minus(feesWithCurrencyEffect.minus(feesAtStartDateWithCurrencyEffect)); |
|
|
|
|
|
|
|
|
|
|
|
const timeWeightedAverageInvestmentBetweenStartAndEndDate = |
|
|
const timeWeightedAverageInvestmentBetweenStartAndEndDate = |
|
|
totalInvestmentDays > 0 |
|
|
totalInvestmentDays > 0 |
|
|
? sumOfTimeWeightedInvestments.div(totalInvestmentDays) |
|
|
? sumOfTimeWeightedInvestments.div(totalInvestmentDays) |
|
@ -810,15 +788,6 @@ export class TWRPortfolioCalculator extends PortfolioCalculator { |
|
|
) |
|
|
) |
|
|
: new Big(0); |
|
|
: new Big(0); |
|
|
|
|
|
|
|
|
const netPerformancePercentageWithCurrencyEffect = |
|
|
|
|
|
timeWeightedAverageInvestmentBetweenStartAndEndDateWithCurrencyEffect.gt( |
|
|
|
|
|
0 |
|
|
|
|
|
) |
|
|
|
|
|
? totalNetPerformanceWithCurrencyEffect.div( |
|
|
|
|
|
timeWeightedAverageInvestmentBetweenStartAndEndDateWithCurrencyEffect |
|
|
|
|
|
) |
|
|
|
|
|
: new Big(0); |
|
|
|
|
|
|
|
|
|
|
|
const netPerformancePercentageWithCurrencyEffectMap: { |
|
|
const netPerformancePercentageWithCurrencyEffectMap: { |
|
|
[key: DateRange]: Big; |
|
|
[key: DateRange]: Big; |
|
|
} = {}; |
|
|
} = {}; |
|
@ -946,9 +915,9 @@ export class TWRPortfolioCalculator extends PortfolioCalculator { |
|
|
Net performance: ${totalNetPerformance.toFixed( |
|
|
Net performance: ${totalNetPerformance.toFixed( |
|
|
2 |
|
|
2 |
|
|
)} / ${netPerformancePercentage.mul(100).toFixed(2)}% |
|
|
)} / ${netPerformancePercentage.mul(100).toFixed(2)}% |
|
|
Net performance with currency effect: ${totalNetPerformanceWithCurrencyEffect.toFixed( |
|
|
Net performance with currency effect: ${netPerformancePercentageWithCurrencyEffectMap[ |
|
|
2 |
|
|
'max' |
|
|
)} / ${netPerformancePercentageWithCurrencyEffect.mul(100).toFixed(2)}%` |
|
|
].toFixed(2)}%` |
|
|
); |
|
|
); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -964,7 +933,6 @@ export class TWRPortfolioCalculator extends PortfolioCalculator { |
|
|
investmentValuesAccumulatedWithCurrencyEffect, |
|
|
investmentValuesAccumulatedWithCurrencyEffect, |
|
|
investmentValuesWithCurrencyEffect, |
|
|
investmentValuesWithCurrencyEffect, |
|
|
netPerformancePercentage, |
|
|
netPerformancePercentage, |
|
|
netPerformancePercentageWithCurrencyEffect, |
|
|
|
|
|
netPerformancePercentageWithCurrencyEffectMap, |
|
|
netPerformancePercentageWithCurrencyEffectMap, |
|
|
netPerformanceValues, |
|
|
netPerformanceValues, |
|
|
netPerformanceValuesWithCurrencyEffect, |
|
|
netPerformanceValuesWithCurrencyEffect, |
|
@ -987,7 +955,6 @@ export class TWRPortfolioCalculator extends PortfolioCalculator { |
|
|
totalGrossPerformanceWithCurrencyEffect, |
|
|
totalGrossPerformanceWithCurrencyEffect, |
|
|
hasErrors: totalUnits.gt(0) && (!initialValue || !unitPriceAtEndDate), |
|
|
hasErrors: totalUnits.gt(0) && (!initialValue || !unitPriceAtEndDate), |
|
|
netPerformance: totalNetPerformance, |
|
|
netPerformance: totalNetPerformance, |
|
|
netPerformanceWithCurrencyEffect: totalNetPerformanceWithCurrencyEffect, |
|
|
|
|
|
timeWeightedInvestment: |
|
|
timeWeightedInvestment: |
|
|
timeWeightedAverageInvestmentBetweenStartAndEndDate, |
|
|
timeWeightedAverageInvestmentBetweenStartAndEndDate, |
|
|
timeWeightedInvestmentWithCurrencyEffect: |
|
|
timeWeightedInvestmentWithCurrencyEffect: |
|
|