596 lines
27 KiB
JavaScript
596 lines
27 KiB
JavaScript
// /workspace/hyperstitionstudio-core/site/quant/quant-app.js
|
|
// Interactive Quantitative Finance & Memetic Gematria Time-Series Workbench (v2.0.22)
|
|
(function () {
|
|
"use strict";
|
|
|
|
const DATA = (window.HyperstitionStudio && window.HyperstitionStudio.QuantTimeSeries) || null;
|
|
if (!DATA) {
|
|
console.error("QuantTimeSeries bundle missing.");
|
|
return;
|
|
}
|
|
|
|
// Resolve file:// vs https:// navigation links automatically
|
|
if (window.location.protocol === "file:") {
|
|
const navHome = document.getElementById("navHome");
|
|
const navGraph = document.getElementById("navGraph");
|
|
const navLearn = document.getElementById("navLearn");
|
|
const navCalc = document.getElementById("navCalc");
|
|
const navManual = document.getElementById("navManual");
|
|
const navDonate = document.getElementById("navDonate");
|
|
if (navHome) navHome.href = "../index.html";
|
|
if (navGraph) navGraph.href = "../../../encyclopedia-knowledge-graph/index.html";
|
|
if (navLearn) navLearn.href = "../learn/index.html";
|
|
if (navCalc) navCalc.href = "../../../haiperdohp-jemaytreeah/index.html";
|
|
if (navManual) navManual.href = "./OPERATORS-MANUAL-QUANT-TIMESERIES-WORKBENCH.pdf";
|
|
if (navDonate) navDonate.href = "../donate/index.html";
|
|
}
|
|
|
|
let activeSpotlight = null;
|
|
|
|
const state = {
|
|
guildFilter: "ALL",
|
|
selectedSymbol: "NVDA",
|
|
selectedLens: DATA.default_lens || "fund_manager",
|
|
metricMode: "spoken_aq", // "spoken_aq" | "close_usd" | "change_bps" | "digit_aq"
|
|
selectedDateIdx: DATA.dates_utc.length - 1,
|
|
};
|
|
|
|
const guilds = ["ALL", "S1", "S2", "S3", "S4", "S5", "S6"];
|
|
const modes = [
|
|
{ id: "spoken_aq", label: "Spoken AQ (Gen 1)" },
|
|
{ id: "close_usd", label: "Close Price (USD)" },
|
|
{ id: "change_bps", label: "Move (BPS)" },
|
|
{ id: "digit_aq", label: "Digit AQ" },
|
|
];
|
|
|
|
const elGuildPills = document.getElementById("guildFilterPills");
|
|
const elTickerSelect = document.getElementById("tickerSelect");
|
|
const elLensSelect = document.getElementById("lensSelect");
|
|
const elModePills = document.getElementById("metricModePills");
|
|
const elDateBadge = document.getElementById("activeDateBadge");
|
|
const elTvBtn = document.getElementById("openTradingViewBtn");
|
|
const elPanel3TvBtn = document.getElementById("panel3TvBtn");
|
|
const canvas = document.getElementById("tsCanvas");
|
|
const ctx = canvas.getContext("2d");
|
|
|
|
function getFilteredInstruments() {
|
|
if (state.guildFilter === "ALL") return DATA.instruments;
|
|
return DATA.instruments.filter((inst) => inst.guilds.indexOf(state.guildFilter) !== -1);
|
|
}
|
|
|
|
function getSelectedInstrument() {
|
|
return (
|
|
DATA.instruments.find((inst) => inst.symbol === state.selectedSymbol) ||
|
|
DATA.instruments[0]
|
|
);
|
|
}
|
|
|
|
function updateTradingViewLinks() {
|
|
const inst = getSelectedInstrument();
|
|
const url = inst.tradingview_url || ("https://www.tradingview.com/chart/?symbol=" + encodeURIComponent(inst.symbol));
|
|
const label = "Open TradingView (" + (inst.tradingview_symbol || inst.symbol) + ") \u2197";
|
|
if (elTvBtn) {
|
|
elTvBtn.href = url;
|
|
elTvBtn.textContent = label;
|
|
}
|
|
if (elPanel3TvBtn) {
|
|
elPanel3TvBtn.href = url;
|
|
elPanel3TvBtn.textContent = (inst.tradingview_symbol || inst.symbol) + " on TradingView \u2197";
|
|
}
|
|
}
|
|
|
|
function renderControls() {
|
|
// Guild Pills
|
|
elGuildPills.innerHTML = "";
|
|
guilds.forEach((g) => {
|
|
const btn = document.createElement("button");
|
|
btn.className = "pill" + (state.guildFilter === g ? " active" : "");
|
|
btn.textContent = g;
|
|
btn.onclick = function () {
|
|
state.guildFilter = g;
|
|
const list = getFilteredInstruments();
|
|
if (list.length && !list.some((x) => x.symbol === state.selectedSymbol)) {
|
|
state.selectedSymbol = list[0].symbol;
|
|
}
|
|
renderAll();
|
|
};
|
|
elGuildPills.appendChild(btn);
|
|
});
|
|
|
|
// Ticker Select
|
|
const filtered = getFilteredInstruments();
|
|
elTickerSelect.innerHTML = "";
|
|
filtered.forEach((inst) => {
|
|
const opt = document.createElement("option");
|
|
opt.value = inst.symbol;
|
|
opt.textContent = inst.symbol + " — " + inst.entity_eng + " [" + inst.guilds.join(",") + "] (AQ " + inst.entity_ing_aq + ")";
|
|
if (inst.symbol === state.selectedSymbol) opt.selected = true;
|
|
elTickerSelect.appendChild(opt);
|
|
});
|
|
elTickerSelect.onchange = function () {
|
|
state.selectedSymbol = elTickerSelect.value;
|
|
renderAll();
|
|
};
|
|
|
|
// Lens Select (populated dynamically from DATA.enabled_lenses)
|
|
elLensSelect.innerHTML = "";
|
|
(DATA.enabled_lenses || []).forEach((lid) => {
|
|
const meta = (DATA.lens_registry_meta && DATA.lens_registry_meta[lid]) || { short_label: lid, title: lid };
|
|
const opt = document.createElement("option");
|
|
opt.value = lid;
|
|
opt.textContent = meta.short_label + " — " + meta.title;
|
|
if (lid === state.selectedLens) opt.selected = true;
|
|
elLensSelect.appendChild(opt);
|
|
});
|
|
elLensSelect.onchange = function () {
|
|
state.selectedLens = elLensSelect.value;
|
|
renderAll();
|
|
};
|
|
|
|
// Metric Mode Pills
|
|
elModePills.innerHTML = "";
|
|
modes.forEach((m) => {
|
|
const btn = document.createElement("button");
|
|
btn.className = "pill" + (state.metricMode === m.id ? " active" : "");
|
|
btn.textContent = m.label;
|
|
btn.onclick = function () {
|
|
state.metricMode = m.id;
|
|
renderAll();
|
|
};
|
|
elModePills.appendChild(btn);
|
|
});
|
|
|
|
elDateBadge.textContent = DATA.dates_utc[state.selectedDateIdx];
|
|
updateTradingViewLinks();
|
|
}
|
|
|
|
function drawCanvas() {
|
|
const inst = getSelectedInstrument();
|
|
const bars = inst.bars;
|
|
const N = bars.length;
|
|
const W = canvas.width;
|
|
const H = canvas.height;
|
|
ctx.clearRect(0, 0, W, H);
|
|
|
|
const padL = 62;
|
|
const padR = 28;
|
|
const plotW = W - padL - padR;
|
|
|
|
// 3 Panes: Top (20..195), Middle (215..310), Bottom (330..385)
|
|
const topY0 = 22, topY1 = 192;
|
|
const midY0 = 216, midY1 = 306;
|
|
const botY0 = 328, botY1 = 382;
|
|
|
|
function xAt(i) {
|
|
return padL + (i / Math.max(1, N - 1)) * plotW;
|
|
}
|
|
|
|
// Selected date vertical crosshair
|
|
const selX = xAt(state.selectedDateIdx);
|
|
ctx.strokeStyle = "rgba(245, 198, 48, 0.45)";
|
|
ctx.lineWidth = 1.5;
|
|
ctx.beginPath();
|
|
ctx.moveTo(selX, 10);
|
|
ctx.lineTo(selX, H - 18);
|
|
ctx.stroke();
|
|
|
|
// Pane dividers
|
|
ctx.strokeStyle = "#1e293b";
|
|
ctx.lineWidth = 1;
|
|
[topY1, midY1, botY1].forEach((yLine) => {
|
|
ctx.beginPath();
|
|
ctx.moveTo(padL, yLine);
|
|
ctx.lineTo(W - padR, yLine);
|
|
ctx.stroke();
|
|
});
|
|
|
|
// Top Pane: Selected Metric Trajectory
|
|
const vals = bars.map((b) => {
|
|
if (state.metricMode === "close_usd") return Number(b.close_usd);
|
|
if (state.metricMode === "change_bps") return Number(b.change_bps);
|
|
if (state.metricMode === "digit_aq") return Number(b.close_digit_aq);
|
|
return Number(b.close_spoken_ing_aq);
|
|
});
|
|
const minV = Math.min.apply(null, vals);
|
|
const maxV = Math.max.apply(null, vals);
|
|
const spanV = Math.max(1e-3, maxV - minV);
|
|
|
|
function yTop(v) {
|
|
return topY1 - ((v - minV) / spanV) * (topY1 - topY0 - 14) - 6;
|
|
}
|
|
|
|
// Draw entity AQ horizontal reference line if within range
|
|
const refAq = inst.entity_ing_aq;
|
|
if (refAq >= minV && refAq <= maxV) {
|
|
const ry = yTop(refAq);
|
|
ctx.strokeStyle = "rgba(255, 77, 77, 0.45)";
|
|
ctx.setLineDash([4, 4]);
|
|
ctx.beginPath();
|
|
ctx.moveTo(padL, ry);
|
|
ctx.lineTo(W - padR, ry);
|
|
ctx.stroke();
|
|
ctx.setLineDash([]);
|
|
ctx.fillStyle = "#ff4d4d";
|
|
ctx.font = "10px monospace";
|
|
ctx.fillText(inst.entity_ing + "=" + refAq, padL + 6, ry - 4);
|
|
}
|
|
|
|
// Plot curve
|
|
ctx.strokeStyle = "#22d3ee";
|
|
ctx.lineWidth = 2.2;
|
|
ctx.beginPath();
|
|
vals.forEach((v, idx) => {
|
|
const px = xAt(idx);
|
|
const py = yTop(v);
|
|
if (idx === 0) ctx.moveTo(px, py);
|
|
else ctx.lineTo(px, py);
|
|
});
|
|
ctx.stroke();
|
|
|
|
// Lock beacon markers on Top Pane
|
|
bars.forEach((b, idx) => {
|
|
const px = xAt(idx);
|
|
const py = yTop(vals[idx]);
|
|
if (b.scope1_locks && b.scope1_locks.length > 0) {
|
|
ctx.fillStyle = "#f5c630";
|
|
ctx.beginPath();
|
|
ctx.arc(px, py, 5.2, 0, Math.PI * 2);
|
|
ctx.fill();
|
|
} else if (b.scope2_ring_coordinates && b.scope2_ring_coordinates.length > 0) {
|
|
ctx.fillStyle = "#22d3ee";
|
|
ctx.beginPath();
|
|
ctx.arc(px, py, 3.8, 0, Math.PI * 2);
|
|
ctx.fill();
|
|
}
|
|
});
|
|
|
|
// Middle Pane: 00:00 GMT News Wire Equation Counts + Co-Presence Diamonds
|
|
const wireTotals = DATA.daily_wire_series.map((d) => Number(d.equation_counts.total || 0));
|
|
const maxW = Math.max(10, Math.max.apply(null, wireTotals));
|
|
const barW = Math.max(6, Math.floor(plotW / N) - 5);
|
|
|
|
wireTotals.forEach((wt, idx) => {
|
|
const px = xAt(idx);
|
|
const bh = (wt / maxW) * (midY1 - midY0 - 14);
|
|
ctx.fillStyle = bars[idx].co_present_in_news_wire ? "#34d399" : "#a78bfa";
|
|
ctx.fillRect(px - barW / 2, midY1 - bh, barW, bh);
|
|
});
|
|
|
|
// Bottom Pane: 20-Day Volume Ratio & Regime Color Strip
|
|
const vols = bars.map((b) => Number(b.volume_ratio_20d));
|
|
const maxVol = Math.max(2.6, Math.max.apply(null, vols));
|
|
vols.forEach((vr, idx) => {
|
|
const px = xAt(idx);
|
|
const bh = (vr / maxVol) * (botY1 - botY0 - 8);
|
|
const b = bars[idx];
|
|
ctx.fillStyle = b.change_pct <= -5.0 || vr >= 2.5 ? "#ff4d4d" : (vr < 0.45 ? "#f5c630" : "#38bdf8");
|
|
ctx.fillRect(px - barW / 2, botY1 - bh, barW, bh);
|
|
});
|
|
|
|
// Axis labels
|
|
ctx.fillStyle = "#94a3b8";
|
|
ctx.font = "10px monospace";
|
|
ctx.fillText(maxV.toFixed(1), 6, topY0 + 8);
|
|
ctx.fillText(minV.toFixed(1), 6, topY1 - 4);
|
|
ctx.fillText("Wire Eq", 6, midY0 + 12);
|
|
ctx.fillText("Vol20d", 6, botY0 + 12);
|
|
|
|
// Date ticks along bottom
|
|
for (let i = 0; i < N; i += 4) {
|
|
ctx.fillText(DATA.dates_utc[i].slice(5), xAt(i) - 14, H - 4);
|
|
}
|
|
|
|
// Optional Tutorial Spotlight Ring & Callout Banner on Canvas
|
|
if (activeSpotlight && activeSpotlight.target === "canvas") {
|
|
const spX = padL + (activeSpotlight.xRatio || 0.9) * plotW;
|
|
const spY = (activeSpotlight.yRatio || 0.25) * H;
|
|
ctx.save();
|
|
ctx.strokeStyle = "#f5c630";
|
|
ctx.lineWidth = 2.5;
|
|
ctx.beginPath();
|
|
ctx.arc(spX, spY, 18, 0, Math.PI * 2);
|
|
ctx.stroke();
|
|
ctx.strokeStyle = "rgba(251, 113, 133, 0.85)";
|
|
ctx.lineWidth = 1.5;
|
|
ctx.beginPath();
|
|
ctx.arc(spX, spY, 25, 0, Math.PI * 2);
|
|
ctx.stroke();
|
|
|
|
const lbl = activeSpotlight.label || "Spotlight";
|
|
ctx.font = "bold 11px monospace";
|
|
const tw = ctx.measureText(lbl).width + 16;
|
|
const bx = Math.max(padL + 6, Math.min(W - tw - 12, spX - tw - 24));
|
|
const by = Math.max(18, spY - 14);
|
|
ctx.fillStyle = "rgba(2, 6, 23, 0.92)";
|
|
ctx.fillRect(bx, by, tw, 24);
|
|
ctx.strokeStyle = "#f5c630";
|
|
ctx.strokeRect(bx, by, tw, 24);
|
|
ctx.fillStyle = "#f5c630";
|
|
ctx.fillText(lbl, bx + 8, by + 16);
|
|
ctx.restore();
|
|
}
|
|
}
|
|
|
|
function renderHeatmap() {
|
|
const tbl = document.getElementById("heatmapTable");
|
|
const filtered = getFilteredInstruments();
|
|
let html = "<thead><tr><th class='sym-col'>Ticker (TV)</th>";
|
|
DATA.dates_utc.forEach((dt, idx) => {
|
|
const selStyle = idx === state.selectedDateIdx ? "color:var(--gold);font-weight:700;" : "color:var(--text-muted);";
|
|
html += "<th style='" + selStyle + "'>" + dt.slice(8) + "</th>";
|
|
});
|
|
html += "</tr></thead><tbody>";
|
|
|
|
filtered.forEach((inst) => {
|
|
const rowSel = inst.symbol === state.selectedSymbol ? "background:rgba(34,211,238,0.12);" : "";
|
|
html += "<tr style='" + rowSel + "'><th class='sym-col'>";
|
|
html += "<span style='cursor:pointer;color:var(--text-main);' data-sym='" + inst.symbol + "' class='hm-sym-pick'>" + inst.symbol + "</span> ";
|
|
html += "<a href='" + inst.tradingview_url + "' target='_blank' rel='noopener noreferrer' style='color:var(--gold);text-decoration:none;' title='Open " + inst.tradingview_symbol + " on TradingView'>\u2197</a>";
|
|
html += "</th>";
|
|
inst.bars.forEach((b, dIdx) => {
|
|
let cls = "hm-cell hm-none";
|
|
if (b.scope1_locks && b.scope1_locks.length > 0) cls = "hm-cell hm-scope1";
|
|
else if (b.scope2_ring_coordinates && b.scope2_ring_coordinates.length > 0) cls = "hm-cell hm-scope2";
|
|
if (b.co_present_in_news_wire) cls += " hm-wire";
|
|
if (inst.symbol === state.selectedSymbol && dIdx === state.selectedDateIdx) cls += " hm-selected";
|
|
const tip = inst.symbol + " (" + b.date_utc + "): $" + b.close_usd + " (" + b.change_bps + " bps) | Spoken AQ=" + b.close_spoken_ing_aq;
|
|
html += "<td><span class='" + cls + "' data-sym='" + inst.symbol + "' data-didx='" + dIdx + "' title='" + tip + "'></span></td>";
|
|
});
|
|
html += "</tr>";
|
|
});
|
|
html += "</tbody>";
|
|
tbl.innerHTML = html;
|
|
|
|
tbl.querySelectorAll(".hm-cell").forEach((cell) => {
|
|
cell.addEventListener("click", function () {
|
|
state.selectedSymbol = cell.getAttribute("data-sym");
|
|
state.selectedDateIdx = parseInt(cell.getAttribute("data-didx"), 10);
|
|
renderAll();
|
|
});
|
|
});
|
|
tbl.querySelectorAll(".hm-sym-pick").forEach((sp) => {
|
|
sp.addEventListener("click", function () {
|
|
state.selectedSymbol = sp.getAttribute("data-sym");
|
|
renderAll();
|
|
});
|
|
});
|
|
}
|
|
|
|
function renderInspectorAndLens() {
|
|
const inst = getSelectedInstrument();
|
|
const bar = inst.bars[state.selectedDateIdx];
|
|
const dt = bar.date_utc;
|
|
const proj = (inst.lens_projections && inst.lens_projections[state.selectedLens]) || null;
|
|
|
|
document.getElementById("panel3Title").textContent =
|
|
"PANEL 3: " + inst.symbol + " (" + inst.entity_eng + " \u2192 " + inst.entity_ing + "=" + inst.entity_ing_aq + ") @ " + dt;
|
|
|
|
const metricsGrid = document.getElementById("dateMetricsGrid");
|
|
const lockSummary = (bar.scope1_locks || []).concat((bar.scope2_ring_coordinates || []).map((c) => "Ring " + c)).join(", ") || "None";
|
|
metricsGrid.innerHTML = [
|
|
{ l: "Close USD (Change)", v: "$" + bar.close_usd + " (" + (bar.change_bps >= 0 ? "+" : "") + bar.change_bps + " bps)" },
|
|
{ l: "Spoken Close (Gen 1 AQ)", v: bar.close_spoken_ing + " (" + bar.close_spoken_ing_aq + ")" },
|
|
{ l: "Scaled Cap (Gen 1 AQ)", v: bar.market_cap_str + " (" + bar.scaled_cap_spoken_ing_aq + ")" },
|
|
{ l: "BPS Spoken AQ / Vol20d", v: bar.bps_spoken_ing_aq + " / " + bar.volume_ratio_20d + "x" },
|
|
{ l: "Active Contingent Locks", v: lockSummary },
|
|
{ l: "00:00 GMT Wire Co-Present", v: bar.co_present_in_news_wire ? "YES (Scope 3 Lock)" : "No" },
|
|
]
|
|
.map((m) => "<div class='stat-box'><div class='stat-label'>" + m.l + "</div><div class='stat-val'>" + m.v + "</div></div>")
|
|
.join("");
|
|
|
|
// Render Active Lens Projection Card (LENS_REGISTRY)
|
|
const lensCard = document.getElementById("lensProjectionCard");
|
|
if (proj) {
|
|
let rowsHtml = "";
|
|
Object.keys(proj.labeled_timeseries || {}).forEach((k) => {
|
|
const val = proj.labeled_timeseries[k];
|
|
const disp = typeof val === "object" ? JSON.stringify(val) : String(val);
|
|
rowsHtml += "<div style='display:flex;justify-content:space-between;font-size:0.69rem;border-bottom:1px solid #162032;padding:0.18rem 0;'>" +
|
|
"<span style='color:var(--text-muted);'>" + k + ":</span><span style='color:var(--text-main);font-weight:600;'>" + disp + "</span></div>";
|
|
});
|
|
lensCard.innerHTML =
|
|
"<div style='display:flex;justify-content:space-between;align-items:center;margin-bottom:0.4rem;'>" +
|
|
"<span style='font-size:0.76rem;font-weight:700;color:var(--gold);'>Lens: " + proj.lens_title + "</span>" +
|
|
"<span style='font-size:0.7rem;color:var(--cyan);'>" + proj.tier_classification + "</span></div>" +
|
|
"<div style='font-size:0.71rem;color:var(--emerald);margin-bottom:0.4rem;'>" +
|
|
"Archetype: " + proj.qualitative_profile.archetype + " • " + proj.qualitative_profile.regime_specialization +
|
|
" • 30d: " + inst.timeseries_moments.ts_sparkline_30d + "</div>" +
|
|
rowsHtml;
|
|
}
|
|
|
|
// Render Knowledge-Graph-Modeled Documentation & Cited Passages Card
|
|
const docCard = document.getElementById("docReferencesCard");
|
|
if (docCard && inst.doc_references) {
|
|
const dr = inst.doc_references;
|
|
const resolveUrl = (window.HyperstitionStudio.QuantTutorials && window.HyperstitionStudio.QuantTutorials.adaptHrefForFileProtocol) || function (u) { return u; };
|
|
const encUrl = resolveUrl(dr.encyclopedia_deep_link);
|
|
const kgUrl = resolveUrl(dr.knowledge_graph_deep_link);
|
|
const dosUrl = resolveUrl(dr.exemplar_dossier_deep_link);
|
|
const apiUrl = dr.rest_api_deep_link;
|
|
docCard.innerHTML =
|
|
"<div style='font-size:0.74rem;font-weight:700;color:var(--cyan);margin-bottom:0.3rem;'>Documentation & Passage-Encoded Deep Citations</div>" +
|
|
"<div style='font-size:0.68rem;color:var(--text-muted);margin-bottom:0.4rem;'>" + (dr.verbatim_citation_passage || "") + "</div>" +
|
|
"<div style='display:flex;flex-wrap:wrap;gap:0.35rem;'>" +
|
|
"<a class='pill' style='text-decoration:none;color:var(--gold);border-color:var(--gold);' href='" + encUrl + "' target='_blank' rel='noopener noreferrer'>\uD83D\uDCC4 Encyclopedia PDF (#page & search) \u2197</a>" +
|
|
"<a class='pill' style='text-decoration:none;color:var(--cyan);border-color:var(--cyan);' href='" + kgUrl + "' target='_blank' rel='noopener noreferrer'>\uD83D\uDD78\uFE0F Knowledge Graph (aq:" + inst.entity_ing_aq + ") \u2197</a>" +
|
|
"<a class='pill' style='text-decoration:none;color:var(--emerald);border-color:var(--emerald);' href='" + dosUrl + "' target='_blank' rel='noopener noreferrer'>\uD83D\uDCDC Dossier Passage (#:~:text=) \u2197</a>" +
|
|
"<button type='button' class='pill preview-api-btn' data-api='" + apiUrl + "' style='color:var(--violet);border-color:var(--violet);'>\uD83D\uDD0D Inline Passage Preview</button>" +
|
|
"</div>";
|
|
}
|
|
|
|
// Render Dated 00:00 GMT News-Wire Equation Tape
|
|
const wireDay = DATA.daily_wire_series[state.selectedDateIdx];
|
|
const tapeEl = document.getElementById("wireEqTape");
|
|
const hdrEl = document.getElementById("wireTapeHeader");
|
|
const resolveUrl = (window.HyperstitionStudio.QuantTutorials && window.HyperstitionStudio.QuantTutorials.adaptHrefForFileProtocol) || function (u) { return u; };
|
|
if (wireDay && wireDay.dossier_file) {
|
|
hdrEl.innerHTML =
|
|
"Dated 00:00 GMT Wire Dossier (<a href='" + resolveUrl(wireDay.archive_route) + "' target='_blank' style='color:var(--cyan);'>" +
|
|
wireDay.dossier_file + "</a> • " + wireDay.equation_counts.total + " Verified Equations):";
|
|
tapeEl.innerHTML = (wireDay.sample_equations || [])
|
|
.map(
|
|
(eq) => {
|
|
const dLink = resolveUrl(eq.dossier_deep_link || wireDay.archive_route);
|
|
const gLink = resolveUrl((eq.graph_hub_links && eq.graph_hub_links[0]) || ("/graph/index.html?select=aq:" + eq.target));
|
|
const aLink = eq.api_highlight_link || ("/api/v1/dossiers/" + wireDay.dossier_number + "?highlight=" + encodeURIComponent(eq.ing.slice(0, 20)));
|
|
return "<div class='eq-item'><div><strong style='color:var(--gold);'>[" + eq.target + "]</strong> " +
|
|
"<code>" + eq.ing + "</code> (\"" + eq.eng + "\")</div>" +
|
|
"<div style='color:var(--text-muted);font-size:0.65rem;margin-bottom:0.2rem;'>" + eq.breakdown + " = " + eq.target + "</div>" +
|
|
"<div style='display:flex;flex-wrap:wrap;gap:0.3rem;'>" +
|
|
"<a class='pill' style='text-decoration:none;font-size:0.62rem;padding:0.12rem 0.4rem;color:var(--emerald);' href='" + dLink + "' target='_blank'>Passage #:~:text= \u2197</a>" +
|
|
"<a class='pill' style='text-decoration:none;font-size:0.62rem;padding:0.12rem 0.4rem;color:var(--cyan);' href='" + gLink + "' target='_blank'>Graph Hub \u2197</a>" +
|
|
"<button type='button' class='pill preview-api-btn' data-api='" + aLink + "' data-fallback='" + eq.ing + " (\"" + eq.eng + "\") = " + eq.target + "' style='font-size:0.62rem;padding:0.12rem 0.4rem;color:var(--violet);'>Preview Passage</button>" +
|
|
"</div></div>";
|
|
}
|
|
)
|
|
.join("");
|
|
} else {
|
|
hdrEl.textContent = "Dated 00:00 GMT Wire Dossier (" + dt + "):";
|
|
tapeEl.innerHTML = "<div style='color:var(--text-muted);'>No separate dated news dossier archived on " + dt + " (US Closing-Bell Market Telemetry Bar active).</div>";
|
|
}
|
|
|
|
document.querySelectorAll(".preview-api-btn").forEach(function (btn) {
|
|
btn.onclick = function () {
|
|
const apiTarget = btn.getAttribute("data-api");
|
|
const fallbackTxt = btn.getAttribute("data-fallback") || (inst.doc_references && inst.doc_references.verbatim_citation_passage) || "";
|
|
const previewBox = document.getElementById("passagePreviewBox");
|
|
if (!previewBox) return;
|
|
previewBox.style.display = "block";
|
|
previewBox.textContent = "Loading passage preview from " + apiTarget + " ...";
|
|
fetch(apiTarget)
|
|
.then(function (r) { return r.json(); })
|
|
.then(function (j) {
|
|
const d = (j && j.data) || j || {};
|
|
const matches = d.matched_passages || [];
|
|
if (matches.length > 0) {
|
|
previewBox.textContent =
|
|
"[REST API Passage Match in " + (d.uri || apiTarget) + " — Line " + matches[0].line_number + "]\n" +
|
|
matches[0].context;
|
|
} else {
|
|
previewBox.textContent = "[Passage Preview]\n" + fallbackTxt;
|
|
}
|
|
})
|
|
.catch(function () {
|
|
previewBox.textContent = "[Offline Passage Preview]\n" + fallbackTxt;
|
|
});
|
|
};
|
|
});
|
|
}
|
|
|
|
function renderLagExplorer() {
|
|
const inst = getSelectedInstrument();
|
|
const curve = inst.timeseries_moments.ts_lag_correlation_curve || {};
|
|
const optLag = inst.timeseries_moments.ts_optimal_lag_days;
|
|
const container = document.getElementById("lagBarsContainer");
|
|
let html = "";
|
|
for (let tau = -5; tau <= 5; tau++) {
|
|
const r = Number(curve[String(tau)] || 0);
|
|
const hPct = Math.max(6, Math.round(Math.abs(r) * 85));
|
|
const color = tau === optLag ? "var(--gold)" : (r >= 0 ? "var(--cyan)" : "var(--rose)");
|
|
html +=
|
|
"<div class='lag-col' title='Lag tau=" + tau + "d: r=" + r.toFixed(3) + "'>" +
|
|
"<div style='font-size:0.62rem;color:var(--text-main);'>" + r.toFixed(2) + "</div>" +
|
|
"<div class='lag-bar' style='height:" + hPct + "px;background:" + color + ";'></div>" +
|
|
"<div class='lag-lbl'>τ=" + (tau >= 0 ? "+" + tau : tau) + "d</div></div>";
|
|
}
|
|
container.innerHTML = html;
|
|
|
|
const pGate = DATA.periodicity_gate || {};
|
|
document.getElementById("periodicityAuditFooter").textContent =
|
|
"Periodicity Gate Enforced: " + pGate.dated_news_dossiers_ingested + " dated 00:00 UTC news dossiers + 30 daily 21:30 UTC closing-bell bars (" +
|
|
pGate.non_periodic_records_ingested + " non-periodic/static records ingested) | Optimal Lag tau* = " +
|
|
(optLag >= 0 ? "+" + optLag : optLag) + "d | CIDv1: " + (DATA.ipld_dag_json_cidv1 && DATA.ipld_dag_json_cidv1["/"]);
|
|
}
|
|
|
|
function renderAll() {
|
|
renderControls();
|
|
drawCanvas();
|
|
renderHeatmap();
|
|
renderInspectorAndLens();
|
|
renderLagExplorer();
|
|
}
|
|
|
|
// Canvas scrub interaction
|
|
canvas.addEventListener("click", function (ev) {
|
|
const rect = canvas.getBoundingClientRect();
|
|
const relX = ((ev.clientX - rect.left) / rect.width) * canvas.width;
|
|
const padL = 62, padR = 28;
|
|
const ratio = (relX - padL) / (canvas.width - padL - padR);
|
|
const idx = Math.round(ratio * (DATA.dates_utc.length - 1));
|
|
state.selectedDateIdx = Math.max(0, Math.min(DATA.dates_utc.length - 1, idx));
|
|
renderAll();
|
|
});
|
|
|
|
document.getElementById("prevDateBtn").onclick = function () {
|
|
state.selectedDateIdx = Math.max(0, state.selectedDateIdx - 1);
|
|
renderAll();
|
|
};
|
|
document.getElementById("nextDateBtn").onclick = function () {
|
|
state.selectedDateIdx = Math.min(DATA.dates_utc.length - 1, state.selectedDateIdx + 1);
|
|
renderAll();
|
|
};
|
|
|
|
// Keyboard shortcuts: Left/Right arrows step UTC dates; 'T' opens TradingView chart in new window
|
|
window.addEventListener("keydown", function (ev) {
|
|
if (ev.target && (ev.target.tagName === "INPUT" || ev.target.tagName === "SELECT" || ev.target.tagName === "TEXTAREA")) {
|
|
return;
|
|
}
|
|
if (ev.key === "ArrowLeft") {
|
|
state.selectedDateIdx = Math.max(0, state.selectedDateIdx - 1);
|
|
renderAll();
|
|
} else if (ev.key === "ArrowRight") {
|
|
state.selectedDateIdx = Math.min(DATA.dates_utc.length - 1, state.selectedDateIdx + 1);
|
|
renderAll();
|
|
} else if (ev.key === "t" || ev.key === "T") {
|
|
const inst = getSelectedInstrument();
|
|
window.open(inst.tradingview_url, "_blank", "noopener,noreferrer");
|
|
}
|
|
});
|
|
|
|
// CSV & JSON Exports
|
|
document.getElementById("exportCsvBtn").onclick = function () {
|
|
const inst = getSelectedInstrument();
|
|
const headers = ["date_utc", "symbol", "close_usd", "change_bps", "volume_ratio_20d", "close_spoken_ing_aq", "bps_spoken_ing_aq", "co_present_in_news_wire", "contingent_points"];
|
|
const lines = [headers.join(",")];
|
|
inst.bars.forEach((b) => {
|
|
lines.push([b.date_utc, inst.symbol, b.close_usd, b.change_bps, b.volume_ratio_20d, b.close_spoken_ing_aq, b.bps_spoken_ing_aq, b.co_present_in_news_wire, b.contingent_points].join(","));
|
|
});
|
|
const blob = new Blob([lines.join("\n") + "\n"], { type: "text/csv;charset=utf-8" });
|
|
const a = document.createElement("a");
|
|
a.href = URL.createObjectURL(blob);
|
|
a.download = inst.symbol + "-quant-timeseries.csv";
|
|
a.click();
|
|
};
|
|
|
|
document.getElementById("exportJsonBtn").onclick = function () {
|
|
const inst = getSelectedInstrument();
|
|
const blob = new Blob([JSON.stringify(inst, null, 2) + "\n"], { type: "application/json;charset=utf-8" });
|
|
const a = document.createElement("a");
|
|
a.href = URL.createObjectURL(blob);
|
|
a.download = inst.symbol + "-lens-neutral-slice.json";
|
|
a.click();
|
|
};
|
|
|
|
window.HyperstitionStudio = window.HyperstitionStudio || {};
|
|
window.HyperstitionStudio.QuantWorkbenchApp = {
|
|
getState: function () { return Object.assign({}, state); },
|
|
setStateAndRender: function (nextState, spotlight) {
|
|
if (nextState) {
|
|
if (nextState.guildFilter) state.guildFilter = nextState.guildFilter;
|
|
if (nextState.selectedSymbol) state.selectedSymbol = nextState.selectedSymbol;
|
|
if (nextState.selectedLens && DATA.lens_registry_meta[nextState.selectedLens]) {
|
|
state.selectedLens = nextState.selectedLens;
|
|
}
|
|
if (nextState.metricMode) state.metricMode = nextState.metricMode;
|
|
if (typeof nextState.selectedDateIdx === "number") {
|
|
state.selectedDateIdx = Math.max(0, Math.min(DATA.dates_utc.length - 1, nextState.selectedDateIdx));
|
|
}
|
|
}
|
|
activeSpotlight = spotlight || null;
|
|
renderAll();
|
|
}
|
|
};
|
|
|
|
renderAll();
|
|
})();
|