Fix payout calculation for correct bet in bet panel.
This commit is contained in:
		
							parent
							
								
									fbc61fe28f
								
							
						
					
					
						commit
						75e9d419ee
					
				|  | @ -18,7 +18,7 @@ import { | ||||||
|   getProbability, |   getProbability, | ||||||
|   calculateShares, |   calculateShares, | ||||||
|   getProbabilityAfterBet, |   getProbabilityAfterBet, | ||||||
|   calculatePayout, |   calculatePayoutAfterCorrectBet, | ||||||
| } from '../lib/calculate' | } from '../lib/calculate' | ||||||
| import { firebaseLogin } from '../lib/firebase/users' | import { firebaseLogin } from '../lib/firebase/users' | ||||||
| import { OutcomeLabel } from './outcome-label' | import { OutcomeLabel } from './outcome-label' | ||||||
|  | @ -179,11 +179,13 @@ export function BetPanel(props: { contract: Contract; className?: string }) { | ||||||
|         </div> |         </div> | ||||||
|         <div> |         <div> | ||||||
|           {formatMoney( |           {formatMoney( | ||||||
|             calculatePayout( |             betAmount | ||||||
|               contract, |               ? calculatePayoutAfterCorrectBet(contract, { | ||||||
|               { outcome: betChoice, amount: betAmount ?? 0, shares } as Bet, |                   outcome: betChoice, | ||||||
|               betChoice |                   amount: betAmount, | ||||||
|             ) |                   shares, | ||||||
|  |                 } as Bet) | ||||||
|  |               : 0 | ||||||
|           )} |           )} | ||||||
|         </div> |         </div> | ||||||
|       </AdvancedPanel> |       </AdvancedPanel> | ||||||
|  |  | ||||||
|  | @ -62,6 +62,25 @@ export function calculatePayout( | ||||||
|   return (1 - fees) * (amount + ((shares - amount) / total) * winningsPool) |   return (1 - fees) * (amount + ((shares - amount) / total) * winningsPool) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | export function calculatePayoutAfterCorrectBet(contract: Contract, bet: Bet) { | ||||||
|  |   const { amount, outcome, shares } = bet | ||||||
|  |   const { totalShares, totalBets } = contract | ||||||
|  | 
 | ||||||
|  |   const startPool = contract.startPool.YES + contract.startPool.NO | ||||||
|  |   const truePool = amount + contract.pool.YES + contract.pool.NO - startPool | ||||||
|  | 
 | ||||||
|  |   const totalBetsOutcome = totalBets[outcome] + amount | ||||||
|  |   const totalSharesOutcome = totalShares[outcome] + shares | ||||||
|  | 
 | ||||||
|  |   if (totalBetsOutcome >= truePool) | ||||||
|  |     return (amount / totalBetsOutcome) * truePool | ||||||
|  | 
 | ||||||
|  |   const total = totalSharesOutcome - totalBetsOutcome | ||||||
|  |   const winningsPool = truePool - totalBetsOutcome | ||||||
|  | 
 | ||||||
|  |   return (1 - fees) * (amount + ((shares - amount) / total) * winningsPool) | ||||||
|  | } | ||||||
|  | 
 | ||||||
| function calculateMktPayout(contract: Contract, bet: Bet) { | function calculateMktPayout(contract: Contract, bet: Bet) { | ||||||
|   const p = |   const p = | ||||||
|     contract.pool.YES ** 2 / (contract.pool.YES ** 2 + contract.pool.NO ** 2) |     contract.pool.YES ** 2 / (contract.pool.YES ** 2 + contract.pool.NO ** 2) | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user