Fix payout calculation for correct bet in bet panel.

This commit is contained in:
jahooma 2022-01-05 17:03:26 -06:00
parent fbc61fe28f
commit 75e9d419ee
2 changed files with 27 additions and 6 deletions

View File

@ -18,7 +18,7 @@ import {
getProbability,
calculateShares,
getProbabilityAfterBet,
calculatePayout,
calculatePayoutAfterCorrectBet,
} from '../lib/calculate'
import { firebaseLogin } from '../lib/firebase/users'
import { OutcomeLabel } from './outcome-label'
@ -179,11 +179,13 @@ export function BetPanel(props: { contract: Contract; className?: string }) {
</div>
<div>
{formatMoney(
calculatePayout(
contract,
{ outcome: betChoice, amount: betAmount ?? 0, shares } as Bet,
betChoice
)
betAmount
? calculatePayoutAfterCorrectBet(contract, {
outcome: betChoice,
amount: betAmount,
shares,
} as Bet)
: 0
)}
</div>
</AdvancedPanel>

View File

@ -62,6 +62,25 @@ export function calculatePayout(
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) {
const p =
contract.pool.YES ** 2 / (contract.pool.YES ** 2 + contract.pool.NO ** 2)