Fix payout calculation for correct bet in bet panel.
This commit is contained in:
parent
fbc61fe28f
commit
75e9d419ee
|
@ -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>
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue
Block a user