Browse Source

Merge 1c56d9a644 into d1351b4665

pull/4793/merge
bptrgx 1 week ago
committed by GitHub
parent
commit
4046c18c3d
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 34
      apps/api/src/app/portfolio/calculator/roai/portfolio-calculator.ts
  2. 5
      apps/api/src/app/portfolio/portfolio.service.ts
  3. 21
      apps/client/src/app/components/holding-detail-dialog/holding-detail-dialog.component.ts

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

@ -554,6 +554,16 @@ export class RoaiPortfolioCalculator extends PortfolioCalculator {
initialValueWithCurrencyEffect = initialValueWithCurrencyEffect =
transactionInvestmentWithCurrencyEffect; transactionInvestmentWithCurrencyEffect;
} else if (
order.quantity.gt(0) &&
['BUY', 'SELL'].includes(order.type) &&
!order.itemType
) {
initialValue = order.quantity.mul(marketPriceInBaseCurrency);
initialValueWithCurrencyEffect = order.quantity.mul(
marketPriceInBaseCurrencyWithCurrencyEffect
);
} }
} }
@ -783,7 +793,9 @@ export class RoaiPortfolioCalculator extends PortfolioCalculator {
? totalGrossPerformance.div( ? totalGrossPerformance.div(
timeWeightedAverageInvestmentBetweenStartAndEndDate timeWeightedAverageInvestmentBetweenStartAndEndDate
) )
: new Big(0); : totalGrossPerformance
? new Big(1)
: new Big(0);
const grossPerformancePercentageWithCurrencyEffect = const grossPerformancePercentageWithCurrencyEffect =
timeWeightedAverageInvestmentBetweenStartAndEndDateWithCurrencyEffect.gt( timeWeightedAverageInvestmentBetweenStartAndEndDateWithCurrencyEffect.gt(
@ -792,7 +804,9 @@ export class RoaiPortfolioCalculator extends PortfolioCalculator {
? totalGrossPerformanceWithCurrencyEffect.div( ? totalGrossPerformanceWithCurrencyEffect.div(
timeWeightedAverageInvestmentBetweenStartAndEndDateWithCurrencyEffect timeWeightedAverageInvestmentBetweenStartAndEndDateWithCurrencyEffect
) )
: new Big(0); : totalGrossPerformanceWithCurrencyEffect
? new Big(1)
: new Big(0);
const feesPerUnit = totalUnits.gt(0) const feesPerUnit = totalUnits.gt(0)
? fees.minus(feesAtStartDate).div(totalUnits) ? fees.minus(feesAtStartDate).div(totalUnits)
@ -809,7 +823,9 @@ export class RoaiPortfolioCalculator extends PortfolioCalculator {
? totalNetPerformance.div( ? totalNetPerformance.div(
timeWeightedAverageInvestmentBetweenStartAndEndDate timeWeightedAverageInvestmentBetweenStartAndEndDate
) )
: new Big(0); : totalNetPerformance
? new Big(1)
: new Big(0);
const netPerformancePercentageWithCurrencyEffectMap: { const netPerformancePercentageWithCurrencyEffectMap: {
[key: DateRange]: Big; [key: DateRange]: Big;
@ -902,7 +918,9 @@ export class RoaiPortfolioCalculator extends PortfolioCalculator {
netPerformancePercentageWithCurrencyEffectMap[dateRange] = average.gt(0) netPerformancePercentageWithCurrencyEffectMap[dateRange] = average.gt(0)
? netPerformanceWithCurrencyEffectMap[dateRange].div(average) ? netPerformanceWithCurrencyEffectMap[dateRange].div(average)
: new Big(0); : netPerformanceWithCurrencyEffectMap[dateRange]
? new Big(1)
: new Big(0);
} }
if (PortfolioCalculator.ENABLE_LOGGING) { if (PortfolioCalculator.ENABLE_LOGGING) {
@ -938,9 +956,11 @@ export class RoaiPortfolioCalculator extends PortfolioCalculator {
Net performance: ${totalNetPerformance.toFixed( Net performance: ${totalNetPerformance.toFixed(
2 2
)} / ${netPerformancePercentage.mul(100).toFixed(2)}% )} / ${netPerformancePercentage.mul(100).toFixed(2)}%
Net performance with currency effect: ${netPerformancePercentageWithCurrencyEffectMap[ Net performance with currency effect: ${netPerformanceValuesWithCurrencyEffect[
'max' endDateString
].toFixed(2)}%` ].toFixed(2)} / ${netPerformancePercentageWithCurrencyEffectMap['max']
.mul(100)
.toFixed(2)}%`
); );
} }

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

@ -798,10 +798,7 @@ export class PortfolioService {
historicalDataArray.push({ historicalDataArray.push({
date, date,
averagePrice: currentAveragePrice, averagePrice: currentAveragePrice,
marketPrice: marketPrice,
historicalDataArray.length > 0
? marketPrice
: currentAveragePrice,
quantity: currentQuantity quantity: currentQuantity
}); });

21
apps/client/src/app/components/holding-detail-dialog/holding-detail-dialog.component.ts

@ -275,11 +275,13 @@ export class GfHoldingDetailDialogComponent implements OnDestroy, OnInit {
SymbolProfile?.userId === this.user?.id; SymbolProfile?.userId === this.user?.id;
this.historicalDataItems = historicalData.map( this.historicalDataItems = historicalData.map(
({ averagePrice, date, marketPrice }) => { ({ averagePrice, date, marketPrice, quantity }) => {
this.benchmarkDataItems.push({ if (quantity) {
date, this.benchmarkDataItems.push({
value: averagePrice date,
}); value: averagePrice
});
}
return { return {
date, date,
@ -429,15 +431,6 @@ export class GfHoldingDetailDialogComponent implements OnDestroy, OnInit {
this.benchmarkDataItems[0].value = this.averagePrice; this.benchmarkDataItems[0].value = this.averagePrice;
} }
this.benchmarkDataItems = this.benchmarkDataItems.map(
({ date, value }) => {
return {
date,
value: value === 0 ? null : value
};
}
);
if (this.hasPermissionToReadMarketDataOfOwnAssetProfile) { if (this.hasPermissionToReadMarketDataOfOwnAssetProfile) {
this.fetchMarketData(); this.fetchMarketData();
} }

Loading…
Cancel
Save