Change current value to uncapped sell value.

This commit is contained in:
jahooma 2021-12-24 15:45:02 -05:00
parent ff10aaf4e7
commit cc38f35423
2 changed files with 38 additions and 21 deletions

View File

@ -68,19 +68,26 @@ export function BetsList(props: { user: User }) {
contracts,
(contract) => contract.isResolved
)
const currentBets = _.sumBy(unresolved, (contract) =>
_.sumBy(contractBets[contract.id], (bet) => bet.amount)
_.sumBy(contractBets[contract.id], (bet) => {
if (bet.isSold || bet.sale) return 0
return bet.amount
})
)
const currentBetsValue = _.sumBy(unresolved, (contract) =>
_.sumBy(contractBets[contract.id], (bet) => currentValue(contract, bet))
_.sumBy(contractBets[contract.id], (bet) => {
if (bet.isSold || bet.sale) return 0
return currentValue(contract, bet)
})
)
return (
<Col className="mt-6 gap-6">
<Row className="gap-8">
<Col>
<div className="text-sm text-gray-500">Active bets</div>
<div className="text-sm text-gray-500">Currently invested</div>
<div>{formatMoney(currentBets)}</div>
</Col>
<Col>

View File

@ -51,14 +51,6 @@ export function calculatePayout(
const startPool = contract.startPool.YES + contract.startPool.NO
const pool = contract.pool.YES + contract.pool.NO - startPool
console.log(
'calcPayout',
'shares',
shares,
'totalShares',
totalShares,
'pool'
)
return (1 - fees) * (shares / totalShares[outcome]) * pool
}
@ -69,18 +61,36 @@ export function resolvedPayout(contract: Contract, bet: Bet) {
}
export function currentValue(contract: Contract, bet: Bet) {
const prob = getProbability(contract.pool)
const yesPayout = calculatePayout(contract, bet, 'YES')
const noPayout = calculatePayout(contract, bet, 'NO')
// const prob = getProbability(contract.pool)
// const yesPayout = calculatePayout(contract, bet, 'YES')
// const noPayout = calculatePayout(contract, bet, 'NO')
console.log('calculate value', {
prob,
yesPayout,
noPayout,
amount: bet.amount,
})
// return prob * yesPayout + (1 - prob) * noPayout
return prob * yesPayout + (1 - prob) * noPayout
const { shares, outcome } = bet
const { YES: yesPool, NO: noPool } = contract.pool
const [y, n, s] = [yesPool, noPool, shares]
const shareValue =
outcome === 'YES'
? // https://www.wolframalpha.com/input/?i=b+%2B+%28b+n%5E2%29%2F%28y+%28-b+%2B+y%29%29+%3D+c+solve+b
(n ** 2 +
s * y +
y ** 2 -
Math.sqrt(
n ** 4 + (s - y) ** 2 * y ** 2 + 2 * n ** 2 * y * (s + y)
)) /
(2 * y)
: (y ** 2 +
s * n +
n ** 2 -
Math.sqrt(
y ** 4 + (s - n) ** 2 * n ** 2 + 2 * y ** 2 * n * (s + n)
)) /
(2 * n)
return (1 - fees) * shareValue
}
export function calculateSaleAmount(contract: Contract, bet: Bet) {
const { shares, outcome } = bet