Allow scrubbing forwards and backwards on the simulation
This commit is contained in:
parent
dff7cf39c4
commit
b3f156e4ef
|
@ -1,5 +1,14 @@
|
||||||
<template>
|
<template>
|
||||||
<div class="overflow-x-auto px-12">
|
<div class="overflow-x-auto px-12">
|
||||||
|
<label>Simulation step: {{ steps }} </label>
|
||||||
|
<input
|
||||||
|
class="range"
|
||||||
|
type="range"
|
||||||
|
v-model="steps"
|
||||||
|
min="1"
|
||||||
|
:max="entries.length"
|
||||||
|
/>
|
||||||
|
|
||||||
<table class="table">
|
<table class="table">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
|
@ -14,13 +23,13 @@
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr v-for="(entry, i) in entries">
|
<tr v-for="(entry, i) in truncatedEntries">
|
||||||
<th>{{ i + 1 }}</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.yesWeight.toFixed(2) || '' }}</td>
|
||||||
<td>{{ entry.noWeight || '' }}</td>
|
<td>{{ entry.noWeight.toFixed(2) || '' }}</td>
|
||||||
<td>{{ entry.prob }}</td>
|
<td>{{ entry.prob.toFixed(2) }}</td>
|
||||||
<td>{{ entry.yesPayout.value.toFixed(2) }}</td>
|
<td>{{ entry.yesPayout.value.toFixed(2) }}</td>
|
||||||
<td>{{ entry.noPayout.value.toFixed(2) }}</td>
|
<td>{{ entry.noPayout.value.toFixed(2) }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
@ -40,11 +49,23 @@ const NO_SEED = 9
|
||||||
// Regular variables
|
// Regular variables
|
||||||
let yesPot = 0
|
let yesPot = 0
|
||||||
let noPot = 0
|
let noPot = 0
|
||||||
// Reactive variables
|
// UI parameters
|
||||||
const yesPotRef = ref(0)
|
const steps = ref(10)
|
||||||
const noPotRef = ref(0)
|
|
||||||
const yesWeightsRef = ref(0)
|
// Computed variables: stop the simulation at the appropriate number of steps
|
||||||
const noWeightsRef = ref(0)
|
const truncatedEntries = computed(() => entries.slice(0, steps.value))
|
||||||
|
const yesPotC = computed(() =>
|
||||||
|
truncatedEntries.value.reduce((acc, entry) => acc + entry.yesBid, 0)
|
||||||
|
)
|
||||||
|
const noPotC = computed(() =>
|
||||||
|
truncatedEntries.value.reduce((acc, entry) => acc + entry.noBid, 0)
|
||||||
|
)
|
||||||
|
const yesWeightsC = computed(() =>
|
||||||
|
truncatedEntries.value.reduce((acc, entry) => acc + entry.yesWeight, 0)
|
||||||
|
)
|
||||||
|
const noWeightsC = computed(() =>
|
||||||
|
truncatedEntries.value.reduce((acc, entry) => acc + entry.noWeight, 0)
|
||||||
|
)
|
||||||
|
|
||||||
// Calculations:
|
// Calculations:
|
||||||
for (const bid of bids) {
|
for (const bid of bids) {
|
||||||
|
@ -59,29 +80,23 @@ for (const bid of bids) {
|
||||||
|
|
||||||
// Payout: You get your initial bid back, as well as your share of the
|
// Payout: You get your initial bid back, as well as your share of the
|
||||||
// (noPot - seed) according to your yesWeight
|
// (noPot - seed) according to your yesWeight
|
||||||
yesWeightsRef.value += yesWeight
|
|
||||||
noWeightsRef.value += noWeight
|
|
||||||
const yesPayout = computed(
|
const yesPayout = computed(
|
||||||
() =>
|
() => yesBid + (yesWeight / yesWeightsC.value) * (noPotC.value - NO_SEED)
|
||||||
yesBid + (yesWeight / yesWeightsRef.value) * (noPotRef.value - NO_SEED)
|
|
||||||
)
|
)
|
||||||
const noPayout = computed(
|
const noPayout = computed(
|
||||||
() => noBid + (noWeight / noWeightsRef.value) * (yesPotRef.value - YES_SEED)
|
() => noBid + (noWeight / noWeightsC.value) * (yesPotC.value - YES_SEED)
|
||||||
)
|
)
|
||||||
|
|
||||||
entries.push({
|
entries.push({
|
||||||
yesBid,
|
yesBid,
|
||||||
noBid,
|
noBid,
|
||||||
// Show two decimal places
|
// Show two decimal places
|
||||||
yesWeight: yesWeight.toFixed(2),
|
yesWeight: yesWeight,
|
||||||
noWeight: noWeight.toFixed(2),
|
noWeight: noWeight,
|
||||||
prob: prob.toFixed(2),
|
prob: prob,
|
||||||
// These are reactive, so fix decimal places in HTML template
|
// These are reactive, so fix decimal places in HTML template
|
||||||
yesPayout,
|
yesPayout,
|
||||||
noPayout,
|
noPayout,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
yesPotRef.value = yesPot
|
|
||||||
noPotRef.value = noPot
|
|
||||||
</script>
|
</script>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user