rename dpm calculations
This commit is contained in:
parent
e80926d201
commit
42577b20a9
|
@ -1,5 +1,5 @@
|
|||
import { Bet } from './bet'
|
||||
import { getProbability } from './calculate-dpm'
|
||||
import { getDpmProbability } from './calculate-dpm'
|
||||
import { getCpmmProbability } from './calculate-cpmm'
|
||||
import { Binary, CPMM, DPM, FreeResponse, FullContract } from './contract'
|
||||
import { User } from './user'
|
||||
|
@ -67,7 +67,7 @@ export function getAnteBets(
|
|||
yesAnteId: string,
|
||||
noAnteId: string
|
||||
) {
|
||||
const p = getProbability(contract.totalShares)
|
||||
const p = getDpmProbability(contract.totalShares)
|
||||
const ante = contract.totalBets.YES + contract.totalBets.NO
|
||||
|
||||
const { createdTime } = contract
|
||||
|
|
|
@ -3,12 +3,12 @@ import { Bet } from './bet'
|
|||
import { Binary, DPM, FullContract } from './contract'
|
||||
import { FEES } from './fees'
|
||||
|
||||
export function getProbability(totalShares: { [outcome: string]: number }) {
|
||||
export function getDpmProbability(totalShares: { [outcome: string]: number }) {
|
||||
// For binary contracts only.
|
||||
return getOutcomeProbability(totalShares, 'YES')
|
||||
return getDpmOutcomeProbability(totalShares, 'YES')
|
||||
}
|
||||
|
||||
export function getOutcomeProbability(
|
||||
export function getDpmOutcomeProbability(
|
||||
totalShares: {
|
||||
[outcome: string]: number
|
||||
},
|
||||
|
@ -19,22 +19,22 @@ export function getOutcomeProbability(
|
|||
return shares ** 2 / squareSum
|
||||
}
|
||||
|
||||
export function getProbabilityAfterBet(
|
||||
export function getDpmProbabilityAfterBet(
|
||||
totalShares: {
|
||||
[outcome: string]: number
|
||||
},
|
||||
outcome: string,
|
||||
bet: number
|
||||
) {
|
||||
const shares = calculateShares(totalShares, bet, outcome)
|
||||
const shares = calculateDpmShares(totalShares, bet, outcome)
|
||||
|
||||
const prevShares = totalShares[outcome] ?? 0
|
||||
const newTotalShares = { ...totalShares, [outcome]: prevShares + shares }
|
||||
|
||||
return getOutcomeProbability(newTotalShares, outcome)
|
||||
return getDpmOutcomeProbability(newTotalShares, outcome)
|
||||
}
|
||||
|
||||
export function getProbabilityAfterSale(
|
||||
export function getDpmProbabilityAfterSale(
|
||||
totalShares: {
|
||||
[outcome: string]: number
|
||||
},
|
||||
|
@ -45,10 +45,10 @@ export function getProbabilityAfterSale(
|
|||
const newTotalShares = { ...totalShares, [outcome]: prevShares - shares }
|
||||
|
||||
const predictionOutcome = outcome === 'NO' ? 'YES' : outcome
|
||||
return getOutcomeProbability(newTotalShares, predictionOutcome)
|
||||
return getDpmOutcomeProbability(newTotalShares, predictionOutcome)
|
||||
}
|
||||
|
||||
export function calculateShares(
|
||||
export function calculateDpmShares(
|
||||
totalShares: {
|
||||
[outcome: string]: number
|
||||
},
|
||||
|
@ -63,7 +63,7 @@ export function calculateShares(
|
|||
return Math.sqrt(bet ** 2 + shares ** 2 + c) - shares
|
||||
}
|
||||
|
||||
export function calculateRawShareValue(
|
||||
export function calculateDpmRawShareValue(
|
||||
totalShares: {
|
||||
[outcome: string]: number
|
||||
},
|
||||
|
@ -85,7 +85,7 @@ export function calculateRawShareValue(
|
|||
return currentValue - postSaleValue
|
||||
}
|
||||
|
||||
export function calculateMoneyRatio(
|
||||
export function calculateDpmMoneyRatio(
|
||||
contract: FullContract<DPM, any>,
|
||||
bet: Bet,
|
||||
shareValue: number
|
||||
|
@ -93,7 +93,7 @@ export function calculateMoneyRatio(
|
|||
const { totalShares, totalBets, pool } = contract
|
||||
const { outcome, amount } = bet
|
||||
|
||||
const p = getOutcomeProbability(totalShares, outcome)
|
||||
const p = getDpmOutcomeProbability(totalShares, outcome)
|
||||
|
||||
const actual = _.sum(Object.values(pool)) - shareValue
|
||||
|
||||
|
@ -103,7 +103,7 @@ export function calculateMoneyRatio(
|
|||
_.sumBy(
|
||||
Object.keys(totalBets),
|
||||
(outcome) =>
|
||||
getOutcomeProbability(totalShares, outcome) *
|
||||
getDpmOutcomeProbability(totalShares, outcome) *
|
||||
(totalBets as { [outcome: string]: number })[outcome]
|
||||
) - betAmount
|
||||
|
||||
|
@ -112,42 +112,42 @@ export function calculateMoneyRatio(
|
|||
return actual / expected
|
||||
}
|
||||
|
||||
export function calculateShareValue(
|
||||
export function calculateDpmShareValue(
|
||||
contract: FullContract<DPM, any>,
|
||||
bet: Bet
|
||||
) {
|
||||
const { pool, totalShares } = contract
|
||||
const { shares, outcome } = bet
|
||||
|
||||
const shareValue = calculateRawShareValue(totalShares, shares, outcome)
|
||||
const f = calculateMoneyRatio(contract, bet, shareValue)
|
||||
const shareValue = calculateDpmRawShareValue(totalShares, shares, outcome)
|
||||
const f = calculateDpmMoneyRatio(contract, bet, shareValue)
|
||||
|
||||
const myPool = pool[outcome]
|
||||
const adjShareValue = Math.min(Math.min(1, f) * shareValue, myPool)
|
||||
return adjShareValue
|
||||
}
|
||||
|
||||
export function calculateSaleAmount(
|
||||
export function calculateDpmSaleAmount(
|
||||
contract: FullContract<DPM, any>,
|
||||
bet: Bet
|
||||
) {
|
||||
const { amount } = bet
|
||||
const winnings = calculateShareValue(contract, bet)
|
||||
return deductFees(amount, winnings)
|
||||
const winnings = calculateDpmShareValue(contract, bet)
|
||||
return deductDpmFees(amount, winnings)
|
||||
}
|
||||
|
||||
export function calculatePayout(
|
||||
export function calculateDpmPayout(
|
||||
contract: FullContract<DPM, any>,
|
||||
bet: Bet,
|
||||
outcome: string
|
||||
) {
|
||||
if (outcome === 'CANCEL') return calculateCancelPayout(contract, bet)
|
||||
if (outcome === 'MKT') return calculateMktPayout(contract, bet)
|
||||
if (outcome === 'CANCEL') return calculateDpmCancelPayout(contract, bet)
|
||||
if (outcome === 'MKT') return calculateMktDpmPayout(contract, bet)
|
||||
|
||||
return calculateStandardPayout(contract, bet, outcome)
|
||||
return calculateStandardDpmPayout(contract, bet, outcome)
|
||||
}
|
||||
|
||||
export function calculateCancelPayout(
|
||||
export function calculateDpmCancelPayout(
|
||||
contract: FullContract<DPM, any>,
|
||||
bet: Bet
|
||||
) {
|
||||
|
@ -158,7 +158,7 @@ export function calculateCancelPayout(
|
|||
return (bet.amount / betTotal) * poolTotal
|
||||
}
|
||||
|
||||
export function calculateStandardPayout(
|
||||
export function calculateStandardDpmPayout(
|
||||
contract: FullContract<DPM, any>,
|
||||
bet: Bet,
|
||||
outcome: string
|
||||
|
@ -179,7 +179,7 @@ export function calculateStandardPayout(
|
|||
return amount + (1 - FEES) * Math.max(0, winnings - amount)
|
||||
}
|
||||
|
||||
export function calculatePayoutAfterCorrectBet(
|
||||
export function calculateDpmPayoutAfterCorrectBet(
|
||||
contract: FullContract<DPM, any>,
|
||||
bet: Bet
|
||||
) {
|
||||
|
@ -206,12 +206,12 @@ export function calculatePayoutAfterCorrectBet(
|
|||
},
|
||||
}
|
||||
|
||||
return calculateStandardPayout(newContract, bet, outcome)
|
||||
return calculateStandardDpmPayout(newContract, bet, outcome)
|
||||
}
|
||||
|
||||
function calculateMktPayout(contract: FullContract<DPM, any>, bet: Bet) {
|
||||
function calculateMktDpmPayout(contract: FullContract<DPM, any>, bet: Bet) {
|
||||
if (contract.outcomeType === 'BINARY')
|
||||
return calculateBinaryMktPayout(contract, bet)
|
||||
return calculateBinaryMktDpmPayout(contract, bet)
|
||||
|
||||
const { totalShares, pool } = contract
|
||||
|
||||
|
@ -230,13 +230,13 @@ function calculateMktPayout(contract: FullContract<DPM, any>, bet: Bet) {
|
|||
|
||||
const { outcome, amount, shares } = bet
|
||||
|
||||
const betP = getOutcomeProbability(totalShares, outcome)
|
||||
const betP = getDpmOutcomeProbability(totalShares, outcome)
|
||||
const winnings = ((betP * shares) / weightedShareTotal) * totalPool
|
||||
|
||||
return deductFees(amount, winnings)
|
||||
return deductDpmFees(amount, winnings)
|
||||
}
|
||||
|
||||
function calculateBinaryMktPayout(
|
||||
function calculateBinaryMktDpmPayout(
|
||||
contract: FullContract<DPM, Binary>,
|
||||
bet: Bet
|
||||
) {
|
||||
|
@ -244,7 +244,7 @@ function calculateBinaryMktPayout(
|
|||
const p =
|
||||
resolutionProbability !== undefined
|
||||
? resolutionProbability
|
||||
: getProbability(totalShares)
|
||||
: getDpmProbability(totalShares)
|
||||
|
||||
const pool = contract.pool.YES + contract.pool.NO
|
||||
|
||||
|
@ -257,16 +257,16 @@ function calculateBinaryMktPayout(
|
|||
const betP = outcome === 'YES' ? p : 1 - p
|
||||
const winnings = ((betP * shares) / weightedShareTotal) * pool
|
||||
|
||||
return deductFees(amount, winnings)
|
||||
return deductDpmFees(amount, winnings)
|
||||
}
|
||||
|
||||
export function resolvedPayout(contract: FullContract<DPM, any>, bet: Bet) {
|
||||
export function resolvedDpmPayout(contract: FullContract<DPM, any>, bet: Bet) {
|
||||
if (contract.resolution)
|
||||
return calculatePayout(contract, bet, contract.resolution)
|
||||
return calculateDpmPayout(contract, bet, contract.resolution)
|
||||
throw new Error('Contract was not resolved')
|
||||
}
|
||||
|
||||
export const deductFees = (betAmount: number, winnings: number) => {
|
||||
export const deductDpmFees = (betAmount: number, winnings: number) => {
|
||||
return winnings > betAmount
|
||||
? betAmount + (1 - FEES) * (winnings - betAmount)
|
||||
: winnings
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
import * as _ from 'lodash'
|
||||
import { Bet, MAX_LOAN_PER_CONTRACT } from './bet'
|
||||
import {
|
||||
calculateShares,
|
||||
getProbability,
|
||||
getOutcomeProbability,
|
||||
calculateDpmShares,
|
||||
getDpmProbability,
|
||||
getDpmOutcomeProbability,
|
||||
} from './calculate-dpm'
|
||||
import { calculateCpmmShares, getCpmmProbability } from './calculate-cpmm'
|
||||
import {
|
||||
|
@ -71,7 +71,7 @@ export const getNewBinaryDpmBetInfo = (
|
|||
? { YES: yesPool + amount, NO: noPool }
|
||||
: { YES: yesPool, NO: noPool + amount }
|
||||
|
||||
const shares = calculateShares(contract.totalShares, amount, outcome)
|
||||
const shares = calculateDpmShares(contract.totalShares, amount, outcome)
|
||||
|
||||
const { YES: yesShares, NO: noShares } = contract.totalShares
|
||||
|
||||
|
@ -87,8 +87,8 @@ export const getNewBinaryDpmBetInfo = (
|
|||
? { YES: yesBets + amount, NO: noBets }
|
||||
: { YES: yesBets, NO: noBets + amount }
|
||||
|
||||
const probBefore = getProbability(contract.totalShares)
|
||||
const probAfter = getProbability(newTotalShares)
|
||||
const probBefore = getDpmProbability(contract.totalShares)
|
||||
const probAfter = getDpmProbability(newTotalShares)
|
||||
|
||||
const newBet: Bet = {
|
||||
id: newBetId,
|
||||
|
@ -121,7 +121,7 @@ export const getNewMultiBetInfo = (
|
|||
const prevOutcomePool = pool[outcome] ?? 0
|
||||
const newPool = { ...pool, [outcome]: prevOutcomePool + amount }
|
||||
|
||||
const shares = calculateShares(contract.totalShares, amount, outcome)
|
||||
const shares = calculateDpmShares(contract.totalShares, amount, outcome)
|
||||
|
||||
const prevShares = totalShares[outcome] ?? 0
|
||||
const newTotalShares = { ...totalShares, [outcome]: prevShares + shares }
|
||||
|
@ -129,8 +129,8 @@ export const getNewMultiBetInfo = (
|
|||
const prevTotalBets = totalBets[outcome] ?? 0
|
||||
const newTotalBets = { ...totalBets, [outcome]: prevTotalBets + amount }
|
||||
|
||||
const probBefore = getOutcomeProbability(totalShares, outcome)
|
||||
const probAfter = getOutcomeProbability(newTotalShares, outcome)
|
||||
const probBefore = getDpmOutcomeProbability(totalShares, outcome)
|
||||
const probAfter = getDpmOutcomeProbability(newTotalShares, outcome)
|
||||
|
||||
const newBet: Bet = {
|
||||
id: newBetId,
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import * as _ from 'lodash'
|
||||
|
||||
import { Bet } from './bet'
|
||||
import { deductFees, getProbability } from './calculate-dpm'
|
||||
import { deductDpmFees, getDpmProbability } from './calculate-dpm'
|
||||
import {
|
||||
Binary,
|
||||
Contract,
|
||||
|
@ -124,7 +124,7 @@ export const getMktPayouts = (
|
|||
) => {
|
||||
const p =
|
||||
resolutionProbability === undefined
|
||||
? getProbability(contract.totalShares)
|
||||
? getDpmProbability(contract.totalShares)
|
||||
: resolutionProbability
|
||||
|
||||
const weightedShareTotal = _.sumBy(bets, (b) =>
|
||||
|
@ -137,7 +137,7 @@ export const getMktPayouts = (
|
|||
const betP = outcome === 'YES' ? p : 1 - p
|
||||
const winnings = ((betP * shares) / weightedShareTotal) * pool
|
||||
const profit = winnings - amount
|
||||
const payout = deductFees(amount, winnings)
|
||||
const payout = deductDpmFees(amount, winnings)
|
||||
return { userId, profit, payout }
|
||||
})
|
||||
|
||||
|
@ -167,14 +167,14 @@ export const getMktFixedPayouts = (
|
|||
) => {
|
||||
const p =
|
||||
resolutionProbability === undefined
|
||||
? getProbability(contract.pool)
|
||||
? getDpmProbability(contract.pool)
|
||||
: resolutionProbability
|
||||
|
||||
const payouts = bets.map(({ userId, outcome, amount, shares }) => {
|
||||
const betP = outcome === 'YES' ? p : 1 - p
|
||||
const winnings = betP * shares
|
||||
const profit = winnings - amount
|
||||
const payout = deductFees(amount, winnings)
|
||||
const payout = deductDpmFees(amount, winnings)
|
||||
return { userId, profit, payout }
|
||||
})
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import { Bet } from './bet'
|
||||
import {
|
||||
calculateShareValue,
|
||||
deductFees,
|
||||
getProbability,
|
||||
getDpmProbability,
|
||||
calculateDpmShareValue,
|
||||
deductDpmFees,
|
||||
} from './calculate-dpm'
|
||||
import {
|
||||
calculateCpmmSale,
|
||||
|
@ -22,7 +22,7 @@ export const getSellBetInfo = (
|
|||
const { pool, totalShares, totalBets } = contract
|
||||
const { id: betId, amount, shares, outcome, loanAmount } = bet
|
||||
|
||||
const adjShareValue = calculateShareValue(contract, bet)
|
||||
const adjShareValue = calculateDpmShareValue(contract, bet)
|
||||
|
||||
const newPool = { ...pool, [outcome]: pool[outcome] - adjShareValue }
|
||||
|
||||
|
@ -33,12 +33,12 @@ export const getSellBetInfo = (
|
|||
|
||||
const newTotalBets = { ...totalBets, [outcome]: totalBets[outcome] - amount }
|
||||
|
||||
const probBefore = getProbability(totalShares)
|
||||
const probAfter = getProbability(newTotalShares)
|
||||
const probBefore = getDpmProbability(totalShares)
|
||||
const probAfter = getDpmProbability(newTotalShares)
|
||||
|
||||
const profit = adjShareValue - amount
|
||||
const creatorFee = CREATOR_FEE * Math.max(0, profit)
|
||||
const saleAmount = deductFees(amount, adjShareValue)
|
||||
const saleAmount = deductDpmFees(amount, adjShareValue)
|
||||
|
||||
console.log(
|
||||
'SELL M$',
|
||||
|
@ -94,7 +94,7 @@ export const getCpmmSellBetInfo = (
|
|||
|
||||
const profit = saleValue - amount
|
||||
const creatorFee = CREATOR_FEE * Math.max(0, profit)
|
||||
const saleAmount = deductFees(amount, profit)
|
||||
const saleAmount = deductDpmFees(amount, profit)
|
||||
|
||||
console.log(
|
||||
'SELL M$',
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import _ = require('lodash')
|
||||
import { Answer } from '../../common/answer'
|
||||
import { Bet } from '../../common/bet'
|
||||
import { getProbability } from '../../common/calculate-dpm'
|
||||
import { getDpmProbability } from '../../common/calculate-dpm'
|
||||
import { Comment } from '../../common/comment'
|
||||
import { Contract } from '../../common/contract'
|
||||
import { CREATOR_FEE } from '../../common/fees'
|
||||
|
@ -59,7 +59,7 @@ export const sendMarketResolutionEmail = async (
|
|||
const user = await getUser(userId)
|
||||
if (!user) return
|
||||
|
||||
const prob = resolutionProbability ?? getProbability(contract.totalShares)
|
||||
const prob = resolutionProbability ?? getDpmProbability(contract.totalShares)
|
||||
|
||||
const outcome = toDisplayResolution(resolution, prob, resolutions)
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ import * as _ from 'lodash'
|
|||
|
||||
import { getValues } from './utils'
|
||||
import { Contract } from '../../common/contract'
|
||||
import { getProbability } from '../../common/calculate-dpm'
|
||||
import { getDpmProbability } from '../../common/calculate-dpm'
|
||||
|
||||
const cache = { lastUpdated: 0, data: '' }
|
||||
|
||||
|
@ -50,7 +50,7 @@ const getContractInfo = ({
|
|||
description,
|
||||
url: `https://manifold.markets/${creatorUsername}/${slug}`,
|
||||
pool: pool.YES + pool.NO,
|
||||
probability: getProbability(totalShares),
|
||||
probability: getDpmProbability(totalShares),
|
||||
volume7Days,
|
||||
volume24Hours,
|
||||
isResolved,
|
||||
|
|
|
@ -5,7 +5,7 @@ import { initAdmin } from './script-init'
|
|||
initAdmin('stephen')
|
||||
|
||||
import { Bet } from '../../../common/bet'
|
||||
import { getProbability } from '../../../common/calculate-dpm'
|
||||
import { getDpmProbability } from '../../../common/calculate-dpm'
|
||||
import { Contract } from '../../../common/contract'
|
||||
|
||||
type DocRef = admin.firestore.DocumentReference
|
||||
|
@ -19,7 +19,7 @@ async function migrateContract(contractRef: DocRef, contract: Contract) {
|
|||
|
||||
const lastBet = _.sortBy(bets, (bet) => -bet.createdTime)[0]
|
||||
if (lastBet) {
|
||||
const probAfter = getProbability(contract.totalShares)
|
||||
const probAfter = getDpmProbability(contract.totalShares)
|
||||
|
||||
await firestore
|
||||
.doc(`contracts/${contract.id}/bets/${lastBet.id}`)
|
||||
|
|
|
@ -6,7 +6,10 @@ initAdmin('stephenDev')
|
|||
|
||||
import { Contract } from '../../../common/contract'
|
||||
import { Bet } from '../../../common/bet'
|
||||
import { calculateShares, getProbability } from '../../../common/calculate-dpm'
|
||||
import {
|
||||
calculateDpmShares,
|
||||
getDpmProbability,
|
||||
} from '../../../common/calculate-dpm'
|
||||
import { getSellBetInfo } from '../../../common/sell-bet'
|
||||
import { User } from '../../../common/user'
|
||||
|
||||
|
@ -126,7 +129,7 @@ async function recalculateContract(
|
|||
continue
|
||||
}
|
||||
|
||||
const shares = calculateShares(totalShares, bet.amount, bet.outcome)
|
||||
const shares = calculateDpmShares(totalShares, bet.amount, bet.outcome)
|
||||
const probBefore = p
|
||||
const ind = bet.outcome === 'YES' ? 1 : 0
|
||||
|
||||
|
@ -145,7 +148,7 @@ async function recalculateContract(
|
|||
NO: totalBets.NO + (1 - ind) * bet.amount,
|
||||
}
|
||||
|
||||
p = getProbability(totalShares)
|
||||
p = getDpmProbability(totalShares)
|
||||
|
||||
const probAfter = p
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ import { getValues } from './utils'
|
|||
import { Contract } from '../../common/contract'
|
||||
import { Bet } from '../../common/bet'
|
||||
import { User } from '../../common/user'
|
||||
import { calculatePayout } from '../../common/calculate-dpm'
|
||||
import { calculateDpmPayout } from '../../common/calculate-dpm'
|
||||
|
||||
const firestore = admin.firestore()
|
||||
|
||||
|
@ -52,7 +52,7 @@ const computeInvestmentValue = async (
|
|||
if (!contract || contract.isResolved) return 0
|
||||
if (bet.sale || bet.isSold) return 0
|
||||
|
||||
const payout = calculatePayout(contract, bet, 'MKT')
|
||||
const payout = calculateDpmPayout(contract, bet, 'MKT')
|
||||
return payout - (bet.loanAmount ?? 0)
|
||||
})
|
||||
}
|
||||
|
|
|
@ -18,10 +18,10 @@ import {
|
|||
import { InfoTooltip } from '../info-tooltip'
|
||||
import { useUser } from '../../hooks/use-user'
|
||||
import {
|
||||
getProbabilityAfterBet,
|
||||
getOutcomeProbability,
|
||||
calculateShares,
|
||||
calculatePayoutAfterCorrectBet,
|
||||
getDpmProbabilityAfterBet,
|
||||
getDpmOutcomeProbability,
|
||||
calculateDpmShares,
|
||||
calculateDpmPayoutAfterCorrectBet,
|
||||
} from '../../../common/calculate-dpm'
|
||||
import { firebaseLogin } from '../../lib/firebase/users'
|
||||
import { Bet } from '../../../common/bet'
|
||||
|
@ -76,18 +76,22 @@ export function AnswerBetPanel(props: {
|
|||
|
||||
const betDisabled = isSubmitting || !betAmount || error
|
||||
|
||||
const initialProb = getOutcomeProbability(contract.totalShares, answer.id)
|
||||
const initialProb = getDpmOutcomeProbability(contract.totalShares, answer.id)
|
||||
|
||||
const resultProb = getProbabilityAfterBet(
|
||||
const resultProb = getDpmProbabilityAfterBet(
|
||||
contract.totalShares,
|
||||
answerId,
|
||||
betAmount ?? 0
|
||||
)
|
||||
|
||||
const shares = calculateShares(contract.totalShares, betAmount ?? 0, answerId)
|
||||
const shares = calculateDpmShares(
|
||||
contract.totalShares,
|
||||
betAmount ?? 0,
|
||||
answerId
|
||||
)
|
||||
|
||||
const currentPayout = betAmount
|
||||
? calculatePayoutAfterCorrectBet(contract, {
|
||||
? calculateDpmPayoutAfterCorrectBet(contract, {
|
||||
outcome: answerId,
|
||||
amount: betAmount,
|
||||
shares,
|
||||
|
|
|
@ -10,7 +10,7 @@ import { Avatar } from '../avatar'
|
|||
import { SiteLink } from '../site-link'
|
||||
import { BuyButton } from '../yes-no-selector'
|
||||
import { formatPercent } from '../../../common/util/format'
|
||||
import { getOutcomeProbability } from '../../../common/calculate-dpm'
|
||||
import { getDpmOutcomeProbability } from '../../../common/calculate-dpm'
|
||||
import { tradingAllowed } from '../../lib/firebase/contracts'
|
||||
import { AnswerBetPanel } from './answer-bet-panel'
|
||||
import { ContractFeed } from '../contract-feed'
|
||||
|
@ -38,7 +38,7 @@ export function AnswerItem(props: {
|
|||
const { username, avatarUrl, name, number, text } = answer
|
||||
const isChosen = chosenProb !== undefined
|
||||
|
||||
const prob = getOutcomeProbability(totalShares, answer.id)
|
||||
const prob = getDpmOutcomeProbability(totalShares, answer.id)
|
||||
const roundedProb = Math.round(prob * 100)
|
||||
const probPercent = formatPercent(prob)
|
||||
const wasResolvedTo =
|
||||
|
|
|
@ -6,7 +6,7 @@ import { DPM, FreeResponse, FullContract } from '../../../common/contract'
|
|||
import { Col } from '../layout/col'
|
||||
import { formatPercent } from '../../../common/util/format'
|
||||
import { useUser } from '../../hooks/use-user'
|
||||
import { getOutcomeProbability } from '../../../common/calculate-dpm'
|
||||
import { getDpmOutcomeProbability } from '../../../common/calculate-dpm'
|
||||
import { useAnswers } from '../../hooks/use-answers'
|
||||
import { tradingAllowed } from '../../lib/firebase/contracts'
|
||||
import { AnswerItem } from './answer-item'
|
||||
|
@ -34,7 +34,7 @@ export function AnswersPanel(props: {
|
|||
),
|
||||
..._.sortBy(
|
||||
otherAnswers,
|
||||
(answer) => -1 * getOutcomeProbability(contract.totalShares, answer.id)
|
||||
(answer) => -1 * getDpmOutcomeProbability(contract.totalShares, answer.id)
|
||||
),
|
||||
]
|
||||
|
||||
|
@ -102,7 +102,7 @@ export function AnswersPanel(props: {
|
|||
) : (
|
||||
<div className="text-gray-500 self-end p-4">
|
||||
None of the above:{' '}
|
||||
{formatPercent(getOutcomeProbability(contract.totalShares, '0'))}
|
||||
{formatPercent(getDpmOutcomeProbability(contract.totalShares, '0'))}
|
||||
</div>
|
||||
)}
|
||||
|
||||
|
|
|
@ -21,9 +21,9 @@ import {
|
|||
import { InfoTooltip } from '../info-tooltip'
|
||||
import { useUser } from '../../hooks/use-user'
|
||||
import {
|
||||
getProbabilityAfterBet,
|
||||
calculateShares,
|
||||
calculatePayoutAfterCorrectBet,
|
||||
getDpmProbabilityAfterBet,
|
||||
calculateDpmShares,
|
||||
calculateDpmPayoutAfterCorrectBet,
|
||||
} from '../../../common/calculate-dpm'
|
||||
import { firebaseLogin } from '../../lib/firebase/users'
|
||||
import { Bet } from '../../../common/bet'
|
||||
|
@ -59,16 +59,16 @@ export function CreateAnswerPanel(props: {
|
|||
}
|
||||
}
|
||||
|
||||
const resultProb = getProbabilityAfterBet(
|
||||
const resultProb = getDpmProbabilityAfterBet(
|
||||
contract.totalShares,
|
||||
'new',
|
||||
betAmount ?? 0
|
||||
)
|
||||
|
||||
const shares = calculateShares(contract.totalShares, betAmount ?? 0, 'new')
|
||||
const shares = calculateDpmShares(contract.totalShares, betAmount ?? 0, 'new')
|
||||
|
||||
const currentPayout = betAmount
|
||||
? calculatePayoutAfterCorrectBet(contract, {
|
||||
? calculateDpmPayoutAfterCorrectBet(contract, {
|
||||
outcome: 'new',
|
||||
amount: betAmount,
|
||||
shares,
|
||||
|
|
|
@ -14,10 +14,10 @@ import {
|
|||
} from '../../common/util/format'
|
||||
import { Title } from './title'
|
||||
import {
|
||||
getProbability,
|
||||
calculateShares,
|
||||
getProbabilityAfterBet,
|
||||
calculatePayoutAfterCorrectBet,
|
||||
getDpmProbability,
|
||||
calculateDpmShares,
|
||||
getDpmProbabilityAfterBet,
|
||||
calculateDpmPayoutAfterCorrectBet,
|
||||
} from '../../common/calculate-dpm'
|
||||
import { firebaseLogin } from '../lib/firebase/users'
|
||||
import { Bet } from '../../common/bet'
|
||||
|
@ -107,23 +107,23 @@ export function BetPanel(props: {
|
|||
|
||||
const betDisabled = isSubmitting || !betAmount || error
|
||||
|
||||
const initialProb = getProbability(contract.totalShares)
|
||||
const initialProb = getDpmProbability(contract.totalShares)
|
||||
|
||||
const outcomeProb = getProbabilityAfterBet(
|
||||
const outcomeProb = getDpmProbabilityAfterBet(
|
||||
contract.totalShares,
|
||||
betChoice || 'YES',
|
||||
betAmount ?? 0
|
||||
)
|
||||
const resultProb = betChoice === 'NO' ? 1 - outcomeProb : outcomeProb
|
||||
|
||||
const shares = calculateShares(
|
||||
const shares = calculateDpmShares(
|
||||
contract.totalShares,
|
||||
betAmount ?? 0,
|
||||
betChoice || 'YES'
|
||||
)
|
||||
|
||||
const currentPayout = betAmount
|
||||
? calculatePayoutAfterCorrectBet(contract, {
|
||||
? calculateDpmPayoutAfterCorrectBet(contract, {
|
||||
outcome: betChoice,
|
||||
amount: betAmount,
|
||||
shares,
|
||||
|
|
|
@ -23,12 +23,12 @@ import {
|
|||
import { Row } from './layout/row'
|
||||
import { UserLink } from './user-page'
|
||||
import {
|
||||
calculatePayout,
|
||||
calculateSaleAmount,
|
||||
getOutcomeProbability,
|
||||
getProbability,
|
||||
getProbabilityAfterSale,
|
||||
resolvedPayout,
|
||||
calculateDpmPayout,
|
||||
calculateDpmSaleAmount,
|
||||
getDpmOutcomeProbability,
|
||||
getDpmProbability,
|
||||
getDpmProbabilityAfterSale,
|
||||
resolvedDpmPayout,
|
||||
} from '../../common/calculate-dpm'
|
||||
import { sellBet } from '../lib/firebase/api-call'
|
||||
import { ConfirmationButton } from './confirmation-button'
|
||||
|
@ -82,7 +82,7 @@ export function BetsList(props: { user: User }) {
|
|||
if (bet.isSold || bet.sale) return 0
|
||||
|
||||
const contract = contracts.find((c) => c.id === contractId)
|
||||
const payout = contract ? calculatePayout(contract, bet, 'MKT') : 0
|
||||
const payout = contract ? calculateDpmPayout(contract, bet, 'MKT') : 0
|
||||
return payout - (bet.loanAmount ?? 0)
|
||||
})
|
||||
}
|
||||
|
@ -288,21 +288,21 @@ export function MyBetsSummary(props: {
|
|||
const betsTotal = _.sumBy(excludeSales, (bet) => bet.amount)
|
||||
|
||||
const betsPayout = resolution
|
||||
? _.sumBy(excludeSales, (bet) => resolvedPayout(contract, bet))
|
||||
? _.sumBy(excludeSales, (bet) => resolvedDpmPayout(contract, bet))
|
||||
: 0
|
||||
|
||||
const yesWinnings = _.sumBy(excludeSales, (bet) =>
|
||||
calculatePayout(contract, bet, 'YES')
|
||||
calculateDpmPayout(contract, bet, 'YES')
|
||||
)
|
||||
const noWinnings = _.sumBy(excludeSales, (bet) =>
|
||||
calculatePayout(contract, bet, 'NO')
|
||||
calculateDpmPayout(contract, bet, 'NO')
|
||||
)
|
||||
|
||||
// const p = getProbability(contract.totalShares)
|
||||
// const expectation = p * yesWinnings + (1 - p) * noWinnings
|
||||
|
||||
const marketWinnings = _.sumBy(excludeSales, (bet) =>
|
||||
calculatePayout(contract, bet, 'MKT')
|
||||
calculateDpmPayout(contract, bet, 'MKT')
|
||||
)
|
||||
|
||||
const currentValue = resolution ? betsPayout : marketWinnings
|
||||
|
@ -385,7 +385,7 @@ export function MyBetsSummary(props: {
|
|||
<>
|
||||
Payout at{' '}
|
||||
<span className="text-blue-400">
|
||||
{formatPercent(getProbability(contract.totalShares))}
|
||||
{formatPercent(getDpmProbability(contract.totalShares))}
|
||||
</span>
|
||||
</>
|
||||
) : (
|
||||
|
@ -473,15 +473,15 @@ function BetRow(props: { bet: Bet; contract: Contract; saleBet?: Bet }) {
|
|||
) : (
|
||||
formatMoney(
|
||||
isResolved
|
||||
? resolvedPayout(contract, bet)
|
||||
: calculateSaleAmount(contract, bet)
|
||||
? resolvedDpmPayout(contract, bet)
|
||||
: calculateDpmSaleAmount(contract, bet)
|
||||
)
|
||||
)
|
||||
|
||||
const payoutIfChosenDisplay =
|
||||
bet.outcome === '0' && bet.isAnte
|
||||
? 'N/A'
|
||||
: formatMoney(calculatePayout(contract, bet, bet.outcome))
|
||||
: formatMoney(calculateDpmPayout(contract, bet, bet.outcome))
|
||||
|
||||
return (
|
||||
<tr>
|
||||
|
@ -519,18 +519,18 @@ function SellButton(props: { contract: Contract; bet: Bet }) {
|
|||
|
||||
const [isSubmitting, setIsSubmitting] = useState(false)
|
||||
|
||||
const initialProb = getOutcomeProbability(
|
||||
const initialProb = getDpmOutcomeProbability(
|
||||
contract.totalShares,
|
||||
outcome === 'NO' ? 'YES' : outcome
|
||||
)
|
||||
|
||||
const outcomeProb = getProbabilityAfterSale(
|
||||
const outcomeProb = getDpmProbabilityAfterSale(
|
||||
contract.totalShares,
|
||||
outcome,
|
||||
shares
|
||||
)
|
||||
|
||||
const saleAmount = calculateSaleAmount(contract, bet)
|
||||
const saleAmount = calculateDpmSaleAmount(contract, bet)
|
||||
|
||||
return (
|
||||
<ConfirmationButton
|
||||
|
|
|
@ -2,7 +2,7 @@ import { DatumValue } from '@nivo/core'
|
|||
import { ResponsiveLine } from '@nivo/line'
|
||||
import dayjs from 'dayjs'
|
||||
import { Bet } from '../../common/bet'
|
||||
import { getProbability } from '../../common/calculate-dpm'
|
||||
import { getDpmProbability } from '../../common/calculate-dpm'
|
||||
import { useBetsWithoutAntes } from '../hooks/use-bets'
|
||||
import { useWindowSize } from '../hooks/use-window-size'
|
||||
import { Contract } from '../lib/firebase/contracts'
|
||||
|
@ -13,7 +13,7 @@ export function ContractProbGraph(props: { contract: Contract; bets: Bet[] }) {
|
|||
|
||||
const bets = useBetsWithoutAntes(contract, props.bets)
|
||||
|
||||
const startProb = getProbability(
|
||||
const startProb = getDpmProbability(
|
||||
phantomShares as { [outcome: string]: number }
|
||||
)
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ import { Spacer } from './layout/spacer'
|
|||
import { ResolveConfirmationButton } from './confirmation-button'
|
||||
import { resolveMarket } from '../lib/firebase/api-call'
|
||||
import { ProbabilitySelector } from './probability-selector'
|
||||
import { getProbability } from '../../common/calculate-dpm'
|
||||
import { getDpmProbability } from '../../common/calculate-dpm'
|
||||
import { CREATOR_FEE } from '../../common/fees'
|
||||
|
||||
export function ResolutionPanel(props: {
|
||||
|
@ -29,7 +29,9 @@ export function ResolutionPanel(props: {
|
|||
'YES' | 'NO' | 'MKT' | 'CANCEL' | undefined
|
||||
>()
|
||||
|
||||
const [prob, setProb] = useState(getProbability(contract.totalShares) * 100)
|
||||
const [prob, setProb] = useState(
|
||||
getDpmProbability(contract.totalShares) * 100
|
||||
)
|
||||
|
||||
const [isSubmitting, setIsSubmitting] = useState(false)
|
||||
const [error, setError] = useState<string | undefined>(undefined)
|
||||
|
|
|
@ -18,7 +18,7 @@ import _ from 'lodash'
|
|||
import { app } from './init'
|
||||
import { getValues, listenForValue, listenForValues } from './utils'
|
||||
import { Binary, Contract, FullContract } from '../../../common/contract'
|
||||
import { getProbability } from '../../../common/calculate-dpm'
|
||||
import { getDpmProbability } from '../../../common/calculate-dpm'
|
||||
import { createRNG, shuffle } from '../../../common/util/random'
|
||||
import { getCpmmProbability } from '../../../common/calculate-cpmm'
|
||||
export type { Contract }
|
||||
|
@ -47,7 +47,7 @@ export function getBinaryProbPercent(contract: FullContract<any, Binary>) {
|
|||
const prob =
|
||||
resolutionProbability ?? mechanism === 'cpmm-1'
|
||||
? getCpmmProbability(pool)
|
||||
: getProbability(totalShares)
|
||||
: getDpmProbability(totalShares)
|
||||
|
||||
const probPercent = Math.round(prob * 100) + '%'
|
||||
return probPercent
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { Bet } from '../../../../common/bet'
|
||||
import { getProbability } from '../../../../common/calculate-dpm'
|
||||
import { getDpmProbability } from '../../../../common/calculate-dpm'
|
||||
import { Comment } from '../../../../common/comment'
|
||||
import { Contract } from '../../../../common/contract'
|
||||
|
||||
|
@ -72,7 +72,7 @@ export function toLiteMarket({
|
|||
tags,
|
||||
url: `https://manifold.markets/${creatorUsername}/${slug}`,
|
||||
pool: pool.YES + pool.NO,
|
||||
probability: getProbability(totalShares),
|
||||
probability: getDpmProbability(totalShares),
|
||||
volume7Days,
|
||||
volume24Hours,
|
||||
isResolved,
|
||||
|
|
|
@ -3,7 +3,7 @@ import dayjs from 'dayjs'
|
|||
import Link from 'next/link'
|
||||
import { useState } from 'react'
|
||||
import Textarea from 'react-expanding-textarea'
|
||||
import { getProbability } from '../../common/calculate-dpm'
|
||||
import { getDpmProbability } from '../../common/calculate-dpm'
|
||||
import { parseWordsAsTags } from '../../common/util/parse'
|
||||
import { AmountInput } from '../components/amount-input'
|
||||
import { InfoTooltip } from '../components/info-tooltip'
|
||||
|
@ -26,7 +26,7 @@ type Prediction = {
|
|||
}
|
||||
|
||||
function toPrediction(contract: Contract): Prediction {
|
||||
const startProb = getProbability(contract.totalShares)
|
||||
const startProb = getDpmProbability(contract.totalShares)
|
||||
return {
|
||||
question: contract.question,
|
||||
description: contract.description,
|
||||
|
|
Loading…
Reference in New Issue
Block a user