From 0af1fb8d4acb5a3178cc78c229e3e651fda30580 Mon Sep 17 00:00:00 2001 From: James Grugett Date: Thu, 17 Feb 2022 13:00:33 -0600 Subject: [PATCH] Show bet probability change and payout when creating answer --- common/calculate.ts | 10 +++-- web/components/answers-panel.tsx | 70 ++++++++++++++++++++++++++------ 2 files changed, 65 insertions(+), 15 deletions(-) diff --git a/common/calculate.ts b/common/calculate.ts index 865d8caf..3dbb6daf 100644 --- a/common/calculate.ts +++ b/common/calculate.ts @@ -156,19 +156,23 @@ export function calculatePayoutAfterCorrectBet(contract: Contract, bet: Bet) { const { totalShares, pool, totalBets } = contract const { shares, amount, outcome } = bet + const prevShares = totalShares[outcome] ?? 0 + const prevPool = pool[outcome] ?? 0 + const prevTotalBet = totalBets[outcome] ?? 0 + const newContract = { ...contract, totalShares: { ...totalShares, - [outcome]: totalShares[outcome] + shares, + [outcome]: prevShares + shares, }, pool: { ...pool, - [outcome]: pool[outcome] + amount, + [outcome]: prevPool + amount, }, totalBets: { ...totalBets, - [outcome]: totalBets[outcome] + amount, + [outcome]: prevTotalBet + amount, }, } diff --git a/web/components/answers-panel.tsx b/web/components/answers-panel.tsx index 7e34c533..3f54600e 100644 --- a/web/components/answers-panel.tsx +++ b/web/components/answers-panel.tsx @@ -376,6 +376,25 @@ function CreateAnswerInput(props: { contract: Contract }) { } } + const resultProb = getProbabilityAfterBet( + contract.totalShares, + 'new', + betAmount ?? 0 + ) + + const shares = calculateShares(contract.totalShares, betAmount ?? 0, 'new') + + const currentPayout = betAmount + ? calculatePayoutAfterCorrectBet(contract, { + outcome: 'new', + amount: betAmount, + shares, + } as Bet) + : 0 + + const currentReturn = betAmount ? (currentPayout - betAmount) / betAmount : 0 + const currentReturnPercent = (currentReturn * 100).toFixed() + '%' + return ( @@ -390,20 +409,47 @@ function CreateAnswerInput(props: { contract: Contract }) { />
{text && ( - -
Bet amount
- - + <> + +
+ Ante bet (cannot be sold) +
+ + + +
Implied probability
+ +
{formatPercent(0)}
+
+
{formatPercent(resultProb)}
+
+ + Payout if chosen + + +
+ {formatMoney(currentPayout)} +   (+{currentReturnPercent}) +
+ + )}