|  | @ -1,3 +1,4 @@ | 
			
		
	
		
		
			
				
					|  |  |  |  |  | import { getFactor } from '@ghostfolio/api/helper/portfolio.helper'; | 
			
		
	
		
		
			
				
					|  |  | import { ExchangeRateDataService } from '@ghostfolio/api/services/exchange-rate-data/exchange-rate-data.service'; |  |  | import { ExchangeRateDataService } from '@ghostfolio/api/services/exchange-rate-data/exchange-rate-data.service'; | 
			
		
	
		
		
			
				
					|  |  | import { IDataGatheringItem } from '@ghostfolio/api/services/interfaces/interfaces'; |  |  | import { IDataGatheringItem } from '@ghostfolio/api/services/interfaces/interfaces'; | 
			
		
	
		
		
			
				
					|  |  | import { DATE_FORMAT, parseDate, resetHours } from '@ghostfolio/common/helper'; |  |  | import { DATE_FORMAT, parseDate, resetHours } from '@ghostfolio/common/helper'; | 
			
		
	
	
		
		
			
				
					|  | @ -12,7 +13,6 @@ import { | 
			
		
	
		
		
			
				
					|  |  | import { GroupBy } from '@ghostfolio/common/types'; |  |  | import { GroupBy } from '@ghostfolio/common/types'; | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  | import { Logger } from '@nestjs/common'; |  |  | import { Logger } from '@nestjs/common'; | 
			
		
	
		
		
			
				
					|  |  | import { Type as TypeOfOrder } from '@prisma/client'; |  |  |  | 
			
		
	
		
		
			
				
					|  |  | import Big from 'big.js'; |  |  | import Big from 'big.js'; | 
			
		
	
		
		
			
				
					|  |  | import { |  |  | import { | 
			
		
	
		
		
			
				
					|  |  |   addDays, |  |  |   addDays, | 
			
		
	
	
		
		
			
				
					|  | @ -76,7 +76,7 @@ export class PortfolioCalculator { | 
			
		
	
		
		
			
				
					|  |  |       let currentTransactionPointItem: TransactionPointSymbol; |  |  |       let currentTransactionPointItem: TransactionPointSymbol; | 
			
		
	
		
		
			
				
					|  |  |       const oldAccumulatedSymbol = symbols[order.symbol]; |  |  |       const oldAccumulatedSymbol = symbols[order.symbol]; | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |       const factor = this.getFactor(order.type); |  |  |       const factor = getFactor(order.type); | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					|  |  |       const unitPrice = new Big(order.unitPrice); |  |  |       const unitPrice = new Big(order.unitPrice); | 
			
		
	
		
		
			
				
					|  |  |       if (oldAccumulatedSymbol) { |  |  |       if (oldAccumulatedSymbol) { | 
			
		
	
		
		
			
				
					|  |  |         const newQuantity = order.quantity |  |  |         const newQuantity = order.quantity | 
			
		
	
	
		
		
			
				
					|  | @ -820,25 +820,6 @@ export class PortfolioCalculator { | 
			
		
	
		
		
			
				
					|  |  |     }; |  |  |     }; | 
			
		
	
		
		
			
				
					|  |  |   } |  |  |   } | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |   private getFactor(type: TypeOfOrder) { |  |  |  | 
			
		
	
		
		
			
				
					|  |  |     let factor: number; |  |  |  | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  |  | 
			
		
	
		
		
			
				
					|  |  |     switch (type) { |  |  |  | 
			
		
	
		
		
			
				
					|  |  |       case 'BUY': |  |  |  | 
			
		
	
		
		
			
				
					|  |  |       case 'ITEM': |  |  |  | 
			
		
	
		
		
			
				
					|  |  |         factor = 1; |  |  |  | 
			
		
	
		
		
			
				
					|  |  |         break; |  |  |  | 
			
		
	
		
		
			
				
					|  |  |       case 'SELL': |  |  |  | 
			
		
	
		
		
			
				
					|  |  |         factor = -1; |  |  |  | 
			
		
	
		
		
			
				
					|  |  |         break; |  |  |  | 
			
		
	
		
		
			
				
					|  |  |       default: |  |  |  | 
			
		
	
		
		
			
				
					|  |  |         factor = 0; |  |  |  | 
			
		
	
		
		
			
				
					|  |  |         break; |  |  |  | 
			
		
	
		
		
			
				
					|  |  |     } |  |  |  | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  |  | 
			
		
	
		
		
			
				
					|  |  |     return factor; |  |  |  | 
			
		
	
		
		
			
				
					|  |  |   } |  |  |  | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  |  | 
			
		
	
		
		
			
				
					|  |  |   private getSymbolMetrics({ |  |  |   private getSymbolMetrics({ | 
			
		
	
		
		
			
				
					|  |  |     end, |  |  |     end, | 
			
		
	
		
		
			
				
					|  |  |     exchangeRates, |  |  |     exchangeRates, | 
			
		
	
	
		
		
			
				
					|  | @ -989,7 +970,7 @@ export class PortfolioCalculator { | 
			
		
	
		
		
			
				
					|  |  |       itemType: 'start', |  |  |       itemType: 'start', | 
			
		
	
		
		
			
				
					|  |  |       name: '', |  |  |       name: '', | 
			
		
	
		
		
			
				
					|  |  |       quantity: new Big(0), |  |  |       quantity: new Big(0), | 
			
		
	
		
		
			
				
					
					|  |  |       type: TypeOfOrder.BUY, |  |  |       type: 'BUY', | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					|  |  |       unitPrice: unitPriceAtStartDate |  |  |       unitPrice: unitPriceAtStartDate | 
			
		
	
		
		
			
				
					|  |  |     }); |  |  |     }); | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
	
		
		
			
				
					|  | @ -1003,7 +984,7 @@ export class PortfolioCalculator { | 
			
		
	
		
		
			
				
					|  |  |       itemType: 'end', |  |  |       itemType: 'end', | 
			
		
	
		
		
			
				
					|  |  |       name: '', |  |  |       name: '', | 
			
		
	
		
		
			
				
					|  |  |       quantity: new Big(0), |  |  |       quantity: new Big(0), | 
			
		
	
		
		
			
				
					
					|  |  |       type: TypeOfOrder.BUY, |  |  |       type: 'BUY', | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					|  |  |       unitPrice: unitPriceAtEndDate |  |  |       unitPrice: unitPriceAtEndDate | 
			
		
	
		
		
			
				
					|  |  |     }); |  |  |     }); | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
	
		
		
			
				
					|  | @ -1030,7 +1011,7 @@ export class PortfolioCalculator { | 
			
		
	
		
		
			
				
					|  |  |             feeInBaseCurrency: new Big(0), |  |  |             feeInBaseCurrency: new Big(0), | 
			
		
	
		
		
			
				
					|  |  |             name: '', |  |  |             name: '', | 
			
		
	
		
		
			
				
					|  |  |             quantity: new Big(0), |  |  |             quantity: new Big(0), | 
			
		
	
		
		
			
				
					
					|  |  |             type: TypeOfOrder.BUY, |  |  |             type: 'BUY', | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					|  |  |             unitPrice: |  |  |             unitPrice: | 
			
		
	
		
		
			
				
					|  |  |               marketSymbolMap[format(day, DATE_FORMAT)]?.[symbol] ?? |  |  |               marketSymbolMap[format(day, DATE_FORMAT)]?.[symbol] ?? | 
			
		
	
		
		
			
				
					|  |  |               lastUnitPrice |  |  |               lastUnitPrice | 
			
		
	
	
		
		
			
				
					|  | @ -1131,24 +1112,24 @@ export class PortfolioCalculator { | 
			
		
	
		
		
			
				
					|  |  |         order.type === 'BUY' |  |  |         order.type === 'BUY' | 
			
		
	
		
		
			
				
					|  |  |           ? order.quantity |  |  |           ? order.quantity | 
			
		
	
		
		
			
				
					|  |  |               .mul(order.unitPriceInBaseCurrency) |  |  |               .mul(order.unitPriceInBaseCurrency) | 
			
		
	
		
		
			
				
					
					|  |  |               .mul(this.getFactor(order.type)) |  |  |               .mul(getFactor(order.type)) | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					|  |  |           : totalUnits.gt(0) |  |  |           : totalUnits.gt(0) | 
			
		
	
		
		
			
				
					|  |  |             ? totalInvestment |  |  |             ? totalInvestment | 
			
		
	
		
		
			
				
					|  |  |                 .div(totalUnits) |  |  |                 .div(totalUnits) | 
			
		
	
		
		
			
				
					|  |  |                 .mul(order.quantity) |  |  |                 .mul(order.quantity) | 
			
		
	
		
		
			
				
					
					|  |  |                 .mul(this.getFactor(order.type)) |  |  |                 .mul(getFactor(order.type)) | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					|  |  |             : new Big(0); |  |  |             : new Big(0); | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |       const transactionInvestmentWithCurrencyEffect = |  |  |       const transactionInvestmentWithCurrencyEffect = | 
			
		
	
		
		
			
				
					|  |  |         order.type === 'BUY' |  |  |         order.type === 'BUY' | 
			
		
	
		
		
			
				
					|  |  |           ? order.quantity |  |  |           ? order.quantity | 
			
		
	
		
		
			
				
					|  |  |               .mul(order.unitPriceInBaseCurrencyWithCurrencyEffect) |  |  |               .mul(order.unitPriceInBaseCurrencyWithCurrencyEffect) | 
			
		
	
		
		
			
				
					
					|  |  |               .mul(this.getFactor(order.type)) |  |  |               .mul(getFactor(order.type)) | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					|  |  |           : totalUnits.gt(0) |  |  |           : totalUnits.gt(0) | 
			
		
	
		
		
			
				
					|  |  |             ? totalInvestmentWithCurrencyEffect |  |  |             ? totalInvestmentWithCurrencyEffect | 
			
		
	
		
		
			
				
					|  |  |                 .div(totalUnits) |  |  |                 .div(totalUnits) | 
			
		
	
		
		
			
				
					|  |  |                 .mul(order.quantity) |  |  |                 .mul(order.quantity) | 
			
		
	
		
		
			
				
					
					|  |  |                 .mul(this.getFactor(order.type)) |  |  |                 .mul(getFactor(order.type)) | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					|  |  |             : new Big(0); |  |  |             : new Big(0); | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |       if (PortfolioCalculator.ENABLE_LOGGING) { |  |  |       if (PortfolioCalculator.ENABLE_LOGGING) { | 
			
		
	
	
		
		
			
				
					|  | @ -1203,9 +1184,7 @@ export class PortfolioCalculator { | 
			
		
	
		
		
			
				
					|  |  |         order.feeInBaseCurrencyWithCurrencyEffect ?? 0 |  |  |         order.feeInBaseCurrencyWithCurrencyEffect ?? 0 | 
			
		
	
		
		
			
				
					|  |  |       ); |  |  |       ); | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |       totalUnits = totalUnits.plus( |  |  |       totalUnits = totalUnits.plus(order.quantity.mul(getFactor(order.type))); | 
			
				
				
			
		
	
		
		
			
				
					|  |  |         order.quantity.mul(this.getFactor(order.type)) |  |  |  | 
			
		
	
		
		
			
				
					|  |  |       ); |  |  |  | 
			
		
	
		
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |       const valueOfInvestment = totalUnits.mul(order.unitPriceInBaseCurrency); |  |  |       const valueOfInvestment = totalUnits.mul(order.unitPriceInBaseCurrency); | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
	
		
		
			
				
					|  | @ -1214,14 +1193,14 @@ export class PortfolioCalculator { | 
			
		
	
		
		
			
				
					|  |  |       ); |  |  |       ); | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |       const grossPerformanceFromSell = |  |  |       const grossPerformanceFromSell = | 
			
		
	
		
		
			
				
					
					|  |  |         order.type === TypeOfOrder.SELL |  |  |         order.type === 'SELL' | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					|  |  |           ? order.unitPriceInBaseCurrency |  |  |           ? order.unitPriceInBaseCurrency | 
			
		
	
		
		
			
				
					|  |  |               .minus(lastAveragePrice) |  |  |               .minus(lastAveragePrice) | 
			
		
	
		
		
			
				
					|  |  |               .mul(order.quantity) |  |  |               .mul(order.quantity) | 
			
		
	
		
		
			
				
					|  |  |           : new Big(0); |  |  |           : new Big(0); | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |       const grossPerformanceFromSellWithCurrencyEffect = |  |  |       const grossPerformanceFromSellWithCurrencyEffect = | 
			
		
	
		
		
			
				
					
					|  |  |         order.type === TypeOfOrder.SELL |  |  |         order.type === 'SELL' | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					|  |  |           ? order.unitPriceInBaseCurrencyWithCurrencyEffect |  |  |           ? order.unitPriceInBaseCurrencyWithCurrencyEffect | 
			
		
	
		
		
			
				
					|  |  |               .minus(lastAveragePriceWithCurrencyEffect) |  |  |               .minus(lastAveragePriceWithCurrencyEffect) | 
			
		
	
		
		
			
				
					|  |  |               .mul(order.quantity) |  |  |               .mul(order.quantity) | 
			
		
	
	
		
		
			
				
					|  | 
 |