Refactoring
This commit is contained in:
parent
188389d26c
commit
5799b9e71c
@ -1269,9 +1269,7 @@ export class PortfolioCalculator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const averageInvestmentBetweenStartAndEndDate = getAverage(
|
const averageInvestmentBetweenStartAndEndDate = getAverage(
|
||||||
Object.values(investmentValues).map((investmentValue) => {
|
Object.values(investmentValues)
|
||||||
return investmentValue.toNumber();
|
|
||||||
})
|
|
||||||
);
|
);
|
||||||
|
|
||||||
const totalGrossPerformance = grossPerformance.minus(
|
const totalGrossPerformance = grossPerformance.minus(
|
||||||
@ -1286,7 +1284,7 @@ export class PortfolioCalculator {
|
|||||||
averagePriceAtStartDate.eq(0) ||
|
averagePriceAtStartDate.eq(0) ||
|
||||||
averagePriceAtEndDate.eq(0) ||
|
averagePriceAtEndDate.eq(0) ||
|
||||||
orders[indexOfStartOrder].unitPrice.eq(0)
|
orders[indexOfStartOrder].unitPrice.eq(0)
|
||||||
? averageInvestmentBetweenStartAndEndDate > 0
|
? averageInvestmentBetweenStartAndEndDate.gt(0)
|
||||||
? totalGrossPerformance.div(averageInvestmentBetweenStartAndEndDate)
|
? totalGrossPerformance.div(averageInvestmentBetweenStartAndEndDate)
|
||||||
: new Big(0)
|
: new Big(0)
|
||||||
: // This formula has the issue that buying more units with a price
|
: // This formula has the issue that buying more units with a price
|
||||||
@ -1307,7 +1305,7 @@ export class PortfolioCalculator {
|
|||||||
averagePriceAtStartDate.eq(0) ||
|
averagePriceAtStartDate.eq(0) ||
|
||||||
averagePriceAtEndDate.eq(0) ||
|
averagePriceAtEndDate.eq(0) ||
|
||||||
orders[indexOfStartOrder].unitPrice.eq(0)
|
orders[indexOfStartOrder].unitPrice.eq(0)
|
||||||
? averageInvestmentBetweenStartAndEndDate > 0
|
? averageInvestmentBetweenStartAndEndDate.gt(0)
|
||||||
? totalNetPerformance.div(averageInvestmentBetweenStartAndEndDate)
|
? totalNetPerformance.div(averageInvestmentBetweenStartAndEndDate)
|
||||||
: new Big(0)
|
: new Big(0)
|
||||||
: // This formula has the issue that buying more units with a price
|
: // 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}`;
|
return `${dataSource}-${symbol}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getAverage(aArray: number[]) {
|
export function getAverage(aArray: Big[]) {
|
||||||
return aArray.reduce((a, b) => a + b, 0) / aArray.length;
|
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) {
|
export function getBackgroundColor(aColorScheme: ColorScheme) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user