Browse Source

add error handling to performance aggregation

pull/239/head
Valentin Zickner 4 years ago
committed by Thomas
parent
commit
b779964adb
  1. 9
      apps/api/src/app/portfolio/portfolio.service.ts

9
apps/api/src/app/portfolio/portfolio.service.ts

@ -468,24 +468,31 @@ export class PortfolioService {
let currentValue = new Big(0); let currentValue = new Big(0);
let grossPerformance = new Big(0); let grossPerformance = new Big(0);
let grossPerformancePercentage = new Big(1); let grossPerformancePercentage = new Big(1);
let hasErrors = false;
for (const currentPosition of currentPositions.positions) { for (const currentPosition of currentPositions.positions) {
currentValue = currentValue.add( currentValue = currentValue.add(
new Big(currentPosition.marketPrice).mul(currentPosition.quantity) new Big(currentPosition.marketPrice).mul(currentPosition.quantity)
); );
if (currentPosition.grossPerformance) {
hasErrors = true;
grossPerformance = grossPerformance.plus( grossPerformance = grossPerformance.plus(
currentPosition.grossPerformance currentPosition.grossPerformance
); );
}
if (currentPosition.grossPerformancePercentage) {
hasErrors = true;
grossPerformancePercentage = grossPerformancePercentage.mul( grossPerformancePercentage = grossPerformancePercentage.mul(
currentPosition.grossPerformancePercentage.plus(1) currentPosition.grossPerformancePercentage.plus(1)
); );
} }
}
const currentGrossPerformance = grossPerformance.toNumber(); const currentGrossPerformance = grossPerformance.toNumber();
const currentGrossPerformancePercent = grossPerformancePercentage const currentGrossPerformancePercent = grossPerformancePercentage
.minus(1) .minus(1)
.toNumber(); .toNumber();
return { return {
hasErrors: currentPositions.hasErrors, hasErrors: currentPositions.hasErrors || hasErrors,
performance: { performance: {
currentGrossPerformance, currentGrossPerformance,
currentGrossPerformancePercent, currentGrossPerformancePercent,

Loading…
Cancel
Save