From f32933f668c239bde42c9e5ceffa070af68cd253 Mon Sep 17 00:00:00 2001 From: jahooma Date: Wed, 15 Dec 2021 17:27:02 -0600 Subject: [PATCH] Bet calculation / UI updates --- web/components/bets-list.tsx | 12 ++++++------ web/lib/calculation/contract.ts | 23 ++++++++++++----------- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/web/components/bets-list.tsx b/web/components/bets-list.tsx index d62cd19e..aa4d45fb 100644 --- a/web/components/bets-list.tsx +++ b/web/components/bets-list.tsx @@ -96,10 +96,10 @@ function MyContractBets(props: { contractId: string; bets: Bet[] }) { ) : ( <> - + {/*
Current value
{formatMoney(betsValue)}
- + */}
If YES
{formatMoney(yesWinnings)}
@@ -127,12 +127,12 @@ function ContractBetsTable(props: { contract: Contract; bets: Bet[] }) { + - - + @@ -151,14 +151,14 @@ function BetRow(props: { bet: Bet; contract: Contract }) { return ( + - - + ) } diff --git a/web/lib/calculation/contract.ts b/web/lib/calculation/contract.ts index 37a80b6a..88ef49ab 100644 --- a/web/lib/calculation/contract.ts +++ b/web/lib/calculation/contract.ts @@ -1,6 +1,8 @@ import { Bet } from '../firebase/bets' import { Contract } from '../firebase/contracts' +const fees = 0.02 + export function getProbability(pot: { YES: number; NO: number }) { const [yesPot, noPot] = [pot.YES, pot.NO] const numerator = Math.pow(yesPot, 2) @@ -37,24 +39,23 @@ export function calculateWinnings( bet: Bet, outcome: 'YES' | 'NO' | 'CANCEL' ) { - let { dpmWeights, pot } = contract const { amount, outcome: betOutcome, dpmWeight } = bet if (outcome === 'CANCEL') return amount + if (betOutcome !== outcome) return 0 + + let { dpmWeights, pot, seedAmounts } = contract + + // Fake data if not set. + if (!dpmWeights) dpmWeights = { YES: 100, NO: 100 } - if (!dpmWeights) { - // Fake data if not set. - dpmWeights = { YES: 100, NO: 100 } - } // Fake data if not set. if (!pot) pot = { YES: 100, NO: 100 } - return betOutcome === outcome - ? 0.98 * - (dpmWeight / dpmWeights[outcome]) * - pot[outcome === 'YES' ? 'NO' : 'YES'] + - amount - : 0 + const otherOutcome = outcome === 'YES' ? 'NO' : 'YES' + const potSize = pot[otherOutcome] - seedAmounts[otherOutcome] + + return (1 - fees) * (dpmWeight / dpmWeights[outcome]) * potSize + amount } export function currentValue(contract: Contract, bet: Bet) {
Date Outcome Bet ProbabilityDate Est. max payoutProfit/lossCurrent value
{dayjs(createdTime).format('MMM D, H:mma')} {outcome} {formatMoney(amount)} {formatPercent(probBefore)} → {formatPercent(probAfter)} {dayjs(createdTime).format('MMM D, H:mma')} {formatMoney(amount + dpmWeight)}{formatMoney(currentValue(contract, bet) - amount)}{formatMoney(currentValue(contract, bet))}