Refactoring

pull/1640/head
Thomas 2 years ago committed by Thomas Kaul
parent 188389d26c
commit 5799b9e71c

@ -1269,9 +1269,7 @@ export class PortfolioCalculator {
}
const averageInvestmentBetweenStartAndEndDate = getAverage(
Object.values(investmentValues).map((investmentValue) => {
return investmentValue.toNumber();
})
Object.values(investmentValues)
);
const totalGrossPerformance = grossPerformance.minus(
@ -1286,7 +1284,7 @@ export class PortfolioCalculator {
averagePriceAtStartDate.eq(0) ||
averagePriceAtEndDate.eq(0) ||
orders[indexOfStartOrder].unitPrice.eq(0)
? averageInvestmentBetweenStartAndEndDate > 0
? averageInvestmentBetweenStartAndEndDate.gt(0)
? totalGrossPerformance.div(averageInvestmentBetweenStartAndEndDate)
: new Big(0)
: // This formula has the issue that buying more units with a price
@ -1307,7 +1305,7 @@ export class PortfolioCalculator {
averagePriceAtStartDate.eq(0) ||
averagePriceAtEndDate.eq(0) ||
orders[indexOfStartOrder].unitPrice.eq(0)
? averageInvestmentBetweenStartAndEndDate > 0
? averageInvestmentBetweenStartAndEndDate.gt(0)
? totalNetPerformance.div(averageInvestmentBetweenStartAndEndDate)
: new Big(0)
: // This formula has the issue that buying more units with a price

@ -133,8 +133,12 @@ export function getAssetProfileIdentifier({ dataSource, symbol }: UniqueAsset) {
return `${dataSource}-${symbol}`;
}
export function getAverage(aArray: number[]) {
return aArray.reduce((a, b) => a + b, 0) / aArray.length;
export function getAverage(aArray: Big[]) {
if (aArray?.length > 0) {
return aArray.reduce((a, b) => a.plus(b), new Big(0)).div(aArray.length);
}
return new Big(0);
}
export function getBackgroundColor(aColorScheme: ColorScheme) {

Loading…
Cancel
Save