Update simulator to use new calculations

This commit is contained in:
jahooma 2021-12-23 12:18:34 -05:00
parent cbdeef4425
commit aa6d4661fe
2 changed files with 13 additions and 10 deletions

View File

@ -21,10 +21,13 @@ function makeWeights(bids: Bid[]) {
// First pass: calculate all the weights
for (const { yesBid, noBid } of bids) {
const yesWeight =
(yesBid * Math.pow(noPot, 2)) / (Math.pow(yesPot, 2) + yesBid * yesPot) ||
0
yesBid +
(yesBid * Math.pow(noPot, 2)) /
(Math.pow(yesPot, 2) + yesBid * yesPot) || 0
const noWeight =
(noBid * Math.pow(yesPot, 2)) / (Math.pow(noPot, 2) + noBid * noPot) || 0
noBid +
(noBid * Math.pow(yesPot, 2)) / (Math.pow(noPot, 2) + noBid * noPot) ||
0
// Note: Need to calculate weights BEFORE updating pot
yesPot += yesBid
@ -53,15 +56,15 @@ export function makeEntries(bids: Bid[]): Entry[] {
const yesWeightsSum = weights.reduce((sum, entry) => sum + entry.yesWeight, 0)
const noWeightsSum = weights.reduce((sum, entry) => sum + entry.noWeight, 0)
const potSize = yesPot + noPot - YES_SEED - NO_SEED
// Second pass: calculate all the payouts
const entries: Entry[] = []
for (const weight of weights) {
const { yesBid, noBid, yesWeight, noWeight } = weight
// Payout: You get your initial bid back, as well as your share of the
// (noPot - seed) according to your yesWeight
const yesPayout = yesBid + (yesWeight / yesWeightsSum) * (noPot - NO_SEED)
const noPayout = noBid + (noWeight / noWeightsSum) * (yesPot - YES_SEED)
const yesPayout = (yesWeight / yesWeightsSum) * potSize
const noPayout = (noWeight / noWeightsSum) * potSize
const yesReturn = (yesPayout - yesBid) / yesBid
const noReturn = (noPayout - noBid) / noBid
entries.push({ ...weight, yesPayout, noPayout, yesReturn, noReturn })

View File

@ -86,7 +86,7 @@ function TableRowEnd(props: { entry: Entry | null; isNew?: boolean }) {
return (
<>
<td>{(entry.prob * 100).toFixed(1)}%</td>
<td>${(entry.yesBid + entry.yesWeight).toFixed(0)}</td>
<td>${entry.yesWeight.toFixed(0)}</td>
{!props.isNew && (
<>
<td>${entry.yesPayout.toFixed(0)}</td>
@ -99,7 +99,7 @@ function TableRowEnd(props: { entry: Entry | null; isNew?: boolean }) {
return (
<>
<td>{(entry.prob * 100).toFixed(1)}%</td>
<td>${(entry.noBid + entry.noWeight).toFixed(0)}</td>
<td>${entry.noWeight.toFixed(0)}</td>
{!props.isNew && (
<>
<td>${entry.noPayout.toFixed(0)}</td>
@ -238,7 +238,7 @@ function NewBidTable(props: {
// Show a hello world React page
export default function Simulator() {
const [steps, setSteps] = useState(1)
const [bids, setBids] = useState([{ yesBid: 550, noBid: 450 }])
const [bids, setBids] = useState([{ yesBid: 100, noBid: 100 }])
const entries = useMemo(
() => makeEntries(bids.slice(0, steps)),