Calculate weights, probs, and payoffs

This commit is contained in:
Austin Chen 2021-11-30 17:49:34 -08:00
parent 81c6da7c58
commit 14402118bf
2 changed files with 47 additions and 10 deletions

View File

@ -6,17 +6,23 @@
<th>Order #</th> <th>Order #</th>
<th>Yes bid</th> <th>Yes bid</th>
<th>No Bid</th> <th>No Bid</th>
<th>Yes Weight</th>
<th>No Weight</th>
<th>Implied Probability</th> <th>Implied Probability</th>
<th>Payout</th> <th>Yes Payout</th>
<th>No Payout</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<tr v-for="(entry, i) in entries"> <tr v-for="(entry, i) in entries">
<th>{{ i }}</th> <th>{{ i + 1 }}</th>
<td>{{ entry.yesBid || '' }}</td> <td>{{ entry.yesBid || '' }}</td>
<td>{{ entry.noBid || '' }}</td> <td>{{ entry.noBid || '' }}</td>
<td>{{ entry.yesWeight || '' }}</td>
<td>{{ entry.noWeight || '' }}</td>
<td>{{ entry.prob }}</td> <td>{{ entry.prob }}</td>
<td>{{ entry.payout }}</td> <td>{{ entry.yesPayout }}</td>
<td>{{ entry.noPayout }}</td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
@ -26,9 +32,41 @@
<script setup lang="ts"> <script setup lang="ts">
import { bids } from './orders' import { bids } from './orders'
const entries = bids.map((bid) => ({ const entries = [] as any
...bid, const YES_SEED = 1
prob: 0.646, const NO_SEED = 9
payout: 1.23, let yesPot = 0
})) let noPot = 0
let yesWeightSum = 0
let noWeightSum = 0
for (const bid of bids) {
const { yesBid, noBid } = bid
const yesWeight = noPot * (Math.log(yesBid + yesPot) - Math.log(yesPot)) || 0
const noWeight = yesPot * (Math.log(noBid + noPot) - Math.log(noPot)) || 0
// Note: Need to calculate weights BEFORE updating pot
yesPot += yesBid
noPot += noBid
const prob = yesPot / (yesPot + noPot)
// Payout: You get your initial bid back, as well as your share of the
// (noPot - seed) according to your yesWeight
yesWeightSum += yesWeight
noWeightSum += noWeight
// This only represents the payout if the market were to close immediately.
// TODO: use refs to reactively update the payout
const yesPayout = yesBid + (yesWeight / yesWeightSum) * (noPot - NO_SEED)
const noPayout = noBid + (noWeight / noWeightSum) * (yesPot - YES_SEED)
entries.push({
yesBid,
noBid,
// Show two decimal places
yesWeight: yesWeight.toFixed(2),
noWeight: noWeight.toFixed(2),
prob: prob.toFixed(2),
yesPayout: yesPayout.toFixed(2),
noPayout: noPayout.toFixed(2),
})
}
</script> </script>

View File

@ -43,8 +43,7 @@ const data = `1,9
10, 10,
,10 ,10
10, 10,
,10 ,10`
`
// Parse data into Yes/No orders // Parse data into Yes/No orders
// E.g. `8,\n,1\n1,` => // E.g. `8,\n,1\n1,` =>