Bet calculation / UI updates
This commit is contained in:
parent
e8f94f48e2
commit
f32933f668
|
@ -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>
|
||||
)
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user