diff --git a/web/components/bet-panel.tsx b/web/components/bet-panel.tsx
index f6f35676..be89621f 100644
--- a/web/components/bet-panel.tsx
+++ b/web/components/bet-panel.tsx
@@ -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 }) {
{formatMoney(
- calculatePayout(
- contract,
- { outcome: betChoice, amount: betAmount ?? 0, shares } as Bet,
- betChoice
- )
+ betAmount
+ ? calculatePayoutAfterCorrectBet(contract, {
+ outcome: betChoice,
+ amount: betAmount,
+ shares,
+ } as Bet)
+ : 0
)}
diff --git a/web/lib/calculate.ts b/web/lib/calculate.ts
index b265f228..6e446155 100644
--- a/web/lib/calculate.ts
+++ b/web/lib/calculate.ts
@@ -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)