|  | @ -4,8 +4,6 @@ import { CashDetails } from '@ghostfolio/api/app/account/interfaces/cash-details | 
			
		
	
		
		
			
				
					|  |  | import { Activity } from '@ghostfolio/api/app/order/interfaces/activities.interface'; |  |  | import { Activity } from '@ghostfolio/api/app/order/interfaces/activities.interface'; | 
			
		
	
		
		
			
				
					|  |  | import { OrderService } from '@ghostfolio/api/app/order/order.service'; |  |  | import { OrderService } from '@ghostfolio/api/app/order/order.service'; | 
			
		
	
		
		
			
				
					|  |  | import { CurrentRateService } from '@ghostfolio/api/app/portfolio/current-rate.service'; |  |  | import { CurrentRateService } from '@ghostfolio/api/app/portfolio/current-rate.service'; | 
			
		
	
		
		
			
				
					|  |  | import { PortfolioOrder } from '@ghostfolio/api/app/portfolio/interfaces/portfolio-order.interface'; |  |  |  | 
			
		
	
		
		
			
				
					|  |  | import { TransactionPoint } from '@ghostfolio/api/app/portfolio/interfaces/transaction-point.interface'; |  |  |  | 
			
		
	
		
		
			
				
					|  |  | import { UserService } from '@ghostfolio/api/app/user/user.service'; |  |  | import { UserService } from '@ghostfolio/api/app/user/user.service'; | 
			
		
	
		
		
			
				
					|  |  | import { getFactor } from '@ghostfolio/api/helper/portfolio.helper'; |  |  | import { getFactor } from '@ghostfolio/api/helper/portfolio.helper'; | 
			
		
	
		
		
			
				
					|  |  | import { AccountClusterRiskCurrentInvestment } from '@ghostfolio/api/models/rules/account-cluster-risk/current-investment'; |  |  | import { AccountClusterRiskCurrentInvestment } from '@ghostfolio/api/models/rules/account-cluster-risk/current-investment'; | 
			
		
	
	
		
		
			
				
					|  | @ -266,15 +264,15 @@ export class PortfolioService { | 
			
		
	
		
		
			
				
					|  |  |   }): Promise<PortfolioInvestments> { |  |  |   }): Promise<PortfolioInvestments> { | 
			
		
	
		
		
			
				
					|  |  |     const userId = await this.getUserId(impersonationId, this.request.user.id); |  |  |     const userId = await this.getUserId(impersonationId, this.request.user.id); | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |     const { portfolioOrders, transactionPoints } = |  |  |     const { activities } = await this.orderService.getOrders({ | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |       await this.getTransactionPoints({ |  |  |       filters, | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |         filters, |  |  |       userId, | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |         userId, |  |  |       includeDrafts: true, | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |         includeDrafts: true, |  |  |       types: ['BUY', 'SELL'], | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |         types: ['BUY', 'SELL'] |  |  |       userCurrency: this.getUserCurrency() | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |       }); |  |  |     }); | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |     if (transactionPoints.length === 0) { |  |  |     if (activities.length === 0) { | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					|  |  |       return { |  |  |       return { | 
			
		
	
		
		
			
				
					|  |  |         investments: [], |  |  |         investments: [], | 
			
		
	
		
		
			
				
					|  |  |         streaks: { currentStreak: 0, longestStreak: 0 } |  |  |         streaks: { currentStreak: 0, longestStreak: 0 } | 
			
		
	
	
		
		
			
				
					|  | @ -282,18 +280,16 @@ export class PortfolioService { | 
			
		
	
		
		
			
				
					|  |  |     } |  |  |     } | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |     const portfolioCalculator = new PortfolioCalculator({ |  |  |     const portfolioCalculator = new PortfolioCalculator({ | 
			
		
	
		
		
			
				
					
					|  |  |       transactionPoints, |  |  |       activities, | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					|  |  |       currency: this.request.user.Settings.settings.baseCurrency, |  |  |       currency: this.request.user.Settings.settings.baseCurrency, | 
			
		
	
		
		
			
				
					|  |  |       currentRateService: this.currentRateService, |  |  |       currentRateService: this.currentRateService, | 
			
		
	
		
		
			
				
					
					|  |  |       exchangeRateDataService: this.exchangeRateDataService, |  |  |       exchangeRateDataService: this.exchangeRateDataService | 
			
				
				
			
		
	
		
		
			
				
					|  |  |       orders: portfolioOrders |  |  |  | 
			
		
	
		
		
	
		
		
			
				
					|  |  |     }); |  |  |     }); | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |     const { items } = await this.getChart({ |  |  |     const { items } = await this.getChart({ | 
			
		
	
		
		
			
				
					|  |  |       dateRange, |  |  |       dateRange, | 
			
		
	
		
		
			
				
					|  |  |       impersonationId, |  |  |       impersonationId, | 
			
		
	
		
		
			
				
					|  |  |       portfolioCalculator, |  |  |       portfolioCalculator, | 
			
		
	
		
		
			
				
					|  |  |       transactionPoints, |  |  |  | 
			
		
	
		
		
			
				
					|  |  |       userId, |  |  |       userId, | 
			
		
	
		
		
			
				
					|  |  |       withDataDecimation: false |  |  |       withDataDecimation: false | 
			
		
	
		
		
			
				
					|  |  |     }); |  |  |     }); | 
			
		
	
	
		
		
			
				
					|  | @ -364,26 +360,25 @@ export class PortfolioService { | 
			
		
	
		
		
			
				
					|  |  |       }); |  |  |       }); | 
			
		
	
		
		
			
				
					|  |  |     } |  |  |     } | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |     const { activities, portfolioOrders, transactionPoints } = |  |  |     const { activities } = await this.orderService.getOrders({ | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |       await this.getTransactionPoints({ |  |  |       filters, | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |         filters, |  |  |       types, | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |         types, |  |  |       userCurrency, | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |         userId, |  |  |       userId, | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |         withExcludedAccounts |  |  |       withExcludedAccounts | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |       }); |  |  |     }); | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |     const portfolioCalculator = new PortfolioCalculator({ |  |  |     const portfolioCalculator = new PortfolioCalculator({ | 
			
		
	
		
		
			
				
					
					|  |  |       transactionPoints, |  |  |       activities, | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					|  |  |       currency: userCurrency, |  |  |       currency: userCurrency, | 
			
		
	
		
		
			
				
					|  |  |       currentRateService: this.currentRateService, |  |  |       currentRateService: this.currentRateService, | 
			
		
	
		
		
			
				
					
					|  |  |       exchangeRateDataService: this.exchangeRateDataService, |  |  |       exchangeRateDataService: this.exchangeRateDataService | 
			
				
				
			
		
	
		
		
			
				
					|  |  |       orders: portfolioOrders |  |  |  | 
			
		
	
		
		
	
		
		
			
				
					|  |  |     }); |  |  |     }); | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |     const portfolioStart = parseDate( |  |  |     const startDate = this.getStartDate( | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |       transactionPoints[0]?.date ?? format(new Date(), DATE_FORMAT) |  |  |       dateRange, | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					|  |  |  |  |  |       portfolioCalculator.getStartDate() | 
			
		
	
		
		
			
				
					|  |  |     ); |  |  |     ); | 
			
		
	
		
		
			
				
					|  |  |     const startDate = this.getStartDate(dateRange, portfolioStart); |  |  |  | 
			
		
	
		
		
			
				
					|  |  |     const currentPositions = |  |  |     const currentPositions = | 
			
		
	
		
		
			
				
					|  |  |       await portfolioCalculator.getCurrentPositions(startDate); |  |  |       await portfolioCalculator.getCurrentPositions(startDate); | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
	
		
		
			
				
					|  | @ -737,39 +732,22 @@ export class PortfolioService { | 
			
		
	
		
		
			
				
					|  |  |       { dataSource: aDataSource, symbol: aSymbol } |  |  |       { dataSource: aDataSource, symbol: aSymbol } | 
			
		
	
		
		
			
				
					|  |  |     ]); |  |  |     ]); | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |     const portfolioOrders: PortfolioOrder[] = orders |  |  |  | 
			
		
	
		
		
			
				
					|  |  |       .filter((order) => { |  |  |  | 
			
		
	
		
		
			
				
					|  |  |         tags = tags.concat(order.tags); |  |  |  | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  |  | 
			
		
	
		
		
			
				
					|  |  |         return ['BUY', 'DIVIDEND', 'ITEM', 'SELL'].includes(order.type); |  |  |  | 
			
		
	
		
		
			
				
					|  |  |       }) |  |  |  | 
			
		
	
		
		
			
				
					|  |  |       .map((order) => ({ |  |  |  | 
			
		
	
		
		
			
				
					|  |  |         currency: order.SymbolProfile.currency, |  |  |  | 
			
		
	
		
		
			
				
					|  |  |         dataSource: order.SymbolProfile.dataSource, |  |  |  | 
			
		
	
		
		
			
				
					|  |  |         date: format(order.date, DATE_FORMAT), |  |  |  | 
			
		
	
		
		
			
				
					|  |  |         fee: new Big(order.fee), |  |  |  | 
			
		
	
		
		
			
				
					|  |  |         name: order.SymbolProfile?.name, |  |  |  | 
			
		
	
		
		
			
				
					|  |  |         quantity: new Big(order.quantity), |  |  |  | 
			
		
	
		
		
			
				
					|  |  |         symbol: order.SymbolProfile.symbol, |  |  |  | 
			
		
	
		
		
			
				
					|  |  |         tags: order.tags, |  |  |  | 
			
		
	
		
		
			
				
					|  |  |         type: order.type, |  |  |  | 
			
		
	
		
		
			
				
					|  |  |         unitPrice: new Big(order.unitPrice) |  |  |  | 
			
		
	
		
		
			
				
					|  |  |       })); |  |  |  | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  |  | 
			
		
	
		
		
			
				
					|  |  |     tags = uniqBy(tags, 'id'); |  |  |     tags = uniqBy(tags, 'id'); | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |     const portfolioCalculator = new PortfolioCalculator({ |  |  |     const portfolioCalculator = new PortfolioCalculator({ | 
			
		
	
		
		
			
				
					|  |  |  |  |  |       activities: orders.filter((order) => { | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         tags = tags.concat(order.tags); | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         return ['BUY', 'DIVIDEND', 'ITEM', 'SELL'].includes(order.type); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |       }), | 
			
		
	
		
		
			
				
					|  |  |       currency: userCurrency, |  |  |       currency: userCurrency, | 
			
		
	
		
		
			
				
					|  |  |       currentRateService: this.currentRateService, |  |  |       currentRateService: this.currentRateService, | 
			
		
	
		
		
			
				
					
					|  |  |       exchangeRateDataService: this.exchangeRateDataService, |  |  |       exchangeRateDataService: this.exchangeRateDataService | 
			
				
				
			
		
	
		
		
			
				
					|  |  |       orders: portfolioOrders |  |  |  | 
			
		
	
		
		
	
		
		
			
				
					|  |  |     }); |  |  |     }); | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |     portfolioCalculator.computeTransactionPoints(); |  |  |     const portfolioStart = portfolioCalculator.getStartDate(); | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					|  |  |     const transactionPoints = portfolioCalculator.getTransactionPoints(); |  |  |     const transactionPoints = portfolioCalculator.getTransactionPoints(); | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |     const portfolioStart = parseDate(transactionPoints[0].date); |  |  |  | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  |  | 
			
		
	
		
		
			
				
					|  |  |     const currentPositions = |  |  |     const currentPositions = | 
			
		
	
		
		
			
				
					|  |  |       await portfolioCalculator.getCurrentPositions(portfolioStart); |  |  |       await portfolioCalculator.getCurrentPositions(portfolioStart); | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
	
		
		
			
				
					|  | @ -982,14 +960,14 @@ export class PortfolioService { | 
			
		
	
		
		
			
				
					|  |  |     const userId = await this.getUserId(impersonationId, this.request.user.id); |  |  |     const userId = await this.getUserId(impersonationId, this.request.user.id); | 
			
		
	
		
		
			
				
					|  |  |     const user = await this.userService.user({ id: userId }); |  |  |     const user = await this.userService.user({ id: userId }); | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |     const { portfolioOrders, transactionPoints } = |  |  |     const { activities } = await this.orderService.getOrders({ | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |       await this.getTransactionPoints({ |  |  |       filters, | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |         filters, |  |  |       userId, | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |         userId, |  |  |       types: ['BUY', 'SELL'], | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |         types: ['BUY', 'SELL'] |  |  |       userCurrency: this.getUserCurrency() | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |       }); |  |  |     }); | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |     if (transactionPoints?.length <= 0) { |  |  |     if (activities?.length <= 0) { | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					|  |  |       return { |  |  |       return { | 
			
		
	
		
		
			
				
					|  |  |         hasErrors: false, |  |  |         hasErrors: false, | 
			
		
	
		
		
			
				
					|  |  |         positions: [] |  |  |         positions: [] | 
			
		
	
	
		
		
			
				
					|  | @ -997,15 +975,16 @@ export class PortfolioService { | 
			
		
	
		
		
			
				
					|  |  |     } |  |  |     } | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |     const portfolioCalculator = new PortfolioCalculator({ |  |  |     const portfolioCalculator = new PortfolioCalculator({ | 
			
		
	
		
		
			
				
					
					|  |  |       transactionPoints, |  |  |       activities, | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					|  |  |       currency: this.request.user.Settings.settings.baseCurrency, |  |  |       currency: this.request.user.Settings.settings.baseCurrency, | 
			
		
	
		
		
			
				
					|  |  |       currentRateService: this.currentRateService, |  |  |       currentRateService: this.currentRateService, | 
			
		
	
		
		
			
				
					
					|  |  |       exchangeRateDataService: this.exchangeRateDataService, |  |  |       exchangeRateDataService: this.exchangeRateDataService | 
			
				
				
			
		
	
		
		
			
				
					|  |  |       orders: portfolioOrders |  |  |  | 
			
		
	
		
		
	
		
		
			
				
					|  |  |     }); |  |  |     }); | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |     const portfolioStart = parseDate(transactionPoints[0].date); |  |  |     const startDate = this.getStartDate( | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |     const startDate = this.getStartDate(dateRange, portfolioStart); |  |  |       dateRange, | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					|  |  |  |  |  |       portfolioCalculator.getStartDate() | 
			
		
	
		
		
			
				
					|  |  |  |  |  |     ); | 
			
		
	
		
		
			
				
					|  |  |     const currentPositions = |  |  |     const currentPositions = | 
			
		
	
		
		
			
				
					|  |  |       await portfolioCalculator.getCurrentPositions(startDate); |  |  |       await portfolioCalculator.getCurrentPositions(startDate); | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
	
		
		
			
				
					|  | @ -1154,15 +1133,15 @@ export class PortfolioService { | 
			
		
	
		
		
			
				
					|  |  |       ) |  |  |       ) | 
			
		
	
		
		
			
				
					|  |  |     ); |  |  |     ); | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |     const { portfolioOrders, transactionPoints } = |  |  |     const { activities } = await this.orderService.getOrders({ | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |       await this.getTransactionPoints({ |  |  |       filters, | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |         filters, |  |  |       userCurrency, | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |         userId, |  |  |       userId, | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |         withExcludedAccounts, |  |  |       withExcludedAccounts, | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |         types: withItems ? ['BUY', 'ITEM', 'SELL'] : ['BUY', 'SELL'] |  |  |       types: withItems ? ['BUY', 'ITEM', 'SELL'] : ['BUY', 'SELL'] | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |       }); |  |  |     }); | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |     if (accountBalanceItems?.length <= 0 && transactionPoints?.length <= 0) { |  |  |     if (accountBalanceItems?.length <= 0 && activities?.length <= 0) { | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					|  |  |       return { |  |  |       return { | 
			
		
	
		
		
			
				
					|  |  |         chart: [], |  |  |         chart: [], | 
			
		
	
		
		
			
				
					|  |  |         firstOrderDate: undefined, |  |  |         firstOrderDate: undefined, | 
			
		
	
	
		
		
			
				
					|  | @ -1184,17 +1163,16 @@ export class PortfolioService { | 
			
		
	
		
		
			
				
					|  |  |     } |  |  |     } | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |     const portfolioCalculator = new PortfolioCalculator({ |  |  |     const portfolioCalculator = new PortfolioCalculator({ | 
			
		
	
		
		
			
				
					
					|  |  |       transactionPoints, |  |  |       activities, | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					|  |  |       currency: userCurrency, |  |  |       currency: userCurrency, | 
			
		
	
		
		
			
				
					|  |  |       currentRateService: this.currentRateService, |  |  |       currentRateService: this.currentRateService, | 
			
		
	
		
		
			
				
					
					|  |  |       exchangeRateDataService: this.exchangeRateDataService, |  |  |       exchangeRateDataService: this.exchangeRateDataService | 
			
				
				
			
		
	
		
		
			
				
					|  |  |       orders: portfolioOrders |  |  |  | 
			
		
	
		
		
	
		
		
			
				
					|  |  |     }); |  |  |     }); | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |     const portfolioStart = min( |  |  |     const portfolioStart = min( | 
			
		
	
		
		
			
				
					|  |  |       [ |  |  |       [ | 
			
		
	
		
		
			
				
					|  |  |         parseDate(accountBalanceItems[0]?.date), |  |  |         parseDate(accountBalanceItems[0]?.date), | 
			
		
	
		
		
			
				
					
					|  |  |         parseDate(transactionPoints[0]?.date) |  |  |         portfolioCalculator.getStartDate() | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					|  |  |       ].filter((date) => { |  |  |       ].filter((date) => { | 
			
		
	
		
		
			
				
					|  |  |         return isValid(date); |  |  |         return isValid(date); | 
			
		
	
		
		
			
				
					|  |  |       }) |  |  |       }) | 
			
		
	
	
		
		
			
				
					|  | @ -1230,7 +1208,6 @@ export class PortfolioService { | 
			
		
	
		
		
			
				
					|  |  |       dateRange, |  |  |       dateRange, | 
			
		
	
		
		
			
				
					|  |  |       impersonationId, |  |  |       impersonationId, | 
			
		
	
		
		
			
				
					|  |  |       portfolioCalculator, |  |  |       portfolioCalculator, | 
			
		
	
		
		
			
				
					|  |  |       transactionPoints, |  |  |  | 
			
		
	
		
		
			
				
					|  |  |       userId |  |  |       userId | 
			
		
	
		
		
			
				
					|  |  |     }); |  |  |     }); | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
	
		
		
			
				
					|  | @ -1307,25 +1284,22 @@ export class PortfolioService { | 
			
		
	
		
		
			
				
					|  |  |     const user = await this.userService.user({ id: userId }); |  |  |     const user = await this.userService.user({ id: userId }); | 
			
		
	
		
		
			
				
					|  |  |     const userCurrency = this.getUserCurrency(user); |  |  |     const userCurrency = this.getUserCurrency(user); | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |     const { activities, portfolioOrders, transactionPoints } = |  |  |     const { activities } = await this.orderService.getOrders({ | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |       await this.getTransactionPoints({ |  |  |       userCurrency, | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |         userId, |  |  |       userId, | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |         types: ['BUY', 'SELL'] |  |  |       types: ['BUY', 'SELL'] | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |       }); |  |  |     }); | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |     const portfolioCalculator = new PortfolioCalculator({ |  |  |     const portfolioCalculator = new PortfolioCalculator({ | 
			
		
	
		
		
			
				
					
					|  |  |       transactionPoints, |  |  |       activities, | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					|  |  |       currency: userCurrency, |  |  |       currency: userCurrency, | 
			
		
	
		
		
			
				
					|  |  |       currentRateService: this.currentRateService, |  |  |       currentRateService: this.currentRateService, | 
			
		
	
		
		
			
				
					
					|  |  |       exchangeRateDataService: this.exchangeRateDataService, |  |  |       exchangeRateDataService: this.exchangeRateDataService | 
			
				
				
			
		
	
		
		
			
				
					|  |  |       orders: portfolioOrders |  |  |  | 
			
		
	
		
		
	
		
		
			
				
					|  |  |     }); |  |  |     }); | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |     const portfolioStart = parseDate( |  |  |     const currentPositions = await portfolioCalculator.getCurrentPositions( | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |       transactionPoints[0]?.date ?? format(new Date(), DATE_FORMAT) |  |  |       portfolioCalculator.getStartDate() | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					|  |  |     ); |  |  |     ); | 
			
		
	
		
		
			
				
					|  |  |     const currentPositions = |  |  |  | 
			
		
	
		
		
			
				
					|  |  |       await portfolioCalculator.getCurrentPositions(portfolioStart); |  |  |  | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |     const positions = currentPositions.positions.filter( |  |  |     const positions = currentPositions.positions.filter( | 
			
		
	
		
		
			
				
					|  |  |       (item) => !item.quantity.eq(0) |  |  |       (item) => !item.quantity.eq(0) | 
			
		
	
	
		
		
			
				
					|  | @ -1455,18 +1429,16 @@ export class PortfolioService { | 
			
		
	
		
		
			
				
					|  |  |     dateRange = 'max', |  |  |     dateRange = 'max', | 
			
		
	
		
		
			
				
					|  |  |     impersonationId, |  |  |     impersonationId, | 
			
		
	
		
		
			
				
					|  |  |     portfolioCalculator, |  |  |     portfolioCalculator, | 
			
		
	
		
		
			
				
					|  |  |     transactionPoints, |  |  |  | 
			
		
	
		
		
			
				
					|  |  |     userId, |  |  |     userId, | 
			
		
	
		
		
			
				
					|  |  |     withDataDecimation = true |  |  |     withDataDecimation = true | 
			
		
	
		
		
			
				
					|  |  |   }: { |  |  |   }: { | 
			
		
	
		
		
			
				
					|  |  |     dateRange?: DateRange; |  |  |     dateRange?: DateRange; | 
			
		
	
		
		
			
				
					|  |  |     impersonationId: string; |  |  |     impersonationId: string; | 
			
		
	
		
		
			
				
					|  |  |     portfolioCalculator: PortfolioCalculator; |  |  |     portfolioCalculator: PortfolioCalculator; | 
			
		
	
		
		
			
				
					|  |  |     transactionPoints: TransactionPoint[]; |  |  |  | 
			
		
	
		
		
			
				
					|  |  |     userId: string; |  |  |     userId: string; | 
			
		
	
		
		
			
				
					|  |  |     withDataDecimation?: boolean; |  |  |     withDataDecimation?: boolean; | 
			
		
	
		
		
			
				
					|  |  |   }): Promise<HistoricalDataContainer> { |  |  |   }): Promise<HistoricalDataContainer> { | 
			
		
	
		
		
			
				
					
					|  |  |     if (transactionPoints.length === 0) { |  |  |     if (portfolioCalculator.getTransactionPoints().length === 0) { | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					|  |  |       return { |  |  |       return { | 
			
		
	
		
		
			
				
					|  |  |         isAllTimeHigh: false, |  |  |         isAllTimeHigh: false, | 
			
		
	
		
		
			
				
					|  |  |         isAllTimeLow: false, |  |  |         isAllTimeLow: false, | 
			
		
	
	
		
		
			
				
					|  | @ -1476,8 +1448,10 @@ export class PortfolioService { | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |     userId = await this.getUserId(impersonationId, userId); |  |  |     userId = await this.getUserId(impersonationId, userId); | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |     const portfolioStart = parseDate(transactionPoints[0].date); |  |  |     const startDate = this.getStartDate( | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |     const startDate = this.getStartDate(dateRange, portfolioStart); |  |  |       dateRange, | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					|  |  |  |  |  |       portfolioCalculator.getStartDate() | 
			
		
	
		
		
			
				
					|  |  |  |  |  |     ); | 
			
		
	
		
		
			
				
					|  |  |     const endDate = new Date(); |  |  |     const endDate = new Date(); | 
			
		
	
		
		
			
				
					|  |  |     const daysInMarket = differenceInDays(endDate, startDate) + 1; |  |  |     const daysInMarket = differenceInDays(endDate, startDate) + 1; | 
			
		
	
		
		
			
				
					|  |  |     const step = withDataDecimation |  |  |     const step = withDataDecimation | 
			
		
	
	
		
		
			
				
					|  | @ -1865,10 +1839,10 @@ export class PortfolioService { | 
			
		
	
		
		
			
				
					|  |  |     const daysInMarket = differenceInDays(new Date(), firstOrderDate); |  |  |     const daysInMarket = differenceInDays(new Date(), firstOrderDate); | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |     const annualizedPerformancePercent = new PortfolioCalculator({ |  |  |     const annualizedPerformancePercent = new PortfolioCalculator({ | 
			
		
	
		
		
			
				
					|  |  |  |  |  |       activities: [], | 
			
		
	
		
		
			
				
					|  |  |       currency: userCurrency, |  |  |       currency: userCurrency, | 
			
		
	
		
		
			
				
					|  |  |       currentRateService: this.currentRateService, |  |  |       currentRateService: this.currentRateService, | 
			
		
	
		
		
			
				
					
					|  |  |       exchangeRateDataService: this.exchangeRateDataService, |  |  |       exchangeRateDataService: this.exchangeRateDataService | 
			
				
				
			
		
	
		
		
			
				
					|  |  |       orders: [] |  |  |  | 
			
		
	
		
		
	
		
		
			
				
					|  |  |     }) |  |  |     }) | 
			
		
	
		
		
			
				
					|  |  |       .getAnnualizedPerformancePercent({ |  |  |       .getAnnualizedPerformancePercent({ | 
			
		
	
		
		
			
				
					|  |  |         daysInMarket, |  |  |         daysInMarket, | 
			
		
	
	
		
		
			
				
					|  | @ -1880,10 +1854,10 @@ export class PortfolioService { | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |     const annualizedPerformancePercentWithCurrencyEffect = |  |  |     const annualizedPerformancePercentWithCurrencyEffect = | 
			
		
	
		
		
			
				
					|  |  |       new PortfolioCalculator({ |  |  |       new PortfolioCalculator({ | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         activities: [], | 
			
		
	
		
		
			
				
					|  |  |         currency: userCurrency, |  |  |         currency: userCurrency, | 
			
		
	
		
		
			
				
					|  |  |         currentRateService: this.currentRateService, |  |  |         currentRateService: this.currentRateService, | 
			
		
	
		
		
			
				
					
					|  |  |         exchangeRateDataService: this.exchangeRateDataService, |  |  |         exchangeRateDataService: this.exchangeRateDataService | 
			
				
				
			
		
	
		
		
			
				
					|  |  |         orders: [] |  |  |  | 
			
		
	
		
		
	
		
		
			
				
					|  |  |       }) |  |  |       }) | 
			
		
	
		
		
			
				
					|  |  |         .getAnnualizedPerformancePercent({ |  |  |         .getAnnualizedPerformancePercent({ | 
			
		
	
		
		
			
				
					|  |  |           daysInMarket, |  |  |           daysInMarket, | 
			
		
	
	
		
		
			
				
					|  | @ -1955,71 +1929,9 @@ export class PortfolioService { | 
			
		
	
		
		
			
				
					|  |  |     ); |  |  |     ); | 
			
		
	
		
		
			
				
					|  |  |   } |  |  |   } | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |   private async getTransactionPoints({ |  |  |   private getUserCurrency(aUser?: UserWithSettings) { | 
			
				
				
			
		
	
		
		
			
				
					|  |  |     filters, |  |  |  | 
			
		
	
		
		
			
				
					|  |  |     includeDrafts = false, |  |  |  | 
			
		
	
		
		
			
				
					|  |  |     types = getAllActivityTypes(), |  |  |  | 
			
		
	
		
		
			
				
					|  |  |     userId, |  |  |  | 
			
		
	
		
		
			
				
					|  |  |     withExcludedAccounts = false |  |  |  | 
			
		
	
		
		
			
				
					|  |  |   }: { |  |  |  | 
			
		
	
		
		
			
				
					|  |  |     filters?: Filter[]; |  |  |  | 
			
		
	
		
		
			
				
					|  |  |     includeDrafts?: boolean; |  |  |  | 
			
		
	
		
		
			
				
					|  |  |     types?: ActivityType[]; |  |  |  | 
			
		
	
		
		
			
				
					|  |  |     userId: string; |  |  |  | 
			
		
	
		
		
			
				
					|  |  |     withExcludedAccounts?: boolean; |  |  |  | 
			
		
	
		
		
			
				
					|  |  |   }): Promise<{ |  |  |  | 
			
		
	
		
		
			
				
					|  |  |     activities: Activity[]; |  |  |  | 
			
		
	
		
		
			
				
					|  |  |     transactionPoints: TransactionPoint[]; |  |  |  | 
			
		
	
		
		
			
				
					|  |  |     portfolioOrders: PortfolioOrder[]; |  |  |  | 
			
		
	
		
		
			
				
					|  |  |   }> { |  |  |  | 
			
		
	
		
		
			
				
					|  |  |     const userCurrency = |  |  |  | 
			
		
	
		
		
			
				
					|  |  |       this.request.user?.Settings?.settings.baseCurrency ?? DEFAULT_CURRENCY; |  |  |  | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  |  | 
			
		
	
		
		
			
				
					|  |  |     const { activities, count } = await this.orderService.getOrders({ |  |  |  | 
			
		
	
		
		
			
				
					|  |  |       filters, |  |  |  | 
			
		
	
		
		
			
				
					|  |  |       includeDrafts, |  |  |  | 
			
		
	
		
		
			
				
					|  |  |       types, |  |  |  | 
			
		
	
		
		
			
				
					|  |  |       userCurrency, |  |  |  | 
			
		
	
		
		
			
				
					|  |  |       userId, |  |  |  | 
			
		
	
		
		
			
				
					|  |  |       withExcludedAccounts |  |  |  | 
			
		
	
		
		
			
				
					|  |  |     }); |  |  |  | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  |  | 
			
		
	
		
		
			
				
					|  |  |     if (count <= 0) { |  |  |  | 
			
		
	
		
		
			
				
					|  |  |       return { activities: [], transactionPoints: [], portfolioOrders: [] }; |  |  |  | 
			
		
	
		
		
			
				
					|  |  |     } |  |  |  | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  |  | 
			
		
	
		
		
			
				
					|  |  |     const portfolioOrders: PortfolioOrder[] = activities.map((order) => ({ |  |  |  | 
			
		
	
		
		
			
				
					|  |  |       currency: order.SymbolProfile.currency, |  |  |  | 
			
		
	
		
		
			
				
					|  |  |       dataSource: order.SymbolProfile.dataSource, |  |  |  | 
			
		
	
		
		
			
				
					|  |  |       date: format(order.date, DATE_FORMAT), |  |  |  | 
			
		
	
		
		
			
				
					|  |  |       fee: new Big(order.fee), |  |  |  | 
			
		
	
		
		
			
				
					|  |  |       name: order.SymbolProfile?.name, |  |  |  | 
			
		
	
		
		
			
				
					|  |  |       quantity: new Big(order.quantity), |  |  |  | 
			
		
	
		
		
			
				
					|  |  |       symbol: order.SymbolProfile.symbol, |  |  |  | 
			
		
	
		
		
			
				
					|  |  |       tags: order.tags, |  |  |  | 
			
		
	
		
		
			
				
					|  |  |       type: order.type, |  |  |  | 
			
		
	
		
		
			
				
					|  |  |       unitPrice: new Big(order.unitPrice) |  |  |  | 
			
		
	
		
		
			
				
					|  |  |     })); |  |  |  | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  |  | 
			
		
	
		
		
			
				
					|  |  |     const portfolioCalculator = new PortfolioCalculator({ |  |  |  | 
			
		
	
		
		
			
				
					|  |  |       currency: userCurrency, |  |  |  | 
			
		
	
		
		
			
				
					|  |  |       currentRateService: this.currentRateService, |  |  |  | 
			
		
	
		
		
			
				
					|  |  |       exchangeRateDataService: this.exchangeRateDataService, |  |  |  | 
			
		
	
		
		
			
				
					|  |  |       orders: portfolioOrders |  |  |  | 
			
		
	
		
		
			
				
					|  |  |     }); |  |  |  | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  |  | 
			
		
	
		
		
			
				
					|  |  |     portfolioCalculator.computeTransactionPoints(); |  |  |  | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  |  | 
			
		
	
		
		
			
				
					|  |  |     return { |  |  |  | 
			
		
	
		
		
			
				
					|  |  |       activities, |  |  |  | 
			
		
	
		
		
			
				
					|  |  |       portfolioOrders, |  |  |  | 
			
		
	
		
		
			
				
					|  |  |       transactionPoints: portfolioCalculator.getTransactionPoints() |  |  |  | 
			
		
	
		
		
			
				
					|  |  |     }; |  |  |  | 
			
		
	
		
		
			
				
					|  |  |   } |  |  |  | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  |  | 
			
		
	
		
		
			
				
					|  |  |   private getUserCurrency(aUser: UserWithSettings) { |  |  |  | 
			
		
	
		
		
	
		
		
			
				
					|  |  |     return ( |  |  |     return ( | 
			
		
	
		
		
			
				
					
					|  |  |       aUser.Settings?.settings.baseCurrency ?? |  |  |       aUser?.Settings?.settings.baseCurrency ?? | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					|  |  |       this.request.user?.Settings?.settings.baseCurrency ?? |  |  |       this.request.user?.Settings?.settings.baseCurrency ?? | 
			
		
	
		
		
			
				
					|  |  |       DEFAULT_CURRENCY |  |  |       DEFAULT_CURRENCY | 
			
		
	
		
		
			
				
					|  |  |     ); |  |  |     ); | 
			
		
	
	
		
		
			
				
					|  | 
 |