Include a chart of the probabilities over time

This commit is contained in:
Austin Chen 2021-12-01 00:08:39 -08:00
parent d52570998d
commit 58fcf4d132
3 changed files with 77 additions and 32 deletions

View File

@ -7,6 +7,7 @@
"serve": "vite preview" "serve": "vite preview"
}, },
"dependencies": { "dependencies": {
"chart.js": "^3.6.1",
"daisyui": "^1.16.0", "daisyui": "^1.16.0",
"firebase": "^9.4.1", "firebase": "^9.4.1",
"vue": "^3.2.16" "vue": "^3.2.16"

View File

@ -4,47 +4,56 @@
<input <input
class="range" class="range"
type="range" type="range"
v-model="steps" v-model.number="steps"
min="1" min="1"
:max="entries.length" :max="entries.length"
/> />
<!-- Two-column layout (on large screen sizes) -->
<table class="table"> <div class="grid grid-cols-1 lg:grid-cols-2">
<thead> <div>
<tr> <canvas id="simChart" width="400" height="400"></canvas>
<th>Order #</th> </div>
<th>Yes bid</th> <div>
<th>No Bid</th> <table class="table">
<th>Yes Weight</th> <thead>
<th>No Weight</th> <tr>
<th>Implied Probability</th> <th>Order #</th>
<th>Yes Payout</th> <th>Yes bid</th>
<th>No Payout</th> <th>No Bid</th>
<th>Yes Return</th> <th>Yes Weight</th>
<th>No Return</th> <th>No Weight</th>
</tr> <th>Implied Probability</th>
</thead> <th>Yes Payout</th>
<tbody> <th>No Payout</th>
<tr v-for="(entry, i) in truncatedEntries"> <th>Yes Return</th>
<th>{{ i + 1 }}</th> <th>No Return</th>
<td>{{ entry.yesBid || '' }}</td> </tr>
<td>{{ entry.noBid || '' }}</td> </thead>
<td>{{ entry.yesWeight.toFixed(2) || '' }}</td> <tbody>
<td>{{ entry.noWeight.toFixed(2) || '' }}</td> <tr v-for="(entry, i) in truncatedEntries">
<td>{{ entry.prob.toFixed(2) || '' }}</td> <th>{{ i + 1 }}</th>
<td>{{ entry.yesPayout.value.toFixed(2) || '' }}</td> <td>{{ entry.yesBid || '' }}</td>
<td>{{ entry.noPayout.value.toFixed(2) || '' }}</td> <td>{{ entry.noBid || '' }}</td>
<td>{{ (entry.yesReturn.value * 100).toFixed(2) || '' }}%</td> <td>{{ entry.yesWeight.toFixed(2) || '' }}</td>
<td>{{ (entry.noReturn.value * 100).toFixed(2) || '' }}%</td> <td>{{ entry.noWeight.toFixed(2) || '' }}</td>
</tr> <td>{{ entry.prob.toFixed(2) || '' }}</td>
</tbody> <td>{{ entry.yesPayout.value.toFixed(2) || '' }}</td>
</table> <td>{{ entry.noPayout.value.toFixed(2) || '' }}</td>
<td>{{ (entry.yesReturn.value * 100).toFixed(2) || '' }}%</td>
<td>{{ (entry.noReturn.value * 100).toFixed(2) || '' }}%</td>
</tr>
</tbody>
</table>
</div>
</div>
</div> </div>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import Chart from 'chart.js/auto'
import { bids } from './orders' import { bids } from './orders'
import { ref, computed } from '@vue/reactivity' import { ref, computed } from '@vue/reactivity'
import { onMounted, watch } from '@vue/runtime-core'
const entries = [] as any const entries = [] as any
// Constants // Constants
@ -107,4 +116,34 @@ for (const bid of bids) {
noReturn, noReturn,
}) })
} }
// Graph the probabilities over time
const probs = computed(() => truncatedEntries.value.map((entry) => entry.prob))
onMounted(initChart)
watch(steps, renderChart)
let chart: Chart
function initChart() {
const ctx = document.getElementById('simChart')
chart = new Chart(ctx as any, {
type: 'line',
data: {
labels: [...Array(steps.value).keys()],
datasets: [
{
label: 'Implied probability',
data: probs.value,
borderColor: 'rgb(75, 192, 192)',
},
],
},
})
}
function renderChart() {
chart.data.labels = [...Array(steps.value).keys()]
chart.data.datasets[0].data = probs.value
chart.update()
}
</script> </script>

View File

@ -762,6 +762,11 @@ character-parser@^2.2.0:
dependencies: dependencies:
is-regex "^1.0.3" is-regex "^1.0.3"
chart.js@^3.6.1:
version "3.6.1"
resolved "https://registry.yarnpkg.com/chart.js/-/chart.js-3.6.1.tgz#edcb6584b8d810306f655f89538c00a4f440c58e"
integrity sha512-AycnixR0I325Fp3bqQ7wRJbkIJPwz/9IZtUBvdBWMjK5+nKCy6FZ3VejkDTtB9udePEXNt1UYoGTsNL49JoIbg==
cliui@^7.0.2: cliui@^7.0.2:
version "7.0.4" version "7.0.4"
resolved "https://registry.yarnpkg.com/cliui/-/cliui-7.0.4.tgz#a0265ee655476fc807aea9df3df8df7783808b4f" resolved "https://registry.yarnpkg.com/cliui/-/cliui-7.0.4.tgz#a0265ee655476fc807aea9df3df8df7783808b4f"