Browse Source

Fix performance calculation

pull/750/head
Reto Kaul 3 years ago
parent
commit
f0c511e3e3
  1. 12
      apps/api/src/app/portfolio/portfolio-calculator-new.ts

12
apps/api/src/app/portfolio/portfolio-calculator-new.ts

@ -701,6 +701,7 @@ export class PortfolioCalculatorNew {
let totalInvestment = new Big(0); let totalInvestment = new Big(0);
let totalInvestmentWithGrossPerformanceFromSell = new Big(0); let totalInvestmentWithGrossPerformanceFromSell = new Big(0);
let totalUnits = new Big(0); let totalUnits = new Big(0);
let valueAtStartDate: Big;
// Add a synthetic order at the start and the end date // Add a synthetic order at the start and the end date
orders.push({ orders.push({
@ -774,14 +775,15 @@ export class PortfolioCalculatorNew {
averagePriceAtStartDate = totalInvestment.div(totalUnits); averagePriceAtStartDate = totalInvestment.div(totalUnits);
} }
if (!investmentAtStartDate && i >= indexOfStartOrder) {
investmentAtStartDate = totalInvestment ?? new Big(0);
}
const valueOfInvestmentBeforeTransaction = totalUnits.mul( const valueOfInvestmentBeforeTransaction = totalUnits.mul(
order.unitPrice order.unitPrice
); );
if (!investmentAtStartDate && i >= indexOfStartOrder) {
investmentAtStartDate = totalInvestment ?? new Big(0);
valueAtStartDate = valueOfInvestmentBeforeTransaction;
}
const transactionInvestment = order.quantity const transactionInvestment = order.quantity
.mul(order.unitPrice) .mul(order.unitPrice)
.mul(this.getFactor(order.type)); .mul(this.getFactor(order.type));
@ -906,7 +908,7 @@ export class PortfolioCalculatorNew {
.minus(grossPerformanceAtStartDate) .minus(grossPerformanceAtStartDate)
.minus(fees.minus(feesAtStartDate)); .minus(fees.minus(feesAtStartDate));
const maxInvestmentBetweenStartAndEndDate = initialValue.plus( const maxInvestmentBetweenStartAndEndDate = valueAtStartDate.plus(
maxTotalInvestment.minus(investmentAtStartDate) maxTotalInvestment.minus(investmentAtStartDate)
); );

Loading…
Cancel
Save