Initial commit — options pricing dashboard
Full-stack options analytics app: IV surface, Greeks, skew metrics, vol term structure. Yahoo Finance data with Black-Scholes IV computation and historical vol fallback for after-hours data. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
714
frontend/tracker.html
Normal file
714
frontend/tracker.html
Normal file
@@ -0,0 +1,714 @@
|
||||
<!doctype html>
|
||||
<html lang="en" data-bs-theme="dark">
|
||||
<head>
|
||||
<meta charset="utf-8"/>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover"/>
|
||||
<meta http-equiv="X-UA-Compatible" content="ie=edge"/>
|
||||
<title>Options Metrics Tracker</title>
|
||||
|
||||
<link rel="stylesheet" href="/assets/tabler.min.css"/>
|
||||
<link rel="stylesheet" href="/assets/tabler-vendors.min.css"/>
|
||||
<script src="/assets/apexcharts.min.js"></script>
|
||||
<script src="/assets/alpine.min.js" defer></script>
|
||||
<script src="/assets/tabler.min.js" defer></script>
|
||||
|
||||
<style>
|
||||
:root {
|
||||
--chart-bg: #1a1c23;
|
||||
--chart-grid: rgba(255, 255, 255, 0.06);
|
||||
--chart-label: #8b95a1;
|
||||
}
|
||||
|
||||
body {
|
||||
background-color: #1a1c23;
|
||||
}
|
||||
|
||||
.navbar-vertical.navbar-dark {
|
||||
background-color: #14161c;
|
||||
border-right: 1px solid rgba(255, 255, 255, 0.07);
|
||||
}
|
||||
|
||||
.chart-card {
|
||||
background-color: var(--chart-bg);
|
||||
border: 1px solid rgba(255, 255, 255, 0.07);
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
.apexcharts-canvas {
|
||||
background: transparent !important;
|
||||
}
|
||||
|
||||
.table-snapshots th {
|
||||
font-size: 0.75rem;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.06em;
|
||||
color: var(--chart-label);
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.toolbar-bar {
|
||||
background-color: #14161c;
|
||||
border-bottom: 1px solid rgba(255, 255, 255, 0.07);
|
||||
}
|
||||
|
||||
.nav-link.active-page {
|
||||
color: #4fc3f7 !important;
|
||||
background-color: rgba(79, 195, 247, 0.1) !important;
|
||||
border-radius: 6px;
|
||||
}
|
||||
|
||||
.badge-fat-tails {
|
||||
background-color: #f59f00;
|
||||
color: #1a1c23;
|
||||
}
|
||||
|
||||
.badge-thin-tails {
|
||||
background-color: #d63939;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.badge-normal {
|
||||
background-color: rgba(255, 255, 255, 0.1);
|
||||
color: #8b95a1;
|
||||
}
|
||||
|
||||
.snapshot-count-badge {
|
||||
font-size: 0.7rem;
|
||||
padding: 2px 8px;
|
||||
border-radius: 12px;
|
||||
background-color: rgba(79, 195, 247, 0.15);
|
||||
color: #4fc3f7;
|
||||
border: 1px solid rgba(79, 195, 247, 0.3);
|
||||
font-weight: 600;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
[x-cloak] { display: none !important; }
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body class="antialiased" x-data="trackerApp()" x-init="init()">
|
||||
<div class="wrapper">
|
||||
|
||||
<!-- Vertical Sidebar -->
|
||||
<aside class="navbar navbar-vertical navbar-expand-lg" data-bs-theme="dark">
|
||||
<div class="container-fluid">
|
||||
|
||||
<!-- Toggle for mobile -->
|
||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#sidebar-menu">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
|
||||
<!-- Logo -->
|
||||
<h1 class="navbar-brand navbar-brand-autodark">
|
||||
<a href="index.html" class="text-decoration-none d-flex align-items-center gap-2">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="28" height="28" viewBox="0 0 24 24" fill="none"
|
||||
stroke="#4fc3f7" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||
<polyline points="22 7 13.5 15.5 8.5 10.5 2 17"></polyline>
|
||||
<polyline points="16 7 22 7 22 13"></polyline>
|
||||
</svg>
|
||||
<span class="fw-bold" style="color:#4fc3f7; font-size:1rem; letter-spacing:0.04em;">OPTIONS PRICER</span>
|
||||
</a>
|
||||
</h1>
|
||||
|
||||
<!-- Nav links -->
|
||||
<div class="collapse navbar-collapse" id="sidebar-menu">
|
||||
<ul class="navbar-nav pt-lg-3">
|
||||
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="index.html">
|
||||
<span class="nav-link-icon d-md-none d-lg-inline-block">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24"
|
||||
fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||
<rect x="3" y="3" width="7" height="7"></rect><rect x="14" y="3" width="7" height="7"></rect>
|
||||
<rect x="14" y="14" width="7" height="7"></rect><rect x="3" y="14" width="7" height="7"></rect>
|
||||
</svg>
|
||||
</span>
|
||||
<span class="nav-link-title">Dashboard</span>
|
||||
</a>
|
||||
</li>
|
||||
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="chain.html">
|
||||
<span class="nav-link-icon d-md-none d-lg-inline-block">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24"
|
||||
fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||
<line x1="8" y1="6" x2="21" y2="6"></line><line x1="8" y1="12" x2="21" y2="12"></line>
|
||||
<line x1="8" y1="18" x2="21" y2="18"></line>
|
||||
<line x1="3" y1="6" x2="3.01" y2="6"></line><line x1="3" y1="12" x2="3.01" y2="12"></line>
|
||||
<line x1="3" y1="18" x2="3.01" y2="18"></line>
|
||||
</svg>
|
||||
</span>
|
||||
<span class="nav-link-title">Options Chain</span>
|
||||
</a>
|
||||
</li>
|
||||
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="surface.html">
|
||||
<span class="nav-link-icon d-md-none d-lg-inline-block">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24"
|
||||
fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||
<path d="M3 3l7 7 4-4 7 7"></path>
|
||||
<path d="M21 17v4h-4"></path>
|
||||
</svg>
|
||||
</span>
|
||||
<span class="nav-link-title">Vol Surface</span>
|
||||
</a>
|
||||
</li>
|
||||
|
||||
<li class="nav-item">
|
||||
<a class="nav-link active-page" href="tracker.html">
|
||||
<span class="nav-link-icon d-md-none d-lg-inline-block">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24"
|
||||
fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||
<circle cx="12" cy="12" r="10"></circle>
|
||||
<polyline points="12 6 12 12 16 14"></polyline>
|
||||
</svg>
|
||||
</span>
|
||||
<span class="nav-link-title">Tracker</span>
|
||||
</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</aside>
|
||||
|
||||
<!-- Main content -->
|
||||
<div class="page-wrapper">
|
||||
|
||||
<!-- Toolbar -->
|
||||
<div class="toolbar-bar py-2 px-3 mb-3">
|
||||
<div class="container-xl">
|
||||
<div class="d-flex flex-wrap align-items-center gap-3">
|
||||
|
||||
<!-- Symbol input -->
|
||||
<div class="input-group input-group-sm" style="max-width:140px;">
|
||||
<span class="input-group-text bg-dark border-secondary text-muted">Symbol</span>
|
||||
<input
|
||||
type="text"
|
||||
class="form-control bg-dark border-secondary text-white"
|
||||
placeholder="SPY"
|
||||
x-model="symbol"
|
||||
@keydown.enter="fetchExpirations()"
|
||||
style="text-transform:uppercase;"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<!-- Expiry select -->
|
||||
<div class="input-group input-group-sm" style="max-width:200px;">
|
||||
<span class="input-group-text bg-dark border-secondary text-muted">Expiry</span>
|
||||
<select
|
||||
class="form-select bg-dark border-secondary text-white"
|
||||
x-model="expiry"
|
||||
@change="renderCharts()"
|
||||
>
|
||||
<option value="">All expirations</option>
|
||||
<template x-for="exp in expirations" :key="exp">
|
||||
<option :value="exp" x-text="exp"></option>
|
||||
</template>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<!-- Load button -->
|
||||
<button
|
||||
class="btn btn-sm btn-primary"
|
||||
@click="loadHistory()"
|
||||
:disabled="loading"
|
||||
>
|
||||
<span x-show="loading" class="spinner-border spinner-border-sm me-1" role="status"></span>
|
||||
<span x-show="!loading">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24"
|
||||
fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"
|
||||
class="me-1" style="vertical-align:-2px;">
|
||||
<polyline points="1 4 1 10 7 10"></polyline>
|
||||
<path d="M3.51 15a9 9 0 1 0 .49-3.51"></path>
|
||||
</svg>
|
||||
Load History
|
||||
</span>
|
||||
<span x-show="loading">Loading…</span>
|
||||
</button>
|
||||
|
||||
<!-- Snapshot count badge -->
|
||||
<span class="snapshot-count-badge" x-text="filteredSnapshots.length + ' snapshots'"></span>
|
||||
|
||||
<!-- Error message -->
|
||||
<span x-show="error" x-cloak class="text-danger small ms-2" x-text="error"></span>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Page body -->
|
||||
<div class="page-body">
|
||||
<div class="container-xl">
|
||||
|
||||
<!-- Empty state -->
|
||||
<div x-show="!loading && filteredSnapshots.length === 0" x-cloak class="text-center py-5">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="48" height="48" viewBox="0 0 24 24"
|
||||
fill="none" stroke="#8b95a1" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" class="mb-3">
|
||||
<path d="M3 3l18 18"></path>
|
||||
<path d="M21 21l-1.5-1.5M16.5 16.5L12 12M12 12L7.5 7.5M7.5 7.5L3 3"></path>
|
||||
<circle cx="12" cy="12" r="10"></circle>
|
||||
</svg>
|
||||
<p class="text-muted">No snapshot data. Enter a symbol and click Load History.</p>
|
||||
</div>
|
||||
|
||||
<!-- Charts row -->
|
||||
<div x-show="filteredSnapshots.length > 0" x-cloak>
|
||||
<div class="row g-3 mb-3">
|
||||
|
||||
<!-- Chart 1: ATM IV -->
|
||||
<div class="col-12">
|
||||
<div class="chart-card p-3">
|
||||
<div class="d-flex align-items-center mb-2 gap-2">
|
||||
<span style="display:inline-block;width:10px;height:10px;border-radius:50%;background:#00d4ff;"></span>
|
||||
<span class="fw-semibold text-white" style="font-size:0.9rem;">ATM Implied Volatility History</span>
|
||||
</div>
|
||||
<div id="chart-atm-iv" style="min-height:220px;"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Chart 2: RR25 + Chart 3: Fly25 side by side on wider screens -->
|
||||
<div class="col-12 col-lg-6">
|
||||
<div class="chart-card p-3">
|
||||
<div class="d-flex align-items-center mb-2 gap-2">
|
||||
<span style="display:inline-block;width:10px;height:10px;border-radius:50%;background:#2fb344;"></span>
|
||||
<span class="fw-semibold text-white" style="font-size:0.9rem;">25Δ Risk Reversal History</span>
|
||||
</div>
|
||||
<div id="chart-rr25" style="min-height:220px;"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-12 col-lg-6">
|
||||
<div class="chart-card p-3">
|
||||
<div class="d-flex align-items-center mb-2 gap-2">
|
||||
<span style="display:inline-block;width:10px;height:10px;border-radius:50%;background:#f59f00;"></span>
|
||||
<span class="fw-semibold text-white" style="font-size:0.9rem;">25Δ Butterfly History</span>
|
||||
</div>
|
||||
<div id="chart-fly25" style="min-height:220px;"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<!-- History table -->
|
||||
<div class="card" style="background-color:#14161c; border:1px solid rgba(255,255,255,0.07);">
|
||||
<div class="card-header d-flex align-items-center justify-content-between"
|
||||
style="border-bottom:1px solid rgba(255,255,255,0.07);">
|
||||
<h3 class="card-title text-white mb-0" style="font-size:0.9rem; font-weight:600;">
|
||||
Snapshot History
|
||||
<span class="ms-2 text-muted" style="font-size:0.75rem; font-weight:400;">
|
||||
(most recent first, showing up to 20)
|
||||
</span>
|
||||
</h3>
|
||||
</div>
|
||||
<div class="table-responsive">
|
||||
<table class="table table-sm table-hover table-snapshots mb-0"
|
||||
style="color:#c8d3e0;">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Timestamp</th>
|
||||
<th>Expiry</th>
|
||||
<th>Spot</th>
|
||||
<th>ATM IV</th>
|
||||
<th>RR25</th>
|
||||
<th>RR10</th>
|
||||
<th>Fly25</th>
|
||||
<th>Butterfly Signal</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<template x-for="(snap, idx) in tableRows" :key="snap.timestamp + idx">
|
||||
<tr>
|
||||
<td class="text-muted" style="white-space:nowrap; font-size:0.8rem;"
|
||||
x-text="formatTimestamp(snap.timestamp)"></td>
|
||||
<td x-text="snap.expiry || '—'"></td>
|
||||
<td x-text="snap.spot ? snap.spot.toFixed(2) : '—'"></td>
|
||||
<td>
|
||||
<span x-text="snap.atmIv ? (snap.atmIv * 100).toFixed(2) + '%' : '—'"
|
||||
style="color:#4fc3f7; font-variant-numeric:tabular-nums;"></span>
|
||||
</td>
|
||||
<td>
|
||||
<span
|
||||
:style="{ color: snap.rr25 > 0 ? '#2fb344' : snap.rr25 < 0 ? '#d63939' : '#8b95a1' }"
|
||||
style="font-variant-numeric:tabular-nums;"
|
||||
x-text="snap.rr25 != null ? snap.rr25.toFixed(4) : '—'">
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<span
|
||||
:style="{ color: snap.rr10 > 0 ? '#2fb344' : snap.rr10 < 0 ? '#d63939' : '#8b95a1' }"
|
||||
style="font-variant-numeric:tabular-nums;"
|
||||
x-text="snap.rr10 != null ? snap.rr10.toFixed(4) : '—'">
|
||||
</span>
|
||||
</td>
|
||||
<td style="font-variant-numeric:tabular-nums;"
|
||||
x-text="snap.fly25 != null ? snap.fly25.toFixed(4) : '—'"></td>
|
||||
<td>
|
||||
<template x-if="snap.fly25 > 0.002">
|
||||
<span class="badge badge-fat-tails">Fat Tails</span>
|
||||
</template>
|
||||
<template x-if="snap.fly25 <= 0.002 && snap.fly25 < -0.002">
|
||||
<span class="badge badge-thin-tails">Thin Tails</span>
|
||||
</template>
|
||||
<template x-if="snap.fly25 != null && snap.fly25 >= -0.002 && snap.fly25 <= 0.002">
|
||||
<span class="badge badge-normal">Normal</span>
|
||||
</template>
|
||||
<template x-if="snap.fly25 == null">
|
||||
<span class="text-muted">—</span>
|
||||
</template>
|
||||
</td>
|
||||
</tr>
|
||||
</template>
|
||||
<tr x-show="tableRows.length === 0">
|
||||
<td colspan="8" class="text-center text-muted py-3">No data available</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Alpine + ApexCharts logic -->
|
||||
<script>
|
||||
const CHART_DEFAULTS = {
|
||||
background: 'transparent',
|
||||
foreColor: '#8b95a1',
|
||||
fontFamily: 'inherit',
|
||||
};
|
||||
|
||||
const AXIS_STYLE = {
|
||||
borderColor: 'rgba(255,255,255,0.06)',
|
||||
labels: {
|
||||
style: { colors: '#8b95a1', fontSize: '11px' }
|
||||
},
|
||||
axisBorder: { show: false },
|
||||
axisTicks: { show: false },
|
||||
};
|
||||
|
||||
const TOOLTIP_STYLE = {
|
||||
theme: 'dark',
|
||||
};
|
||||
|
||||
const GRID_STYLE = {
|
||||
borderColor: 'rgba(255,255,255,0.06)',
|
||||
strokeDashArray: 4,
|
||||
};
|
||||
|
||||
// ── ATM IV chart ──────────────────────────────────────────────────────────
|
||||
function buildAtmIvChart(data) {
|
||||
const sorted = [...data].sort((a, b) => new Date(a.timestamp) - new Date(b.timestamp));
|
||||
const series = sorted.map(s => ({
|
||||
x: new Date(s.timestamp).getTime(),
|
||||
y: s.atmIv != null ? parseFloat((s.atmIv * 100).toFixed(4)) : null,
|
||||
})).filter(p => p.y !== null);
|
||||
|
||||
const options = {
|
||||
chart: {
|
||||
type: 'area',
|
||||
height: 220,
|
||||
toolbar: { show: false },
|
||||
...CHART_DEFAULTS,
|
||||
animations: { enabled: true, speed: 400 },
|
||||
zoom: { enabled: false },
|
||||
},
|
||||
series: [{ name: 'ATM IV', data: series }],
|
||||
stroke: { curve: 'smooth', width: 2, colors: ['#00d4ff'] },
|
||||
fill: {
|
||||
type: 'gradient',
|
||||
gradient: {
|
||||
shadeIntensity: 1,
|
||||
opacityFrom: 0.2,
|
||||
opacityTo: 0.0,
|
||||
stops: [0, 100],
|
||||
colorStops: [{
|
||||
offset: 0,
|
||||
color: '#00d4ff',
|
||||
opacity: 0.2,
|
||||
}, {
|
||||
offset: 100,
|
||||
color: '#00d4ff',
|
||||
opacity: 0,
|
||||
}],
|
||||
},
|
||||
},
|
||||
colors: ['#00d4ff'],
|
||||
xaxis: {
|
||||
type: 'datetime',
|
||||
...AXIS_STYLE,
|
||||
},
|
||||
yaxis: {
|
||||
...AXIS_STYLE,
|
||||
labels: {
|
||||
style: { colors: '#8b95a1', fontSize: '11px' },
|
||||
formatter: v => v != null ? v.toFixed(1) + '%' : '',
|
||||
},
|
||||
title: { text: 'IV (%)', style: { color: '#8b95a1', fontSize: '11px', fontWeight: 400 } },
|
||||
},
|
||||
grid: GRID_STYLE,
|
||||
tooltip: {
|
||||
...TOOLTIP_STYLE,
|
||||
x: { format: 'dd MMM yy HH:mm' },
|
||||
y: { formatter: v => v != null ? v.toFixed(2) + '%' : 'N/A' },
|
||||
},
|
||||
markers: { size: series.length <= 15 ? 4 : 0, colors: ['#00d4ff'], strokeColors: '#1a1c23', strokeWidth: 2 },
|
||||
dataLabels: { enabled: false },
|
||||
};
|
||||
|
||||
return options;
|
||||
}
|
||||
|
||||
// ── RR25 chart ────────────────────────────────────────────────────────────
|
||||
function buildRr25Chart(data) {
|
||||
const sorted = [...data].sort((a, b) => new Date(a.timestamp) - new Date(b.timestamp));
|
||||
const series = sorted.map(s => ({
|
||||
x: new Date(s.timestamp).getTime(),
|
||||
y: s.rr25 != null ? parseFloat(s.rr25.toFixed(6)) : null,
|
||||
})).filter(p => p.y !== null);
|
||||
|
||||
const options = {
|
||||
chart: {
|
||||
type: 'line',
|
||||
height: 220,
|
||||
toolbar: { show: false },
|
||||
...CHART_DEFAULTS,
|
||||
animations: { enabled: true, speed: 400 },
|
||||
zoom: { enabled: false },
|
||||
},
|
||||
series: [{ name: 'RR25', data: series }],
|
||||
stroke: { curve: 'smooth', width: 2, colors: ['#2fb344'] },
|
||||
colors: ['#2fb344'],
|
||||
xaxis: {
|
||||
type: 'datetime',
|
||||
...AXIS_STYLE,
|
||||
},
|
||||
yaxis: {
|
||||
...AXIS_STYLE,
|
||||
labels: {
|
||||
style: { colors: '#8b95a1', fontSize: '11px' },
|
||||
formatter: v => v != null ? v.toFixed(4) : '',
|
||||
},
|
||||
title: { text: 'RR25', style: { color: '#8b95a1', fontSize: '11px', fontWeight: 400 } },
|
||||
},
|
||||
grid: GRID_STYLE,
|
||||
annotations: {
|
||||
yaxis: [{
|
||||
y: 0,
|
||||
borderColor: 'rgba(255, 255, 255, 0.25)',
|
||||
strokeDashArray: 5,
|
||||
label: {
|
||||
text: 'Zero',
|
||||
style: {
|
||||
color: '#8b95a1',
|
||||
background: 'transparent',
|
||||
fontSize: '10px',
|
||||
},
|
||||
position: 'right',
|
||||
},
|
||||
}],
|
||||
},
|
||||
tooltip: {
|
||||
...TOOLTIP_STYLE,
|
||||
x: { format: 'dd MMM yy HH:mm' },
|
||||
y: { formatter: v => v != null ? v.toFixed(4) : 'N/A' },
|
||||
},
|
||||
markers: { size: series.length <= 15 ? 4 : 0, colors: ['#2fb344'], strokeColors: '#1a1c23', strokeWidth: 2 },
|
||||
dataLabels: { enabled: false },
|
||||
};
|
||||
|
||||
return options;
|
||||
}
|
||||
|
||||
// ── Fly25 chart ───────────────────────────────────────────────────────────
|
||||
function buildFly25Chart(data) {
|
||||
const sorted = [...data].sort((a, b) => new Date(a.timestamp) - new Date(b.timestamp));
|
||||
const filtered = sorted.filter(s => s.fly25 != null);
|
||||
|
||||
const values = filtered.map(s => parseFloat(s.fly25.toFixed(6)));
|
||||
const timestamps = filtered.map(s => new Date(s.timestamp).getTime());
|
||||
const barColors = values.map(v => v > 0 ? '#f59f00' : '#6c757d');
|
||||
|
||||
const options = {
|
||||
chart: {
|
||||
type: 'bar',
|
||||
height: 220,
|
||||
toolbar: { show: false },
|
||||
...CHART_DEFAULTS,
|
||||
animations: { enabled: true, speed: 400 },
|
||||
zoom: { enabled: false },
|
||||
},
|
||||
series: [{
|
||||
name: 'Fly25',
|
||||
data: filtered.map((s, i) => ({
|
||||
x: timestamps[i],
|
||||
y: values[i],
|
||||
})),
|
||||
}],
|
||||
plotOptions: {
|
||||
bar: {
|
||||
distributed: true,
|
||||
borderRadius: 2,
|
||||
columnWidth: filtered.length > 30 ? '90%' : '60%',
|
||||
},
|
||||
},
|
||||
colors: barColors,
|
||||
legend: { show: false },
|
||||
xaxis: {
|
||||
type: 'datetime',
|
||||
...AXIS_STYLE,
|
||||
},
|
||||
yaxis: {
|
||||
...AXIS_STYLE,
|
||||
labels: {
|
||||
style: { colors: '#8b95a1', fontSize: '11px' },
|
||||
formatter: v => v != null ? v.toFixed(4) : '',
|
||||
},
|
||||
title: { text: 'Fly25', style: { color: '#8b95a1', fontSize: '11px', fontWeight: 400 } },
|
||||
},
|
||||
grid: GRID_STYLE,
|
||||
annotations: {
|
||||
yaxis: [{
|
||||
y: 0,
|
||||
borderColor: 'rgba(255, 255, 255, 0.2)',
|
||||
strokeDashArray: 4,
|
||||
}],
|
||||
},
|
||||
tooltip: {
|
||||
...TOOLTIP_STYLE,
|
||||
x: { format: 'dd MMM yy HH:mm' },
|
||||
y: { formatter: v => v != null ? v.toFixed(4) : 'N/A' },
|
||||
},
|
||||
dataLabels: { enabled: false },
|
||||
};
|
||||
|
||||
return options;
|
||||
}
|
||||
|
||||
// ── Alpine component ──────────────────────────────────────────────────────
|
||||
function trackerApp() {
|
||||
return {
|
||||
symbol: 'SPY',
|
||||
expiry: '',
|
||||
expirations: [],
|
||||
snapshots: [],
|
||||
loading: false,
|
||||
error: '',
|
||||
|
||||
_charts: { atmIv: null, rr25: null, fly25: null },
|
||||
|
||||
async init() {
|
||||
// expirations are built from snapshot data after loadHistory()
|
||||
},
|
||||
|
||||
async fetchExpirations() {
|
||||
if (!this.symbol.trim()) return;
|
||||
try {
|
||||
const sym = this.symbol.trim().toUpperCase();
|
||||
const res = await fetch(`/api/expirations?symbol=${encodeURIComponent(sym)}`);
|
||||
if (!res.ok) throw new Error('Failed to fetch expirations');
|
||||
const env = await res.json();
|
||||
const json = env.data ?? env;
|
||||
this.expirations = Array.isArray(json) ? json : (json.expirations || []);
|
||||
} catch (e) {
|
||||
this.expirations = [];
|
||||
}
|
||||
},
|
||||
|
||||
async loadHistory() {
|
||||
if (!this.symbol.trim()) return;
|
||||
this.loading = true;
|
||||
this.error = '';
|
||||
try {
|
||||
const sym = this.symbol.trim().toUpperCase();
|
||||
const url = `/api/snapshots?symbol=${encodeURIComponent(sym)}&limit=100`;
|
||||
const res = await fetch(url);
|
||||
if (!res.ok) throw new Error(`API error ${res.status}: ${res.statusText}`);
|
||||
const env = await res.json();
|
||||
const json = env.data ?? env;
|
||||
// Accept array or { snapshots: [...] }
|
||||
this.snapshots = json.snapshots ?? (Array.isArray(json) ? json : []);
|
||||
// Sort descending (most recent first)
|
||||
this.snapshots.sort((a, b) => new Date(b.timestamp) - new Date(a.timestamp));
|
||||
// Rebuild expiration list from data if API didn't provide it
|
||||
if (this.expirations.length === 0) {
|
||||
const expSet = new Set(this.snapshots.map(s => s.expiry).filter(Boolean));
|
||||
this.expirations = [...expSet].sort();
|
||||
}
|
||||
this.$nextTick(() => this.renderCharts());
|
||||
} catch (e) {
|
||||
this.error = e.message;
|
||||
this.snapshots = [];
|
||||
} finally {
|
||||
this.loading = false;
|
||||
}
|
||||
},
|
||||
|
||||
get filteredSnapshots() {
|
||||
if (!this.expiry) return this.snapshots;
|
||||
return this.snapshots.filter(s => s.expiry === this.expiry);
|
||||
},
|
||||
|
||||
get tableRows() {
|
||||
// Most recent first, limited to 20
|
||||
return this.filteredSnapshots.slice(0, 20);
|
||||
},
|
||||
|
||||
formatTimestamp(ts) {
|
||||
if (!ts) return '—';
|
||||
try {
|
||||
const d = new Date(ts);
|
||||
return d.toLocaleString('en-US', {
|
||||
month: 'short', day: '2-digit',
|
||||
hour: '2-digit', minute: '2-digit',
|
||||
hour12: false,
|
||||
});
|
||||
} catch {
|
||||
return ts;
|
||||
}
|
||||
},
|
||||
|
||||
renderCharts() {
|
||||
const data = this.filteredSnapshots;
|
||||
|
||||
// Destroy existing instances
|
||||
Object.keys(this._charts).forEach(k => {
|
||||
if (this._charts[k]) {
|
||||
try { this._charts[k].destroy(); } catch (_) {}
|
||||
this._charts[k] = null;
|
||||
}
|
||||
});
|
||||
|
||||
if (data.length === 0) return;
|
||||
|
||||
this._charts.atmIv = new ApexCharts(
|
||||
document.querySelector('#chart-atm-iv'),
|
||||
buildAtmIvChart(data)
|
||||
);
|
||||
this._charts.atmIv.render();
|
||||
|
||||
this._charts.rr25 = new ApexCharts(
|
||||
document.querySelector('#chart-rr25'),
|
||||
buildRr25Chart(data)
|
||||
);
|
||||
this._charts.rr25.render();
|
||||
|
||||
this._charts.fly25 = new ApexCharts(
|
||||
document.querySelector('#chart-fly25'),
|
||||
buildFly25Chart(data)
|
||||
);
|
||||
this._charts.fly25.render();
|
||||
},
|
||||
|
||||
// Re-render charts when expiry filter changes
|
||||
// (triggered via @change on the select, which calls renderCharts() directly)
|
||||
};
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user