From b2f50a438e5723d973b1eac5ef4733b71c424be9 Mon Sep 17 00:00:00 2001 From: mantikoros Date: Tue, 11 Jan 2022 12:40:57 -0600 Subject: [PATCH] antes --- common/antes.ts | 5 ++++- common/calculate.ts | 13 +++++++++---- common/contract.ts | 1 + common/new-contract.ts | 9 ++++----- web/components/contract-prob-graph.tsx | 4 ++-- 5 files changed, 20 insertions(+), 12 deletions(-) diff --git a/common/antes.ts b/common/antes.ts index 70857605..5f269083 100644 --- a/common/antes.ts +++ b/common/antes.ts @@ -10,5 +10,8 @@ export const calcStartPool = (initialProbInt: number, ante = 0) => { const poolYes = p * ante const poolNo = (1 - p) * ante - return { sharesYes, sharesNo, poolYes, poolNo } + const startYes = Math.sqrt(p) * PHANTOM_ANTE + const startNo = Math.sqrt(1 - p) * PHANTOM_ANTE + + return { sharesYes, sharesNo, poolYes, poolNo, startYes, startNo } } diff --git a/common/calculate.ts b/common/calculate.ts index a5c1e4a1..5468588e 100644 --- a/common/calculate.ts +++ b/common/calculate.ts @@ -104,7 +104,7 @@ export function calculateStandardPayout( const { amount, outcome: betOutcome, shares } = bet if (betOutcome !== outcome) return 0 - const { totalShares, totalBets } = contract + const { totalShares, totalBets, startPool } = contract if (totalShares[outcome] === 0) return 0 const truePool = contract.pool.YES + contract.pool.NO @@ -112,7 +112,8 @@ export function calculateStandardPayout( if (totalBets[outcome] >= truePool) return (amount / totalBets[outcome]) * truePool - const total = totalShares[outcome] - totalBets[outcome] + const startShares = startPool.YES + startPool.NO + const total = totalShares[outcome] - startShares - totalBets[outcome] const winningsPool = truePool - totalBets[outcome] return (1 - FEES) * (amount + ((shares - amount) / total) * winningsPool) @@ -139,8 +140,12 @@ function calculateMktPayout(contract: Contract, bet: Bet) { const winningsPool = truePool - weightedTotal const weightedShareTotal = - p * (contract.totalShares.YES - contract.totalBets.YES) + - (1 - p) * (contract.totalShares.NO - contract.totalBets.NO) + p * + (contract.totalShares.YES - + contract.startPool.YES - + contract.totalBets.YES) + + (1 - p) * + (contract.totalShares.NO - contract.startPool.NO - contract.totalBets.NO) return ( (1 - FEES) * diff --git a/common/contract.ts b/common/contract.ts index 7c894ce5..eb00ae7b 100644 --- a/common/contract.ts +++ b/common/contract.ts @@ -11,6 +11,7 @@ export type Contract = { outcomeType: 'BINARY' // | 'MULTI' | 'interval' | 'date' // outcomes: ['YES', 'NO'] + mechanism: 'dpm-2' startPool: { YES: number; NO: number } pool: { YES: number; NO: number } totalShares: { YES: number; NO: number } diff --git a/common/new-contract.ts b/common/new-contract.ts index f8e3225b..e3da778d 100644 --- a/common/new-contract.ts +++ b/common/new-contract.ts @@ -12,10 +12,8 @@ export function getNewContract( ante?: number, closeTime?: number ) { - const { sharesYes, sharesNo, poolYes, poolNo } = calcStartPool( - initialProb, - ante - ) + const { sharesYes, sharesNo, poolYes, poolNo, startYes, startNo } = + calcStartPool(initialProb, ante) const contract: Contract = { id, @@ -29,7 +27,8 @@ export function getNewContract( question: question.trim(), description: description.trim(), - startPool: { YES: poolYes, NO: poolNo }, + mechanism: 'dpm-2', + startPool: { YES: startYes, NO: startNo }, pool: { YES: poolYes, NO: poolNo }, totalShares: { YES: sharesYes, NO: sharesNo }, totalBets: { YES: poolYes, NO: poolNo }, diff --git a/web/components/contract-prob-graph.tsx b/web/components/contract-prob-graph.tsx index beca505d..0c059e62 100644 --- a/web/components/contract-prob-graph.tsx +++ b/web/components/contract-prob-graph.tsx @@ -1,6 +1,7 @@ import { DatumValue } from '@nivo/core' import { ResponsiveLine } from '@nivo/line' import dayjs from 'dayjs' +import { getProbability } from '../../common/calculate' import { useBets } from '../hooks/use-bets' import { useWindowSize } from '../hooks/use-window-size' import { Contract } from '../lib/firebase/contracts' @@ -12,8 +13,7 @@ export function ContractProbGraph(props: { contract: Contract }) { let bets = useBets(id) if (bets === 'loading') bets = [] - const startProb = - startPool.YES ** 2 / (startPool.YES ** 2 + startPool.NO ** 2) + const startProb = getProbability(startPool) const times = [ contract.createdTime,