Update simulator to use new calculations
This commit is contained in:
parent
cbdeef4425
commit
aa6d4661fe
|
@ -21,10 +21,13 @@ function makeWeights(bids: Bid[]) {
|
||||||
// First pass: calculate all the weights
|
// First pass: calculate all the weights
|
||||||
for (const { yesBid, noBid } of bids) {
|
for (const { yesBid, noBid } of bids) {
|
||||||
const yesWeight =
|
const yesWeight =
|
||||||
(yesBid * Math.pow(noPot, 2)) / (Math.pow(yesPot, 2) + yesBid * yesPot) ||
|
yesBid +
|
||||||
0
|
(yesBid * Math.pow(noPot, 2)) /
|
||||||
|
(Math.pow(yesPot, 2) + yesBid * yesPot) || 0
|
||||||
const noWeight =
|
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
|
// Note: Need to calculate weights BEFORE updating pot
|
||||||
yesPot += yesBid
|
yesPot += yesBid
|
||||||
|
@ -53,15 +56,15 @@ export function makeEntries(bids: Bid[]): Entry[] {
|
||||||
const yesWeightsSum = weights.reduce((sum, entry) => sum + entry.yesWeight, 0)
|
const yesWeightsSum = weights.reduce((sum, entry) => sum + entry.yesWeight, 0)
|
||||||
const noWeightsSum = weights.reduce((sum, entry) => sum + entry.noWeight, 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
|
// Second pass: calculate all the payouts
|
||||||
const entries: Entry[] = []
|
const entries: Entry[] = []
|
||||||
|
|
||||||
for (const weight of weights) {
|
for (const weight of weights) {
|
||||||
const { yesBid, noBid, yesWeight, noWeight } = weight
|
const { yesBid, noBid, yesWeight, noWeight } = weight
|
||||||
// Payout: You get your initial bid back, as well as your share of the
|
const yesPayout = (yesWeight / yesWeightsSum) * potSize
|
||||||
// (noPot - seed) according to your yesWeight
|
const noPayout = (noWeight / noWeightsSum) * potSize
|
||||||
const yesPayout = yesBid + (yesWeight / yesWeightsSum) * (noPot - NO_SEED)
|
|
||||||
const noPayout = noBid + (noWeight / noWeightsSum) * (yesPot - YES_SEED)
|
|
||||||
const yesReturn = (yesPayout - yesBid) / yesBid
|
const yesReturn = (yesPayout - yesBid) / yesBid
|
||||||
const noReturn = (noPayout - noBid) / noBid
|
const noReturn = (noPayout - noBid) / noBid
|
||||||
entries.push({ ...weight, yesPayout, noPayout, yesReturn, noReturn })
|
entries.push({ ...weight, yesPayout, noPayout, yesReturn, noReturn })
|
||||||
|
|
|
@ -86,7 +86,7 @@ function TableRowEnd(props: { entry: Entry | null; isNew?: boolean }) {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<td>{(entry.prob * 100).toFixed(1)}%</td>
|
<td>{(entry.prob * 100).toFixed(1)}%</td>
|
||||||
<td>${(entry.yesBid + entry.yesWeight).toFixed(0)}</td>
|
<td>${entry.yesWeight.toFixed(0)}</td>
|
||||||
{!props.isNew && (
|
{!props.isNew && (
|
||||||
<>
|
<>
|
||||||
<td>${entry.yesPayout.toFixed(0)}</td>
|
<td>${entry.yesPayout.toFixed(0)}</td>
|
||||||
|
@ -99,7 +99,7 @@ function TableRowEnd(props: { entry: Entry | null; isNew?: boolean }) {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<td>{(entry.prob * 100).toFixed(1)}%</td>
|
<td>{(entry.prob * 100).toFixed(1)}%</td>
|
||||||
<td>${(entry.noBid + entry.noWeight).toFixed(0)}</td>
|
<td>${entry.noWeight.toFixed(0)}</td>
|
||||||
{!props.isNew && (
|
{!props.isNew && (
|
||||||
<>
|
<>
|
||||||
<td>${entry.noPayout.toFixed(0)}</td>
|
<td>${entry.noPayout.toFixed(0)}</td>
|
||||||
|
@ -238,7 +238,7 @@ function NewBidTable(props: {
|
||||||
// Show a hello world React page
|
// Show a hello world React page
|
||||||
export default function Simulator() {
|
export default function Simulator() {
|
||||||
const [steps, setSteps] = useState(1)
|
const [steps, setSteps] = useState(1)
|
||||||
const [bids, setBids] = useState([{ yesBid: 550, noBid: 450 }])
|
const [bids, setBids] = useState([{ yesBid: 100, noBid: 100 }])
|
||||||
|
|
||||||
const entries = useMemo(
|
const entries = useMemo(
|
||||||
() => makeEntries(bids.slice(0, steps)),
|
() => makeEntries(bids.slice(0, steps)),
|
||||||
|
|
Loading…
Reference in New Issue
Block a user