Change current value to uncapped sell value.
This commit is contained in:
parent
ff10aaf4e7
commit
cc38f35423
|
@ -68,19 +68,26 @@ export function BetsList(props: { user: User }) {
|
||||||
contracts,
|
contracts,
|
||||||
(contract) => contract.isResolved
|
(contract) => contract.isResolved
|
||||||
)
|
)
|
||||||
|
|
||||||
const currentBets = _.sumBy(unresolved, (contract) =>
|
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) =>
|
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 (
|
return (
|
||||||
<Col className="mt-6 gap-6">
|
<Col className="mt-6 gap-6">
|
||||||
<Row className="gap-8">
|
<Row className="gap-8">
|
||||||
<Col>
|
<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>
|
<div>{formatMoney(currentBets)}</div>
|
||||||
</Col>
|
</Col>
|
||||||
<Col>
|
<Col>
|
||||||
|
|
|
@ -51,14 +51,6 @@ export function calculatePayout(
|
||||||
const startPool = contract.startPool.YES + contract.startPool.NO
|
const startPool = contract.startPool.YES + contract.startPool.NO
|
||||||
const pool = contract.pool.YES + contract.pool.NO - startPool
|
const pool = contract.pool.YES + contract.pool.NO - startPool
|
||||||
|
|
||||||
console.log(
|
|
||||||
'calcPayout',
|
|
||||||
'shares',
|
|
||||||
shares,
|
|
||||||
'totalShares',
|
|
||||||
totalShares,
|
|
||||||
'pool'
|
|
||||||
)
|
|
||||||
return (1 - fees) * (shares / totalShares[outcome]) * 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) {
|
export function currentValue(contract: Contract, bet: Bet) {
|
||||||
const prob = getProbability(contract.pool)
|
// const prob = getProbability(contract.pool)
|
||||||
const yesPayout = calculatePayout(contract, bet, 'YES')
|
// const yesPayout = calculatePayout(contract, bet, 'YES')
|
||||||
const noPayout = calculatePayout(contract, bet, 'NO')
|
// const noPayout = calculatePayout(contract, bet, 'NO')
|
||||||
|
|
||||||
console.log('calculate value', {
|
// return prob * yesPayout + (1 - prob) * noPayout
|
||||||
prob,
|
|
||||||
yesPayout,
|
|
||||||
noPayout,
|
|
||||||
amount: bet.amount,
|
|
||||||
})
|
|
||||||
|
|
||||||
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) {
|
export function calculateSaleAmount(contract: Contract, bet: Bet) {
|
||||||
const { shares, outcome } = bet
|
const { shares, outcome } = bet
|
||||||
|
|
Loading…
Reference in New Issue
Block a user