Bet calculation / UI updates

This commit is contained in:
jahooma 2021-12-15 17:27:02 -06:00
parent e8f94f48e2
commit f32933f668
2 changed files with 18 additions and 17 deletions

View File

@ -96,10 +96,10 @@ function MyContractBets(props: { contractId: string; bets: Bet[] }) {
</>
) : (
<>
<Col>
{/* <Col>
<div className="text-sm text-gray-500">Current value</div>
<div className="">{formatMoney(betsValue)}</div>
</Col>
</Col> */}
<Col>
<div className="text-sm text-primary">If YES</div>
<div className="">{formatMoney(yesWinnings)}</div>
@ -127,12 +127,12 @@ function ContractBetsTable(props: { contract: Contract; bets: Bet[] }) {
<table className="table table-zebra table-compact text-gray-500 w-full">
<thead>
<tr className="p-2">
<th>Date</th>
<th>Outcome</th>
<th>Bet</th>
<th>Probability</th>
<th>Date</th>
<th>Est. max payout</th>
<th>Profit/loss</th>
<th>Current value</th>
</tr>
</thead>
<tbody>
@ -151,14 +151,14 @@ function BetRow(props: { bet: Bet; contract: Contract }) {
return (
<tr>
<td>{dayjs(createdTime).format('MMM D, H:mma')}</td>
<td>{outcome}</td>
<td>{formatMoney(amount)}</td>
<td>
{formatPercent(probBefore)} {formatPercent(probAfter)}
</td>
<td>{dayjs(createdTime).format('MMM D, H:mma')}</td>
<td>{formatMoney(amount + dpmWeight)}</td>
<td>{formatMoney(currentValue(contract, bet) - amount)}</td>
<td>{formatMoney(currentValue(contract, bet))}</td>
</tr>
)
}

View File

@ -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) {