Build a macroprudential AI hotspot monitor scanning credit, housing, and asset markets…
- User
Build a macroprudential AI hotspot monitor scanning credit, housing, and asset markets for systemic anomalies with supervisory alerts.
Assistant
Build a macroprudential AI hotspot monitor scanning credit, housing, and asset markets for systemic anomalies with supervisory alerts.
This is a sophisticated request for a macroprudential monitoring system - essentially a financial stability dashboard that regulators and central banks would use to spot systemic risks. Let me think through what this needs:
Core Components:
Key Features:
Visual Design:
Technical Implementation:
Color Scheme:
Interactive Elements:
Let me build this comprehensive system.
A sophisticated financial stability surveillance system with real-time anomaly detection across credit, housing, and asset markets. Features animated scanning effects, interactive heatmaps, and tiered supervisory alerts.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Macroprudential AI Hotspot Monitor</title>
<script src="https://cdn.tailwindcss.com"></script>
<link href="https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@300;400;500;600;700&family=Space+Grotesk:wght@400;500;600;700&display=swap" rel="stylesheet">
<style>
:root {
--bg-primary: #050a0e;
--bg-secondary: #0a1118;
--bg-card: #0d161f;
--border: #1a2a38;
--text-primary: #e8f4f8;
--text-muted: #5a7a8a;
--accent-cyan: #00d4ff;
--status-normal: #00ff88;
--status-caution: #ffd000;
--status-warning: #ff6b00;
--status-critical: #ff0044;
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'JetBrains Mono', monospace;
background: var(--bg-primary);
color: var(--text-primary);
min-height: 100vh;
overflow-x: hidden;
}
.font-display {
font-family: 'Space Grotesk', sans-serif;
}
/* Background Canvas */
#bg-canvas {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 0;
opacity: 0.6;
}
/* Scanning Grid Overlay */
.scan-grid {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-image:
linear-gradient(rgba(0, 212, 255, 0.03) 1px, transparent 1px),
linear-gradient(90deg, rgba(0, 212, 255, 0.03) 1px, transparent 1px);
background-size: 50px 50px;
z-index: 1;
pointer-events: none;
}
.scan-line {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 3px;
background: linear-gradient(90deg,
transparent 0%,
var(--accent-cyan) 50%,
transparent 100%);
z-index: 2;
animation: scanMove 4s ease-in-out infinite;
opacity: 0.5;
filter: blur(1px);
}
@keyframes scanMove {
0%, 100% { top: 0; }
50% { top: 100%; }
}
/* Main Container */
.main-container {
position: relative;
z-index: 10;
max-width: 1600px;
margin: 0 auto;
padding: 1rem;
}
/* Header */
.header {
display: flex;
justify-content: space-between;
align-items: center;
padding: 1rem 1.5rem;
background: linear-gradient(135deg, var(--bg-card) 0%, rgba(13, 22, 31, 0.8) 100%);
border: 1px solid var(--border);
border-radius: 8px;
margin-bottom: 1rem;
}
.system-status {
display: flex;
align-items: center;
gap: 0.75rem;
}
.status-indicator {
width: 12px;
height: 12px;
border-radius: 50%;
animation: pulse 2s ease-in-out infinite;
}
.status-indicator.active {
background: var(--status-normal);
box-shadow: 0 0 20px var(--status-normal);
}
.status-indicator.alert {
background: var(--status-warning);
box-shadow: 0 0 20px var(--status-warning);
animation: alertPulse 0.5s ease-in-out infinite;
}
@keyframes pulse {
0%, 100% { opacity: 1; transform: scale(1); }
50% { opacity: 0.6; transform: scale(0.9); }
}
@keyframes alertPulse {
0%, 100% { opacity: 1; transform: scale(1); }
50% { opacity: 0.5; transform: scale(1.2); }
}
/* Alert Banner */
.alert-banner {
padding: 1rem 1.5rem;
border-radius: 6px;
margin-bottom: 1rem;
display: flex;
align-items: center;
gap: 1rem;
animation: slideIn 0.5s ease-out, glowPulse 2s ease-in-out infinite;
transform-origin: left;
}
.alert-banner.critical {
background: linear-gradient(90deg, rgba(255, 0, 68, 0.2) 0%, rgba(255, 0, 68, 0.05) 100%);
border: 1px solid var(--status-critical);
}
.alert-banner.warning {
background: linear-gradient(90deg, rgba(255, 107, 0, 0.2) 0%, rgba(255, 107, 0, 0.05) 100%);
border: 1px solid var(--status-warning);
}
.alert-banner.caution {
background: linear-gradient(90deg, rgba(255, 208, 0, 0.2) 0%, rgba(255, 208, 0, 0.05) 100%);
border: 1px solid var(--status-caution);
}
@keyframes slideIn {
from { transform: translateX(-20px); opacity: 0; }
to { transform: translateX(0); opacity: 1; }
}
@keyframes glowPulse {
0%, 100% { box-shadow: 0 0 20px currentColor; }
50% { box-shadow: 0 0 40px currentColor; }
}
/* Grid Layout */
.dashboard-grid {
display: grid;
grid-template-columns: repeat(12, 1fr);
gap: 1rem;
}
/* Card Styles */
.monitor-card {
background: linear-gradient(145deg, var(--bg-card) 0%, rgba(10, 17, 24, 0.9) 100%);
border: 1px solid var(--border);
border-radius: 8px;
padding: 1.25rem;
position: relative;
overflow: hidden;
transition: all 0.3s ease;
}
.monitor-card::before {
content: '';
position: absolute;
top: 0;
left: 0;
right: 0;
height: 2px;
background: linear-gradient(90deg, transparent, var(--accent-cyan), transparent);
opacity: 0;
transition: opacity 0.3s ease;
}
.monitor-card:hover::before {
opacity: 1;
}
.monitor-card:hover {
border-color: var(--accent-cyan);
box-shadow: 0 0 30px rgba(0, 212, 255, 0.1);
}
.card-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 1rem;
padding-bottom: 0.75rem;
border-bottom: 1px solid var(--border);
}
.card-title {
font-size: 0.75rem;
text-transform: uppercase;
letter-spacing: 0.1em;
color: var(--text-muted);
}
.card-badge {
font-size: 0.65rem;
padding: 0.25rem 0.5rem;
border-radius: 4px;
font-weight: 600;
}
/* Heatmap */
.heatmap-container {
display: grid;
grid-template-columns: repeat(6, 1fr);
gap: 4px;
}
.heatmap-cell {
aspect-ratio: 1;
border-radius: 4px;
cursor: pointer;
transition: all 0.2s ease;
position: relative;
}
.heatmap-cell:hover {
transform: scale(1.1);
z-index: 10;
}
.heatmap-cell.normal { background: var(--status-normal); }
.heatmap-cell.caution { background: var(--status-caution); }
.heatmap-cell.warning { background: var(--status-warning); }
.heatmap-cell.critical { background: var(--status-critical); }
.heatmap-cell.anomalous {
animation: cellFlash 1s ease-in-out infinite;
}
@keyframes cellFlash {
0%, 100% { opacity: 1; }
50% { opacity: 0.4; }
}
/* Time Series Chart */
.chart-container {
height: 160px;
position: relative;
}
.chart-canvas {
width: 100%;
height: 100%;
}
/* Gauge */
.gauge-container {
display: flex;
justify-content: center;
align-items: center;
height: 140px;
}
.gauge-svg {
width: 120px;
height: 120px;
}
/* Metric Display */
.metric-value {
font-size: 2rem;
font-weight: 700;
font-family: 'Space Grotesk', sans-serif;
}
.metric-change {
font-size: 0.75rem;
display: flex;
align-items: center;
gap: 0.25rem;
}
.metric-change.positive { color: var(--status-normal); }
.metric-change.negative { color: var(--status-critical); }
/* Sector List */
.sector-list {
display: flex;
flex-direction: column;
gap: 0.75rem;
}
.sector-item {
display: flex;
justify-content: space-between;
align-items: center;
padding: 0.75rem;
background: rgba(0, 0, 0, 0.3);
border-radius: 6px;
border-left: 3px solid;
cursor: pointer;
transition: all 0.2s ease;
}
.sector-item:hover {
background: rgba(0, 0, 0, 0.5);
transform: translateX(4px);
}
.sector-item.normal { border-left-color: var(--status-normal); }
.sector-item.caution { border-left-color: var(--status-caution); }
.sector-item.warning { border-left-color: var(--status-warning); }
.sector-item.critical { border-left-color: var(--status-critical); }
/* Correlation Matrix */
.correlation-grid {
display: grid;
grid-template-columns: repeat(5, 1fr);
gap: 2px;
font-size: 0.6rem;
}
.correlation-cell {
padding: 0.5rem;
text-align: center;
border-radius: 2px;
transition: all 0.2s ease;
}
.correlation-cell:hover {
transform: scale(1.05);
z-index: 5;
}
/* Alert Log */
.alert-log {
max-height: 200px;
overflow-y: auto;
display: flex;
flex-direction: column;
gap: 0.5rem;
}
.alert-log::-webkit-scrollbar {
width: 4px;
}
.alert-log::-webkit-scrollbar-thumb {
background: var(--border);
border-radius: 2px;
}
.log-entry {
font-size: 0.7rem;
padding: 0.5rem;
background: rgba(0, 0, 0, 0.3);
border-radius: 4px;
border-left: 2px solid;
opacity: 0;
animation: logFadeIn 0.3s ease-out forwards;
}
@keyframes logFadeIn {
from { opacity: 0; transform: translateY(-10px); }
to { opacity: 1; transform: translateY(0); }
}
.log-entry.critical { border-left-color: var(--status-critical); }
.log-entry.warning { border-left-color: var(--status-warning); }
.log-entry.caution { border-left-color: var(--status-caution); }
.log-entry.info { border-left-color: var(--accent-cyan); }
/* Tooltip */
.tooltip {
position: fixed;
background: var(--bg-card);
border: 1px solid var(--accent-cyan);
padding: 0.75rem 1rem;
border-radius: 6px;
font-size: 0.75rem;
pointer-events: none;
z-index: 1000;
max-width: 250px;
box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
opacity: 0;
transition: opacity 0.2s ease;
}
.tooltip.visible {
opacity: 1;
}
/* Systemic Risk Score */
.risk-score-display {
text-align: center;
}
.risk-score-ring {
width: 140px;
height: 140px;
margin: 0 auto;
position: relative;
}
.risk-score-value {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
font-size: 2.5rem;
font-weight: 700;
font-family: 'Space Grotesk', sans-serif;
}
/* Responsive */
@media (max-width: 1024px) {
.dashboard-grid {
grid-template-columns: repeat(6, 1fr);
}
}
@media (max-width: 768px) {
.dashboard-grid {
grid-template-columns: 1fr;
}
.header {
flex-direction: column;
gap: 1rem;
text-align: center;
}
}
/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
*, *::before, *::after {
animation-duration: 0.01ms !important;
animation-iteration-count: 1 !important;
transition-duration: 0.01ms !important;
}
.scan-line {
display: none;
}
}
</style>
</head>
<body>
<canvas id="bg-canvas"></canvas>
<div class="scan-grid"></div>
<div class="scan-line"></div>
<div class="main-container">
<!-- Header -->
<header class="header">
<div class="system-status">
<div class="status-indicator active" id="mainStatus"></div>
<div>
<h1 class="font-display text-xl font-bold tracking-tight">Macroprudential AI Monitor</h1>
<p class="text-xs text-gray-500">Financial Stability Surveillance System v3.2.1</p>
</div>
</div>
<div class="flex items-center gap-6">
<div class="text-right">
<div class="text-xs text-gray-500">System Uptime</div>
<div class="text-sm font-semibold" id="uptime">99.97%</div>
</div>
<div class="text-right">
<div class="text-xs text-gray-500">Last Scan</div>
<div class="text-sm font-semibold" id="lastScan">--:--:--</div>
</div>
<div class="text-right">
<div class="text-xs text-gray-500">Active Alerts</div>
<div class="text-sm font-semibold text-orange-400" id="alertCount">0</div>
</div>
</div>
</header>
<!-- Alert Banners -->
<div id="alertBanners"></div>
<!-- Main Dashboard Grid -->
<div class="dashboard-grid">
<!-- Systemic Risk Score -->
<div class="monitor-card col-span-12 md:col-span-3">
<div class="card-header">
<span class="card-title">Systemic Risk Index</span>
<span class="card-badge bg-orange-900 text-orange-300" id="riskLevel">ELEVATED</span>
</div>
<div class="risk-score-display">
<div class="risk-score-ring">
<svg viewBox="0 0 140 140" class="w-full h-full">
<circle cx="70" cy="70" r="60" fill="none" stroke="var(--border)" stroke-width="8"/>
<circle cx="70" cy="70" r="60" fill="none" stroke="var(--status-warning)" stroke-width="8"
stroke-dasharray="377" stroke-dashoffset="113" stroke-linecap="round"
transform="rotate(-90 70 70)" id="riskRing"/>
</svg>
<div class="risk-score-value" id="riskScore">72</div>
</div>
<div class="text-xs text-gray-500 mt-2">Probability of Systemic Event</div>
</div>
</div>
<!-- Credit Markets -->
<div class="monitor-card col-span-12 md:col-span-5">
<div class="card-header">
<span class="card-title">Credit Market Surveillance</span>
<span class="card-badge bg-red-900 text-red-300">2 ALERTS</span>
</div>
<div class="grid grid-cols-2 gap-4">
<div>
<div class="text-xs text-gray-500 mb-1">Credit-to-GDP Ratio</div>
<div class="metric-value text-red-400">142.3%</div>
<div class="metric-change negative">
<svg class="w-3 h-3" fill="currentColor" viewBox="0 0 20 20">
<path fill-rule="evenodd" d="M5.293 7.707a1 1 0 010-1.414l4-4a1 1 0 011.414 0l4 4a1 1 0 01-1.414 1.414L11 5.414V17a1 1 0 11-2 0V5.414L6.707 7.707a1 1 0 01-1.414 0z" clip-rule="evenodd"/>
</svg>
+8.2% YoY
</div>
</div>
<div>
<div class="text-xs text-gray-500 mb-1">NPL Ratio</div>
<div class="metric-value text-yellow-400">3.8%</div>
<div class="metric-change negative">
<svg class="w-3 h-3" fill="currentColor" viewBox="0 0 20 20">
<path fill-rule="evenodd" d="M5.293 7.707a1 1 0 010-1.414l4-4a1 1 0 011.414 0l4 4a1 1 0 01-1.414 1.414L11 5.414V17a1 1 0 11-2 0V5.414L6.707 7.707a1 1 0 01-1.414 0z" clip-rule="evenodd"/>
</svg>
+0.6pp
</div>
</div>
</div>
<div class="chart-container mt-4">
<canvas id="creditChart" class="chart-canvas"></canvas>
</div>
</div>
<!-- Housing Market -->
<div class="monitor-card col-span-12 md:col-span-4">
<div class="card-header">
<span class="card-title">Housing Market Monitor</span>
<span class="card-badge bg-yellow-900 text-yellow-300">CAUTION</span>
</div>
<div class="grid grid-cols-2 gap-4">
<div>
<div class="text-xs text-gray-500 mb-1">Price-to-Income</div>
<div class="metric-value text-yellow-400">8.4x</div>
<div class="text-xs text-gray-600">Threshold: 6.0x</div>
</div>
<div>
<div class="text-xs text-gray-500 mb-1">Mortgage Growth</div>
<div class="metric-value">+12.7%</div>
<div class="metric-change negative">Accelerating</div>
</div>
</div>
<div class="mt-4">
<div class="text-xs text-gray-500 mb-2">Regional Heatmap</div>
<div class="heatmap-container" id="housingHeatmap"></div>
</div>
</div>
<!-- Asset Markets Heatmap -->
<div class="monitor-card col-span-12 md:col-span-4">
<div class="card-header">
<span class="card-title">Asset Market Anomalies</span>
<span class="card-badge bg-cyan-900 text-cyan-300">SCANNING</span>
</div>
<div class="heatmap-container" id="assetHeatmap" style="grid-template-columns: repeat(8, 1fr);"></div>
<div class="flex justify-between mt-3 text-xs text-gray-500">
<span>Equity</span>
<span>Bonds</span>
<span>Commodities</span>
<span>Crypto</span>
</div>
</div>
<!-- Market Correlations -->
<div class="monitor-card col-span-12 md:col-span-4">
<div class="card-header">
<span class="card-title">Cross-Market Correlation</span>
<span class="card-badge bg-orange-900 text-orange-300">RISING</span>
</div>
<div class="correlation-grid" id="correlationMatrix"></div>
</div>
<!-- Leverage Monitor -->
<div class="monitor-card col-span-12 md:col-span-4">
<div class="card-header">
<span class="card-title">Leverage Indicators</span>
<span class="card-badge bg-red-900 text-red-300">CRITICAL</span>
</div>
<div class="sector-list" id="leverageList"></div>
</div>
<!-- Supervisory Alerts -->
<div class="monitor-card col-span-12 md:col-span-6">
<div class="card-header">
<span class="card-title">Supervisory Alert Log</span>
<button class="text-xs text-cyan-400 hover:text-cyan-300" onclick="clearAlerts()">Clear All</button>
</div>
<div class="alert-log" id="alertLog"></div>
</div>
<!-- Interconnectedness -->
<div class="monitor-card col-span-12 md:col-span-6">
<div class="card-header">
<span class="card-title">Systemic Interconnectedness</span>
<span class="card-badge bg-cyan-900 text-cyan-300">MONITORING</span>
</div>
<div class="chart-container">
<canvas id="networkCanvas" class="chart-canvas"></canvas>
</div>
</div>
</div>
</div>
<!-- Tooltip -->
<div class="tooltip" id="tooltip"></div>
<script>
// ==================== DATA ====================
const marketData = {
credit: {
sectors: [
{ name: 'Household Debt', value: 89.2, status: 'warning', trend: '+5.2%' },
{ name: 'Corporate Bonds', value: 52.1, status: 'caution', trend: '+3.1%' },
{ name: 'Bank Lending', value: 78.4, status: 'critical', trend: '+12.3%' },
{ name: 'Shadow Banking', value: 41.8, status: 'warning', trend: '+8.7%' },
{ name: 'Sovereign Debt', value: 112.5, status: 'caution', trend: '+2.4%' }
]
},
housing: {
regions: [
{ name: 'Metro Core', pti: 10.2, status: 'critical' },
{ name: 'Metro Suburbs', pti: 8.1, status: 'warning' },
{ name: 'Coastal', pti: 9.4, status: 'critical' },
{ name: 'Inland', pti: 6.2, status: 'caution' },
{ name: 'Industrial', pti: 5.8, status: 'normal' },
{ name: 'Rural', pti: 4.2, status: 'normal' },
{ name: 'Tech Hub', pti: 11.5, status: 'critical' },
{ name: 'Finance District', pti: 9.8, status: 'warning' },
{ name: 'University', pti: 7.4, status: 'caution' },
{ name: 'Port City', pti: 7.1, status: 'caution' },
{ name: 'Capital Region', pti: 8.9, status: 'warning' },
{ name: 'Border Zone', pti: 5.5, status: 'normal' }
]
},
assets: {
categories: [
{ name: 'Large Cap', status: 'caution', volatility: 18 },
{ name: 'Mid Cap', status: 'warning', volatility: 24 },
{ name: 'Small Cap', status: 'critical', volatility: 35 },
{ name: 'Growth', status: 'critical', volatility: 42 },
{ name: 'Value', status: 'normal', volatility: 12 },
{ name: 'IG Bonds', status: 'normal', volatility: 8 },
{ name: 'HY Bonds', status: 'warning', volatility: 28 },
{ name: 'Sovereign', status: 'caution', volatility: 15 },
{ name: 'Gold', status: 'normal', volatility: 14 },
{ name: 'Oil', status: 'warning', volatility: 32 },
{ name: 'Agri', status: 'caution', volatility: 22 },
{ name: 'BTC', status: 'critical', volatility: 68 },
{ name: 'ETH', status: 'critical', volatility: 72 },
{ name: 'Altcoins', status: 'critical', volatility: 85 },
{ name: 'REITs', status: 'warning', volatility: 26 },
{ name: 'Emerging', status: 'warning', volatility: 29 }
]
},
correlations: [
['', 'Credit', 'Housing', 'Equity', 'Bonds'],
['Credit', 1.0, 0.72, 0.45, 0.38],
['Housing', 0.72, 1.0, 0.38, 0.25],
['Equity', 0.45, 0.38, 1.0, 0.15],
['Bonds', 0.38, 0.25, 0.15, 1.0]
]
};
const alertTemplates = [
{ level: 'critical', sector: 'Credit Markets', message: 'Bank lending growth exceeds 10% threshold - potential overheating detected' },
{ level: 'critical', sector: 'Housing', message: 'Metro Core price-to-income ratio at historic high of 10.2x' },
{ level: 'warning', sector: 'Asset Markets', message: 'Small cap volatility spike detected - 35% annualized' },
{ level: 'warning', sector: 'Leverage', message: 'Household debt-to-income approaching regulatory ceiling' },
{ level: 'caution', sector: 'Correlations', message: 'Cross-market correlation rising - contagion risk elevated' },
{ level: 'info', sector: 'System', message: 'Anomaly detection model recalibrated - sensitivity increased' }
];
// ==================== STATE ====================
let alertQueue = [];
let systemTime = new Date();
let riskScore = 72;
let networkNodes = [];
let networkEdges = [];
// ==================== INITIALIZATION ====================
function init() {
initBackgroundCanvas();
initHousingHeatmap();
initAssetHeatmap();
initCorrelationMatrix();
initLeverageList();
initCreditChart();
initNetworkVisualization();
startAlertSystem();
updateTime();
setInterval(updateTime, 1000);
setInterval(scanForAnomalies, 5000);
setInterval(updateRiskScore, 8000);
}
// ==================== BACKGROUND CANVAS ====================
function initBackgroundCanvas() {
const canvas = document.getElementById('bg-canvas');
const ctx = canvas.getContext('2d');
function resize() {
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
}
resize();
window.addEventListener('resize', resize);
const particles = [];
const particleCount = 80;
for (let i = 0; i < particleCount; i++) {
particles.push({
x: Math.random() * canvas.width,
y: Math.random() * canvas.height,
vx: (Math.random() - 0.5) * 0.5,
vy: (Math.random() - 0.5) * 0.5,
radius: Math.random() * 2 + 1
});
}
function animate() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
particles.forEach(p => {
p.x += p.vx;
p.y += p.vy;
if (p.x < 0 || p.x > canvas.width) p.vx *= -1;
if (p.y < 0 || p.y > canvas.height) p.vy *= -1;
});
ctx.strokeStyle = 'rgba(0, 212, 255, 0.1)';
ctx.lineWidth = 1;
for (let i = 0; i < particles.length; i++) {
for (let j = i + 1; j < particles.length; j++) {
const dx = particles[i].x - particles[j].x;
const dy = particles[i].y - particles[j].y;
const dist = Math.sqrt(dx * dx + dy * dy);
if (dist < 150) {
ctx.globalAlpha = (150 - dist) / 150 * 0.3;
ctx.beginPath();
ctx.moveTo(particles[i].x, particles[i].y);
ctx.lineTo(particles[j].x, particles[j].y);
ctx.stroke();
}
}
}
ctx.globalAlpha = 1;
ctx.fillStyle = '#00d4ff';
particles.forEach(p => {
ctx.beginPath();
ctx.arc(p.x, p.y, Math.max(0.5, p.radius), 0, Math.PI * 2);
ctx.fill();
});
requestAnimationFrame(animate);
}
animate();
}
// ==================== HEATMAPS ====================
function initHousingHeatmap() {
const container = document.getElementById('housingHeatmap');
container.innerHTML = '';
marketData.housing.regions.forEach((region, i) => {
const cell = document.createElement('div');
cell.className = `heatmap-cell ${region.status}`;
if (region.status === 'critical' || region.status === 'warning') {
cell.classList.add('anomalous');
}
cell.dataset.name = region.name;
cell.dataset.pti = region.pti;
cell.addEventListener('mouseenter', showTooltip);
cell.addEventListener('mouseleave', hideTooltip);
container.appendChild(cell);
});
}
function initAssetHeatmap() {
const container = document.getElementById('assetHeatmap');
container.innerHTML = '';
marketData.assets.categories.forEach((asset, i) => {
const cell = document.createElement('div');
cell.className = `heatmap-cell ${asset.status}`;
if (asset.status === 'critical') {
cell.classList.add('anomalous');
}
cell.dataset.name = asset.name;
cell.dataset.vol = asset.volatility;
cell.addEventListener('mouseenter', showTooltip);
cell.addEventListener('mouseleave', hideTooltip);
container.appendChild(cell);
});
}
// ==================== CORRELATION MATRIX ====================
function initCorrelationMatrix() {
const container = document.getElementById('correlationMatrix');
container.innerHTML = '';
const corr = marketData.correlations;
for (let i = 0; i < corr.length; i++) {
for (let j = 0; j < corr[i].length; j++) {
const cell = document.createElement('div');
const value = corr[i][j];
if (i === 0 || j === 0) {
cell.className = 'correlation-cell';
cell.style.background = 'rgba(0, 212, 255, 0.1)';
cell.textContent = typeof value === 'string' ? value.substring(0, 3) : '';
} else {
const intensity = Math.abs(value);
let color;
if (intensity > 0.7) {
color = `rgba(255, 0, 68, ${intensity * 0.8})`;
} else if (intensity > 0.4) {
color = `rgba(255, 107, 0, ${intensity * 0.8})`;
} else {
color = `rgba(0, 255, 136, ${intensity * 0.5})`;
}
cell.className = 'correlation-cell';
cell.style.background = color;
cell.textContent = value.toFixed(2);
}
container.appendChild(cell);
}
}
}
// ==================== LEVERAGE LIST ====================
function initLeverageList() {
const container = document.getElementById('leverageList');
container.innerHTML = '';
marketData.credit.sectors.forEach(sector => {
const item = document.createElement('div');
item.className = `sector-item ${sector.status}`;
item.innerHTML = `
<div>
<div class="text-sm font-medium">${sector.name}</div>
<div class="text-xs text-gray-500">${sector.trend} YoY</div>
</div>
<div class="text-right">
<div class="text-lg font-bold">${sector.value}%</div>
<div class="text-xs text-gray-500">of GDP</div>
</div>
`;
container.appendChild(item);
});
}
// ==================== CREDIT CHART ====================
function initCreditChart() {
const canvas = document.getElementById('creditChart');
const ctx = canvas.getContext('2d');
canvas.width = canvas.offsetWidth * 2;
canvas.height = canvas.offsetHeight * 2;
ctx.scale(2, 2);
const width = canvas.offsetWidth;
const height = canvas.offsetHeight;
const data = [];
for (let i = 0; i < 24; i++) {
data.push(100 + Math.sin(i * 0.3) * 15 + Math.random() * 10 + i * 1.5);
}
const maxVal = Math.max(...data);
const minVal = Math.min(...data);
const range = maxVal - minVal;
ctx.clearRect(0, 0, width, height);
// Grid
ctx.strokeStyle = 'rgba(26, 42, 56, 0.5)';
ctx.lineWidth = 1;
for (let i = 0; i < 5; i++) {
const y = (height / 4) * i;
ctx.beginPath();
ctx.moveTo(0, y);
ctx.lineTo(width, y);
ctx.stroke();
}
// Threshold line
const thresholdY = height - ((130 - minVal) / range) * height;
ctx.strokeStyle = 'rgba(255, 0, 68, 0.5)';
ctx.setLineDash([5, 5]);
ctx.beginPath();
ctx.moveTo(0, thresholdY);
ctx.lineTo(width, thresholdY);
ctx.stroke();
ctx.setLineDash([]);
// Data line
const gradient = ctx.createLinearGradient(0, 0, 0, height);
gradient.addColorStop(0, 'rgba(255, 107, 0, 0.3)');
gradient.addColorStop(1, 'rgba(255, 107, 0, 0)');
ctx.beginPath();
data.forEach((val, i) => {
const x = (width / (data.length - 1)) * i;
const y = height - ((val - minVal) / range) * height;
if (i === 0) ctx.moveTo(x, y);
else ctx.lineTo(x, y);
});
ctx.lineTo(width, height);
ctx.lineTo(0, height);
ctx.fillStyle = gradient;
ctx.fill();
ctx.beginPath();
data.forEach((val, i) => {
const x = (width / (data.length - 1)) * i;
const y = height - ((val - minVal) / range) * height;
if (i === 0) ctx.moveTo(x, y);
else ctx.lineTo(x, y);
});
ctx.strokeStyle = '#ff6b00';
ctx.lineWidth = 2;
ctx.stroke();
// Current point
const lastX = width;
const lastY = height - ((data[data.length - 1] - minVal) / range) * height;
ctx.beginPath();
ctx.arc(lastX, lastY, 4, 0, Math.PI * 2);
ctx.fillStyle = '#ff6b00';
ctx.fill();
}
// ==================== NETWORK VISUALIZATION ====================
function initNetworkVisualization() {
const canvas = document.getElementById('networkCanvas');
const ctx = canvas.getContext('2d');
canvas.width = canvas.offsetWidth * 2;
canvas.height = canvas.offsetHeight * 2;
ctx.scale(2, 2);
const width = canvas.offsetWidth;
const height = canvas.offsetHeight;
const centerX = width / 2;
const centerY = height / 2;
const institutions = ['Banks', 'Shadow Banks', 'Insurers', 'Pension Funds', 'Hedge Funds', 'REITs'];
const eps = 1;
networkNodes = institutions.map((name, i) => {
const angle = (Math.PI * 2 / institutions.length) * i - Math.PI / 2;
const radius = Math.min(width, height) * 0.35;
return {
name,
x: centerX + Math.cos(angle) * radius,
y: centerY + Math.sin(angle) * radius,
radius: 12,
risk: Math.random()
};
});
networkEdges = [];
for (let i = 0; i < networkNodes.length; i++) {
for (let j = i + 1; j < networkNodes.length; j++) {
if (Math.random() > 0.3) {
networkEdges.push({
from: i,
to: j,
strength: Math.random()
});
}
}
}
let time = 0;
function animate() {
ctx.clearRect(0, 0, width, height);
time += 0.02;
// Draw edges
networkEdges.forEach(edge => {
const from = networkNodes[edge.from];
const to = networkNodes[edge.to];
ctx.beginPath();
ctx.moveTo(from.x, from.y);
ctx.lineTo(to.x, to.y);
const alpha = 0.2 + Math.sin(time + edge.strength * 10) * 0.1;
ctx.strokeStyle = `rgba(0, 212, 255, ${Math.max(0, Math.min(1, alpha * edge.strength))})`;
ctx.lineWidth = Math.max(eps, edge.strength * 3);
ctx.stroke();
});
// Draw nodes
networkNodes.forEach((node, i) => {
const pulseRadius = node.radius + Math.sin(time * 2 + i) * 2;
let color;
if (node.risk > 0.7) color = '#ff0044';
else if (node.risk > 0.4) color = '#ff6b00';
else color = '#00ff88';
// Glow
const glowRadius = Math.max(eps, pulseRadius * 2);
const glow = ctx.createRadialGradient(node.x, node.y, 0, node.x, node.y, glowRadius);
glow.addColorStop(0, color.replace(')', ', 0.3)').replace('rgb', 'rgba').replace('#ff0044', 'rgba(255, 0, 68, 0.3)').replace('#ff6b00', 'rgba(255, 107, 0, 0.3)').replace('#00ff88', 'rgba(0, 255, 136, 0.3)'));
glow.addColorStop(1, 'rgba(0, 0, 0, 0)');
ctx.beginPath();
ctx.arc(node.x, node.y, glowRadius, 0, Math.PI * 2);
ctx.fillStyle = glow;
ctx.fill();
// Node
ctx.beginPath();
ctx.arc(node.x, node.y, Math.max(eps, pulseRadius), 0, Math.PI * 2);
ctx.fillStyle = color;
ctx.fill();
// Label
ctx.font = '9px JetBrains Mono';
ctx.fillStyle = '#e8f4f8';
ctx.textAlign = 'center';
ctx.fillText(node.name, node.x, node.y + pulseRadius + 14);
});
requestAnimationFrame(animate);
}
animate();
}
// ==================== ALERT SYSTEM ====================
function startAlertSystem() {
addAlert(alertTemplates[0]);
setTimeout(() => addAlert(alertTemplates[1]), 1500);
setTimeout(() => addAlert(alertTemplates[2]), 3000);
setInterval(() => {
const alert = alertTemplates[Math.floor(Math.random() * alertTemplates.length)];
addAlert(alert);
}, 12000);
}
function addAlert(template) {
const timestamp = new Date().toLocaleTimeString();
const alert = {
id: Date.now(),
level: template.level,
sector: template.sector,
message: template.message,
timestamp
};
alertQueue.unshift(alert);
if (alertQueue.length > 10) alertQueue.pop();
renderAlertLog();
updateAlertCount();
if (alert.level === 'critical' || alert.level === 'warning') {
showBanner(alert);
}
}
function renderAlertLog() {
const container = document.getElementById('alertLog');
container.innerHTML = '';
alertQueue.forEach((alert, i) => {
const entry = document.createElement('div');
entry.className = `log-entry ${alert.level}`;
entry.style.animationDelay = `${i * 0.05}s`;
entry.innerHTML = `
<div class="flex justify-between items-start">
<span class="font-semibold uppercase">${alert.level}</span>
<span class="text-gray-600">${alert.timestamp}</span>
</div>
<div class="text-cyan-400">${alert.sector}</div>
<div class="text-gray-400 mt-1">${alert.message}</div>
`;
container.appendChild(entry);
});
}
function updateAlertCount() {
const count = alertQueue.filter(a => a.level === 'critical' || a.level === 'warning').length;
document.getElementById('alertCount').textContent = count;
}
function showBanner(alert) {
const container = document.getElementById('alertBanners');
const banner = document.createElement('div');
banner.className = `alert-banner ${alert.level}`;
banner.innerHTML = `
<svg class="w-5 h-5 flex-shrink-0" fill="currentColor" viewBox="0 0 20 20">
<path fill-rule="evenodd" d="M8.257 3.099c.765-1.36 2.722-1.36 3.486 0l5.58 9.92c.75 1.334-.213 2.98-1.742 2.98H4.42c-1.53 0-2.493-1.646-1.743-2.98l5.58-9.92zM11 13a1 1 0 11-2 0 1 1 0 012 0zm-1-8a1 1 0 00-1 1v3a1 1 0 002 0V6a1 1 0 00-1-1z" clip-rule="evenodd"/>
</svg>
<div class="flex-1">
<div class="font-semibold">${alert.sector}: ${alert.level.toUpperCase()}</div>
<div class="text-sm opacity-80">${alert.message}</div>
</div>
<button class="text-gray-400 hover:text-white" onclick="this.parentElement.remove()">
<svg class="w-4 h-4" fill="currentColor" viewBox="0 0 20 20">
<path fill-rule="evenodd" d="M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z" clip-rule="evenodd"/>
</svg>
</button>
`;
container.prepend(banner);
setTimeout(() => banner.remove(), 10000);
}
function clearAlerts() {
alertQueue = [];
renderAlertLog();
updateAlertCount();
}
// ==================== ANOMALY SCANNING ====================
function scanForAnomalies() {
const cells = document.querySelectorAll('.heatmap-cell');
cells.forEach(cell => {
if (Math.random() > 0.9) {
cell.classList.add('anomalous');
setTimeout(() => cell.classList.remove('anomalous'), 2000);
}
});
}
// ==================== RISK SCORE ====================
function updateRiskScore() {
riskScore = Math.min(100, Math.max(0, riskScore + (Math.random() - 0.5) * 10));
const displayScore = Math.round(riskScore);
document.getElementById('riskScore').textContent = displayScore;
const ring = document.getElementById('riskRing');
const offset = 377 - (377 * displayScore / 100);
ring.style.strokeDashoffset = offset;
let level, color;
if (displayScore >= 80) {
level = 'CRITICAL';
color = 'var(--status-critical)';
} else if (displayScore >= 60) {
level = 'ELEVATED';
color = 'var(--status-warning)';
} else if (displayScore >= 40) {
level = 'CAUTION';
color = 'var(--status-caution)';
} else {
level = 'NORMAL';
color = 'var(--status-normal)';
}
document.getElementById('riskLevel').textContent = level;
ring.style.stroke = color;
const status = document.getElementById('mainStatus');
if (displayScore >= 70) {
status.classList.remove('active');
status.classList.add('alert');
} else {
status.classList.remove('alert');
status.classList.add('active');
}
}
// ==================== TIME ====================
function updateTime() {
systemTime = new Date();
document.getElementById('lastScan').textContent = systemTime.toLocaleTimeString();
}
// ==================== TOOLTIP ====================
const tooltip = document.getElementById('tooltip');
function showTooltip(e) {
const cell = e.target;
const rect = cell.getBoundingClientRect();
let content = '';
if (cell.dataset.pti) {
content = `<strong>${cell.dataset.name}</strong><br>Price-to-Income: ${cell.dataset.pti}x`;
} else if (cell.dataset.vol) {
content = `<strong>${cell.dataset.name}</strong><br>Volatility: ${cell.dataset.vol}%`;
}
if (content) {
tooltip.innerHTML = content;
tooltip.style.left = `${rect.left}px`;
tooltip.style.top = `${rect.bottom + 8}px`;
tooltip.classList.add('visible');
}
}
function hideTooltip() {
tooltip.classList.remove('visible');
}
// ==================== INIT ====================
document.addEventListener('DOMContentLoaded', init);
window.addEventListener('resize', () => {
initCreditChart();
});
</script>
</body>
</html>