Browse Source
			
			
			Bugfix/fix division by zero error in cash positions calculation (#1462)
			
				* Handle division by zero
* Update changelog
			
			
				pull/1463/head
			
			
		 
		
			
				
					
						 Thomas Kaul
					
					3 years ago
						Thomas Kaul
					
					3 years ago
					
						
							committed by
							
								 GitHub
								GitHub
							
						 
					
				 
				
			 
		 
		
			
				
					
					No known key found for this signature in database
					
						
							GPG Key ID: 4AEE18F83AFDEB23
						
					
				
			
		
		
		
	
		
			
				 2 changed files with 
7 additions and 
10 deletions
			 
			
		 
		
			
				- 
					
					
					 
					CHANGELOG.md
				
- 
					
					
					 
					apps/api/src/app/portfolio/portfolio.service.ts
				
				
				
					
						
							
								
									
	
		
		
			
				
					|  | @ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 | 
			
		
	
		
		
			
				
					|  |  | ### Fixed |  |  | ### Fixed | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  | - Fixed the activities sorting in the position detail dialog |  |  | - Fixed the activities sorting in the position detail dialog | 
			
		
	
		
		
			
				
					|  |  |  |  |  | - Fixed a division by zero error in the cash positions calculation | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  | ## 1.213.0 - 14.11.2022 |  |  | ## 1.213.0 - 14.11.2022 | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
	
		
		
			
				
					|  | 
 | 
			
		
	
								
							
						
					 
					
				 
			 
		
			
			
			
			
			
			
				
				
					
						
							
								
									
	
		
		
			
				
					|  | @ -1163,16 +1163,12 @@ export class PortfolioService { | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |     for (const symbol of Object.keys(cashPositions)) { |  |  |     for (const symbol of Object.keys(cashPositions)) { | 
			
		
	
		
		
			
				
					|  |  |       // Calculate allocations for each currency
 |  |  |       // Calculate allocations for each currency
 | 
			
		
	
		
		
			
				
					
					|  |  |       cashPositions[symbol].allocationCurrent = new Big( |  |  |       cashPositions[symbol].allocationCurrent = value.gt(0) | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |         cashPositions[symbol].value |  |  |         ? new Big(cashPositions[symbol].value).div(value).toNumber() | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |       ) |  |  |         : 0; | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |         .div(value) |  |  |       cashPositions[symbol].allocationInvestment = investment.gt(0) | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |         .toNumber(); |  |  |         ? new Big(cashPositions[symbol].investment).div(investment).toNumber() | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |       cashPositions[symbol].allocationInvestment = new Big( |  |  |         : 0; | 
			
				
				
			
		
	
		
		
			
				
					|  |  |         cashPositions[symbol].investment |  |  |  | 
			
		
	
		
		
			
				
					|  |  |       ) |  |  |  | 
			
		
	
		
		
			
				
					|  |  |         .div(investment) |  |  |  | 
			
		
	
		
		
			
				
					|  |  |         .toNumber(); |  |  |  | 
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					|  |  |     } |  |  |     } | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |     return cashPositions; |  |  |     return cashPositions; | 
			
		
	
	
		
		
			
				
					|  | 
 |