Browse Source

Refactoring

pull/5130/head
Thomas Kaul 1 month ago
parent
commit
dbb64b0bbb
  1. 20
      apps/api/src/app/portfolio/calculator/roai/portfolio-calculator.ts

20
apps/api/src/app/portfolio/calculator/roai/portfolio-calculator.ts

@ -233,16 +233,17 @@ export class RoaiPortfolioCalculator extends PortfolioCalculator {
const unitPriceAtStartDate = marketSymbolMap[startDateString]?.[symbol]; const unitPriceAtStartDate = marketSymbolMap[startDateString]?.[symbol];
let unitPriceAtEndDate = marketSymbolMap[endDateString]?.[symbol]; let unitPriceAtEndDate = marketSymbolMap[endDateString]?.[symbol];
const lastOrder = orders.at(-1); let latestActivity = orders.at(-1);
if ( if (
!unitPriceAtEndDate &&
dataSource === 'MANUAL' && dataSource === 'MANUAL' &&
['BUY', 'SELL'].includes(lastOrder?.type) && ['BUY', 'SELL'].includes(latestActivity?.type) &&
lastOrder?.unitPrice latestActivity?.unitPrice &&
!unitPriceAtEndDate
) { ) {
// For BUY/SELL activities with a MANUAL data source where no historical market price is available, // For BUY / SELL activities with a MANUAL data source where no historical market price is available,
// the calculation should fall back to using the activity's unit price. // the calculation should fall back to using the activitys unit price.
unitPriceAtEndDate = lastOrder.unitPrice; unitPriceAtEndDate = latestActivity.unitPrice;
} }
if ( if (
@ -356,9 +357,10 @@ export class RoaiPortfolioCalculator extends PortfolioCalculator {
}); });
} }
const lastOrder = orders.at(-1); latestActivity = orders.at(-1);
lastUnitPrice = lastOrder.unitPriceFromMarketData ?? lastOrder.unitPrice; lastUnitPrice =
latestActivity.unitPriceFromMarketData ?? latestActivity.unitPrice;
} }
// 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

Loading…
Cancel
Save