The user wants a climate-adaptive insurance capital allocation dashboard. This is a sophisticated financial/insurance analytics tool that needs to show:
Let me build this step by step with proper data structures and meaningful interactions.
This is a sophisticated financial dashboard that integrates underwriting risk, reinsurance structures, and solvency requirements with climate scenario analysis. The dashboard features dynamic capital allocation, stress testing, and interactive visualizations.
html Copy code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Climate-Adaptive Capital Allocation Dashboard</title>
<script src="https://cdn.tailwindcss.com"></script>
<link href="https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap" rel="stylesheet">
<style>
:root {
--bg: #0a0f1a;
--bg-elevated: #111827;
--bg-card: #1a2234;
--fg: #e8edf5;
--fg-muted: #6b7a94;
--accent: #00d4aa;
--accent-dim: #00a88a;
--warning: #f59e0b;
--danger: #ef4444;
--info: #3b82f6;
--border: #2a3548;
--gradient-start: #0d1526;
--gradient-end: #0a1628;
}
* {
box-sizing: border-box;
}
body {
font-family: 'Space Grotesk', sans-serif;
background: var(--bg);
color: var(--fg);
min-height: 100vh;
}
.mono {
font-family: 'JetBrains Mono', monospace;
}
.bg-pattern {
background-image:
radial-gradient(ellipse 80% 50% at 50% -20%, rgba(0, 212, 170, 0.08), transparent),
radial-gradient(ellipse 60% 40% at 100% 100%, rgba(59, 130, 246, 0.05), transparent),
linear-gradient(180deg, var(--gradient-start), var(--gradient-end));
}
.card {
background: var(--bg-card);
border: 1px solid var(--border);
border-radius: 12px;
backdrop-filter: blur(10px);
}
.metric-value {
font-family: 'JetBrains Mono', monospace;
font-weight: 500;
letter-spacing: -0.02em;
}
.glow-accent {
box-shadow: 0 0 20px rgba(0, 212, 170, 0.2);
}
.tab-active {
background: var(--accent);
color: var(--bg);
}
.range-slider {
-webkit-appearance: none;
appearance: none;
background: var(--border);
border-radius: 4px;
height: 6px;
}
.range-slider::-webkit-slider-thumb {
-webkit-appearance: none;
appearance: none;
width: 18px;
height: 18px;
border-radius: 50%;
background: var(--accent);
cursor: pointer;
border: 2px solid var(--bg);
box-shadow: 0 2px 8px rgba(0, 212, 170, 0.4);
}
.scenario-btn {
transition: all 0.2s ease;
}
.scenario-btn:hover {
transform: translateY(-2px);
}
.scenario-btn.active {
background: var(--accent);
color: var(--bg);
border-color: var(--accent);
}
@keyframes fadeSlideUp {
from {
opacity: 0;
transform: translateY(20px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
@keyframes pulse {
0%, 100% { opacity: 1; }
50% { opacity: 0.6; }
}
.animate-in {
animation: fadeSlideUp 0.5s ease forwards;
}
.stagger-1 { animation-delay: 0.1s; opacity: 0; }
.stagger-2 { animation-delay: 0.2s; opacity: 0; }
.stagger-3 { animation-delay: 0.3s; opacity: 0; }
.stagger-4 { animation-delay: 0.4s; opacity: 0; }
.stagger-5 { animation-delay: 0.5s; opacity: 0; }
.live-indicator {
animation: pulse 2s ease-in-out infinite;
}
canvas {
display: block;
}
@media (prefers-reduced-motion: reduce) {
.animate-in {
animation: none;
opacity: 1;
}
.live-indicator {
animation: none;
}
}
.tooltip {
position: absolute;
background: var(--bg-elevated);
border: 1px solid var(--border);
padding: 8px 12px;
border-radius: 6px;
font-size: 12px;
pointer-events: none;
z-index: 100;
opacity: 0;
transition: opacity 0.15s ease;
}
.tooltip.visible {
opacity: 1;
}
:focus-visible {
outline: 2px solid var(--accent);
outline-offset: 2px;
}
</style>
</head>
<body class="bg-pattern">
<div class="min-h-screen p-4 lg:p-6">
<!-- Header -->
<header class="mb-6 animate-in stagger-1">
<div class="flex flex-col lg:flex-row lg:items-center lg:justify-between gap-4">
<div>
<div class="flex items-center gap-3 mb-2">
<h1 class="text-2xl lg:text-3xl font-semibold tracking-tight">Capital Allocation Engine</h1>
<span class="px-2 py-1 text-xs font-medium bg-emerald-500/20 text-emerald-400 rounded-full flex items-center gap-1">
<span class="w-1.5 h-1.5 bg-emerald-400 rounded-full live-indicator"></span>
LIVE
</span>
</div>
<p class="text-sm text-[var(--fg-muted)]">Climate-adaptive risk capital optimization platform</p>
</div>
<div class="flex items-center gap-3">
<div class="text-right">
<div class="text-xs text-[var(--fg-muted)]">Last recalibrated</div>
<div class="text-sm mono" id="lastUpdate">2024-01-15 14:32:05</div>
</div>
<button onclick="recalculateCapital()" class="px-4 py-2 bg-[var(--accent)] text-[var(--bg)] font-medium rounded-lg hover:bg-[var(--accent-dim)] transition-colors flex items-center gap-2" aria-label="Recalculate capital allocation">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<path d="M21 12a9 9 0 0 0-9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"/>
<path d="M3 3v5h5"/>
<path d="M3 12a9 9 0 0 0 9 9 9.75 9.75 0 0 0 6.74-2.74L21 16"/>
<path d="M16 21h5v-5"/>
</svg>
Recalculate
</button>
</div>
</div>
</header>
<!-- Climate Scenario Selector -->
<section class="mb-6 animate-in stagger-2">
<div class="card p-4">
<div class="flex items-center justify-between mb-4">
<h2 class="font-medium text-sm uppercase tracking-wider text-[var(--fg-muted)]">Climate Scenario</h2>
<div class="text-xs text-[var(--fg-muted)]">RCP Pathway Selection</div>
</div>
<div class="grid grid-cols-2 lg:grid-cols-5 gap-3" role="radiogroup" aria-label="Climate scenario selection">
<button class="scenario-btn active px-4 py-3 border border-[var(--border)] rounded-lg text-left transition-all" data-scenario="baseline" role="radio" aria-checked="true">
<div class="text-sm font-medium">Baseline</div>
<div class="text-xs text-[var(--fg-muted)] mt-1">Current conditions</div>
<div class="text-lg mono mt-2 text-[var(--accent)]">+0.0°C</div>
</button>
<button class="scenario-btn px-4 py-3 border border-[var(--border)] rounded-lg text-left transition-all" data-scenario="rcp26" role="radio" aria-checked="false">
<div class="text-sm font-medium">RCP 2.6</div>
<div class="text-xs text-[var(--fg-muted)] mt-1">Strong mitigation</div>
<div class="text-lg mono mt-2 text-emerald-400">+1.5°C</div>
</button>
<button class="scenario-btn px-4 py-3 border border-[var(--border)] rounded-lg text-left transition-all" data-scenario="rcp45" role="radio" aria-checked="false">
<div class="text-sm font-medium">RCP 4.5</div>
<div class="text-xs text-[var(--fg-muted)] mt-1">Moderate action</div>
<div class="text-lg mono mt-2 text-yellow-400">+2.4°C</div>
</button>
<button class="scenario-btn px-4 py-3 border border-[var(--border)] rounded-lg text-left transition-all" data-scenario="rcp60" role="radio" aria-checked="false">
<div class="text-sm font-medium">RCP 6.0</div>
<div class="text-xs text-[var(--fg-muted)] mt-1">Limited policy</div>
<div class="text-lg mono mt-2 text-orange-400">+3.0°C</div>
</button>
<button class="scenario-btn px-4 py-3 border border-[var(--border)] rounded-lg text-left transition-all" data-scenario="rcp85" role="radio" aria-checked="false">
<div class="text-sm font-medium">RCP 8.5</div>
<div class="text-xs text-[var(--fg-muted)] mt-1">Business as usual</div>
<div class="text-lg mono mt-2 text-red-400">+4.3°C</div>
</button>
</div>
</div>
</section>
<!-- Key Metrics -->
<section class="grid grid-cols-2 lg:grid-cols-4 gap-4 mb-6 animate-in stagger-3">
<div class="card p-4">
<div class="text-xs text-[var(--fg-muted)] uppercase tracking-wider mb-2">Available Capital</div>
<div class="text-2xl lg:text-3xl mono font-medium" id="availableCapital">$4.82B</div>
<div class="flex items-center gap-2 mt-2">
<span class="text-xs px-2 py-0.5 rounded bg-emerald-500/20 text-emerald-400" id="capitalChange">+2.4%</span>
<span class="text-xs text-[var(--fg-muted)]">vs. prior quarter</span>
</div>
</div>
<div class="card p-4">
<div class="text-xs text-[var(--fg-muted)] uppercase tracking-wider mb-2">SCR Ratio</div>
<div class="text-2xl lg:text-3xl mono font-medium" id="scrRatio">212%</div>
<div class="w-full h-1.5 bg-[var(--border)] rounded-full mt-3">
<div class="h-full bg-[var(--accent)] rounded-full transition-all duration-500" id="scrBar" style="width: 70%"></div>
</div>
<div class="text-xs text-[var(--fg-muted)] mt-2">Min. threshold: 100%</div>
</div>
<div class="card p-4">
<div class="text-xs text-[var(--fg-muted)] uppercase tracking-wider mb-2">Climate VaR</div>
<div class="text-2xl lg:text-3xl mono font-medium" id="climateVar">$382M</div>
<div class="flex items-center gap-2 mt-2">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="var(--warning)" stroke-width="2">
<path d="M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"/>
<line x1="12" y1="9" x2="12" y2="13"/><line x1="12" y1="17" x2="12.01" y2="17"/>
</svg>
<span class="text-xs text-[var(--warning)]" id="varWarning">Elevated tail risk</span>
</div>
</div>
<div class="card p-4">
<div class="text-xs text-[var(--fg-muted)] uppercase tracking-wider mb-2">Reinsurance Efficiency</div>
<div class="text-2xl lg:text-3xl mono font-medium" id="reinsEfficiency">87.3%</div>
<div class="flex items-center gap-2 mt-2">
<div class="flex-1">
<div class="text-xs text-[var(--fg-muted)]">Ceded: <span class="text-[var(--fg)]" id="cededRatio">32%</span></div>
</div>
</div>
</div>
</section>
<!-- Main Dashboard Grid -->
<div class="grid lg:grid-cols-3 gap-6">
<!-- Capital Allocation Chart -->
<div class="lg:col-span-2 animate-in stagger-4">
<div class="card p-4 h-full">
<div class="flex items-center justify-between mb-4">
<h3 class="font-medium">Capital Allocation by Risk Category</h3>
<div class="flex gap-2">
<button class="tab-btn px-3 py-1 text-xs rounded-md bg-[var(--accent)] text-[var(--bg)]" data-view="allocation">Allocation</button>
<button class="tab-btn px-3 py-1 text-xs rounded-md border border-[var(--border)] text-[var(--fg-muted)] hover:border-[var(--accent)] transition-colors" data-view="stress">Stress Impact</button>
</div>
</div>
<div class="relative" style="height: 320px;">
<canvas id="allocationChart" aria-label="Capital allocation bar chart"></canvas>
</div>
<div class="grid grid-cols-3 gap-4 mt-4 pt-4 border-t border-[var(--border)]">
<div>
<div class="text-xs text-[var(--fg-muted)]">Underwriting Risk</div>
<div class="mono text-lg" id="uwRisk">$1.84B</div>
</div>
<div>
<div class="text-xs text-[var(--fg-muted)]">Reserve Risk</div>
<div class="mono text-lg" id="resRisk">$892M</div>
</div>
<div>
<div class="text-xs text-[var(--fg-muted)]">CAT Exposure</div>
<div class="mono text-lg" id="catExp">$1.24B</div>
</div>
</div>
</div>
</div>
<!-- Allocation Controls -->
<div class="animate-in stagger-5">
<div class="card p-4 h-full">
<h3 class="font-medium mb-4">Allocation Parameters</h3>
<div class="space-y-5">
<div>
<div class="flex justify-between text-sm mb-2">
<label for="catLoad">CAT Risk Load</label>
<span class="mono text-[var(--accent)]" id="catLoadValue">15%</span>
</div>
<input type="range" id="catLoad" class="range-slider w-full" min="5" max="50" value="15" aria-label="Catastrophe risk load percentage">
</div>
<div>
<div class="flex justify-between text-sm mb-2">
<label for="reinsRetention">Max Retention</label>
<span class="mono text-[var(--accent)]" id="retentionValue">$500M</span>
</div>
<input type="range" id="reinsRetention" class="range-slider w-full" min="100" max="1000" value="500" aria-label="Maximum retention amount in millions">
</div>
<div>
<div class="flex justify-between text-sm mb-2">
<label for="riskAppetite">Risk Appetite</label>
<span class="mono text-[var(--accent)]" id="appetiteValue">Medium</span>
</div>
<input type="range" id="riskAppetite" class="range-slider w-full" min="1" max="5" value="3" aria-label="Risk appetite level from conservative to aggressive">
</div>
<div class="pt-4 border-t border-[var(--border)]">
<div class="text-sm font-medium mb-3">Solvency Targets</div>
<div class="space-y-2">
<div class="flex justify-between items-center">
<span class="text-xs text-[var(--fg-muted)]">SCR Target</span>
<span class="mono text-sm">180%</span>
</div>
<div class="flex justify-between items-center">
<span class="text-xs text-[var(--fg-muted)]">MCR Buffer</span>
<span class="mono text-sm">145%</span>
</div>
<div class="flex justify-between items-center">
<span class="text-xs text-[var(--fg-muted)]">Rating Target</span>
<span class="mono text-sm">AA-</span>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Bottom Section -->
<div class="grid lg:grid-cols-2 gap-6 mt-6">
<!-- Reinsurance Structure -->
<div class="card p-4 animate-in stagger-4">
<h3 class="font-medium mb-4">Reinsurance Structure</h3>
<div class="relative" style="height: 240px;">
<canvas id="reinsuranceChart" aria-label="Reinsurance structure visualization"></canvas>
</div>
<div class="grid grid-cols-4 gap-3 mt-4">
<div class="text-center p-2 bg-[var(--bg-elevated)] rounded-lg">
<div class="text-xs text-[var(--fg-muted)]">Quota Share</div>
<div class="mono text-sm mt-1">25%</div>
</div>
<div class="text-center p-2 bg-[var(--bg-elevated)] rounded-lg">
<div class="text-xs text-[var(--fg-muted)]">XL Layers</div>
<div class="mono text-sm mt-1">4</div>
</div>
<div class="text-center p-2 bg-[var(--bg-elevated)] rounded-lg">
<div class="text-xs text-[var(--fg-muted)]">Recoverables</div>
<div class="mono text-sm mt-1">$842M</div>
</div>
<div class="text-center p-2 bg-[var(--bg-elevated)] rounded-lg">
<div class="text-xs text-[var(--fg-muted)]">Premium</div>
<div class="mono text-sm mt-1">$127M</div>
</div>
</div>
</div>
<!-- Stress Test Results -->
<div class="card p-4 animate-in stagger-5">
<h3 class="font-medium mb-4">Climate Stress Scenarios</h3>
<div class="space-y-3" id="stressResults">
<!-- Populated by JS -->
</div>
</div>
</div>
<!-- Tooltip -->
<div class="tooltip" id="tooltip"></div>
</div>
<script>
// ============================================
// DATA LAYER
// ============================================
const insuranceData = {
scenarios: {
baseline: {
temp: 0,
catMultiplier: 1.0,
lossMultiplier: 1.0,
varImpact: 0,
capitalAdjustment: 0
},
rcp26: {
temp: 1.5,
catMultiplier: 1.15,
lossMultiplier: 1.08,
varImpact: 0.12,
capitalAdjustment: 0.05
},
rcp45: {
temp: 2.4,
catMultiplier: 1.35,
lossMultiplier: 1.18,
varImpact: 0.24,
capitalAdjustment: 0.12
},
rcp60: {
temp: 3.0,
catMultiplier: 1.55,
lossMultiplier: 1.32,
varImpact: 0.38,
capitalAdjustment: 0.22
},
rcp85: {
temp: 4.3,
catMultiplier: 2.1,
lossMultiplier: 1.55,
varImpact: 0.65,
capitalAdjustment: 0.45
}
},
riskCategories: [
{ name: 'Property CAT', base: 820, color: '#00d4aa', climateSensitivity: 0.45 },
{ name: 'Motor', base: 420, color: '#3b82f6', climateSensitivity: 0.12 },
{ name: 'Liability', base: 380, color: '#8b5cf6', climateSensitivity: 0.08 },
{ name: 'Marine', base: 290, color: '#06b6d4', climateSensitivity: 0.35 },
{ name: 'Crop', base: 210, color: '#f59e0b', climateSensitivity: 0.55 },
{ name: 'Health', base: 340, color: '#ec4899', climateSensitivity: 0.15 }
],
reinsuranceLayers: [
{ name: 'Retention', amount: 100, type: 'retained', color: '#374151' },
{ name: 'QS Ceded', amount: 500, type: 'ceded', color: '#00d4aa' },
{ name: 'XL Layer 1', amount: 200, type: 'ceded', color: '#3b82f6' },
{ name: 'XL Layer 2', amount: 300, type: 'ceded', color: '#8b5cf6' },
{ name: 'XL Layer 3', amount: 400, type: 'ceded', color: '#06b6d4' },
{ name: 'XL Layer 4', amount: 500, type: 'ceded', color: '#f59e0b' }
],
stressTests: [
{ name: '100-Year Hurricane', probability: '1%', loss: 1850, scrImpact: -45, color: '#ef4444' },
{ name: 'Major Flood Event', probability: '2%', loss: 920, scrImpact: -22, color: '#f59e0b' },
{ name: 'Wildfire Outbreak', probability: '3%', loss: 640, scrImpact: -15, color: '#f97316' },
{ name: 'Convective Storm Cluster', probability: '5%', loss: 380, scrImpact: -8, color: '#eab308' },
{ name: 'Climate Trend Shift', probability: '10%', loss: 520, scrImpact: -12, color: '#84cc16' }
],
baseCapital: 4.82,
baseVar: 382,
baseScr: 212
};
// ============================================
// STATE MANAGEMENT
// ============================================
let currentScenario = 'baseline';
let catLoad = 15;
let retention = 500;
let riskAppetite = 3;
let chartView = 'allocation';
// ============================================
// UTILITY FUNCTIONS
// ============================================
function formatCurrency(value, decimals = 0) {
if (value >= 1000) {
return '$' + (value / 1000).toFixed(2) + 'B';
}
return '$' + value.toFixed(decimals) + 'M';
}
function clamp(value, min, max) {
return Math.max(min, Math.min(max, value));
}
function lerp(start, end, t) {
return start + (end - start) * t;
}
// ============================================
// CALCULATIONS
// ============================================
function calculateCapitalAllocation() {
const scenario = insuranceData.scenarios[currentScenario];
return insuranceData.riskCategories.map(cat => {
const climateAdjustment = 1 + (cat.climateSensitivity * (scenario.catMultiplier - 1));
const loadAdjustment = 1 + (catLoad / 100);
return {
...cat,
allocation: cat.base * climateAdjustment * loadAdjustment
};
});
}
function calculateMetrics() {
const scenario = insuranceData.scenarios[currentScenario];
const allocation = calculateCapitalAllocation();
const totalCapital = insuranceData.baseCapital * (1 + scenario.capitalAdjustment);
const totalAllocated = allocation.reduce((sum, cat) => sum + cat.allocation, 0);
const climateVar = insuranceData.baseVar * (1 + scenario.varImpact) * (1 + (catLoad - 15) / 100);
const appetiteFactor = (riskAppetite - 3) * 0.1;
const scrRatio = insuranceData.baseScr * (1 - scenario.varImpact * 0.5) + (appetiteFactor * 20);
const retentionImpact = (retention - 500) / 500;
const reinsEfficiency = 87.3 + (retentionImpact * -5) + (appetiteFactor * 3);
return {
totalCapital,
totalAllocated,
climateVar,
scrRatio: clamp(scrRatio, 100, 300),
reinsEfficiency: clamp(reinsEfficiency, 70, 95),
cededRatio: 32 + (retentionImpact * -8)
};
}
// ============================================
// CHART RENDERING
// ============================================
function drawAllocationChart() {
const canvas = document.getElementById('allocationChart');
if (!canvas) return;
const ctx = canvas.getContext('2d');
const rect = canvas.parentElement.getBoundingClientRect();
const dpr = window.devicePixelRatio || 1;
canvas.width = rect.width * dpr;
canvas.height = rect.height * dpr;
canvas.style.width = rect.width + 'px';
canvas.style.height = rect.height + 'px';
ctx.scale(dpr, dpr);
const width = rect.width;
const height = rect.height;
const padding = { top: 20, right: 30, bottom: 50, left: 80 };
const chartWidth = width - padding.left - padding.right;
const chartHeight = height - padding.top - padding.bottom;
ctx.clearRect(0, 0, width, height);
const allocation = calculateCapitalAllocation();
const maxValue = Math.max(...allocation.map(d => d.allocation)) * 1.2;
const barHeight = (chartHeight / allocation.length) * 0.7;
const barGap = (chartHeight / allocation.length) * 0.3;
// Draw grid lines
ctx.strokeStyle = '#2a3548';
ctx.lineWidth = 1;
for (let i = 0; i <= 5; i++) {
const x = padding.left + (chartWidth * i / 5);
ctx.beginPath();
ctx.moveTo(x, padding.top);
ctx.lineTo(x, height - padding.bottom);
ctx.stroke();
// X-axis labels
ctx.fillStyle = '#6b7a94';
ctx.font = '11px JetBrains Mono';
ctx.textAlign = 'center';
const value = (maxValue * i / 5);
ctx.fillText(formatCurrency(value), x, height - padding.bottom + 20);
}
// Draw bars
allocation.forEach((cat, i) => {
const y = padding.top + (i * (barHeight + barGap)) + barGap / 2;
const barWidth = Math.max(1, (cat.allocation / maxValue) * chartWidth);
// Bar background
ctx.fillStyle = '#1a2234';
ctx.fillRect(padding.left, y, chartWidth, barHeight);
// Animated bar with gradient
const gradient = ctx.createLinearGradient(padding.left, 0, padding.left + barWidth, 0);
gradient.addColorStop(0, cat.color);
gradient.addColorStop(1, cat.color + '80');
ctx.fillStyle = gradient;
ctx.fillRect(padding.left, y, barWidth, barHeight);
// Glow effect
ctx.shadowColor = cat.color;
ctx.shadowBlur = 10;
ctx.fillRect(padding.left, y, barWidth, barHeight);
ctx.shadowBlur = 0;
// Category label
ctx.fillStyle = '#e8edf5';
ctx.font = '12px Space Grotesk';
ctx.textAlign = 'right';
ctx.fillText(cat.name, padding.left - 10, y + barHeight / 2 + 4);
// Value label
ctx.fillStyle = cat.color;
ctx.font = '12px JetBrains Mono';
ctx.textAlign = 'left';
ctx.fillText(formatCurrency(cat.allocation), padding.left + barWidth + 8, y + barHeight / 2 + 4);
});
}
function drawReinsuranceChart() {
const canvas = document.getElementById('reinsuranceChart');
if (!canvas) return;
const ctx = canvas.getContext('2d');
const rect = canvas.parentElement.getBoundingClientRect();
const dpr = window.devicePixelRatio || 1;
canvas.width = rect.width * dpr;
canvas.height = rect.height * dpr;
canvas.style.width = rect.width + 'px';
canvas.style.height = rect.height + 'px';
ctx.scale(dpr, dpr);
const width = rect.width;
const height = rect.height;
const centerX = width / 2;
const centerY = height / 2;
const radius = Math.min(width, height) / 2 - 20;
ctx.clearRect(0, 0, width, height);
const layers = insuranceData.reinsuranceLayers;
const total = layers.reduce((sum, l) => sum + l.amount, 0);
let currentAngle = -Math.PI / 2;
layers.forEach((layer, i) => {
const sliceAngle = (layer.amount / total) * Math.PI * 2;
// Draw slice
ctx.beginPath();
ctx.moveTo(centerX, centerY);
ctx.arc(centerX, centerY, radius, currentAngle, currentAngle + sliceAngle);
ctx.closePath();
ctx.fillStyle = layer.color;
ctx.fill();
// Border
ctx.strokeStyle = '#0a0f1a';
ctx.lineWidth = 2;
ctx.stroke();
// Label
const midAngle = currentAngle + sliceAngle / 2;
const labelRadius = radius * 0.65;
const labelX = centerX + Math.cos(midAngle) * labelRadius;
const labelY = centerY + Math.sin(midAngle) * labelRadius;
if (sliceAngle > 0.3) {
ctx.fillStyle = layer.type === 'retained' ? '#e8edf5' : '#0a0f1a';
ctx.font = '10px Space Grotesk';
ctx.textAlign = 'center';
ctx.textBaseline = 'middle';
ctx.fillText(layer.name, labelX, labelY - 6);
ctx.font = '11px JetBrains Mono';
ctx.fillText('$' + layer.amount + 'M', labelX, labelY + 8);
}
currentAngle += sliceAngle;
});
// Center circle
ctx.beginPath();
ctx.arc(centerX, centerY, radius * 0.35, 0, Math.PI * 2);
ctx.fillStyle = '#0a0f1a';
ctx.fill();
ctx.fillStyle = '#e8edf5';
ctx.font = '11px Space Grotesk';
ctx.textAlign = 'center';
ctx.fillText('Total Capacity', centerX, centerY - 8);
ctx.font = '14px JetBrains Mono';
ctx.fillStyle = '#00d4aa';
ctx.fillText('$2.0B', centerX, centerY + 12);
}
// ============================================
// UI UPDATES
// ============================================
function updateDashboard() {
const metrics = calculateMetrics();
const allocation = calculateCapitalAllocation();
// Update metrics
document.getElementById('availableCapital').textContent = formatCurrency(metrics.totalCapital * 1000);
document.getElementById('scrRatio').textContent = metrics.scrRatio.toFixed(0) + '%';
document.getElementById('climateVar').textContent = formatCurrency(metrics.climateVar);
document.getElementById('reinsEfficiency').textContent = metrics.reinsEfficiency.toFixed(1) + '%';
document.getElementById('cededRatio').textContent = metrics.cededRatio.toFixed(0) + '%';
// Update SCR bar
const scrPercentage = clamp((metrics.scrRatio - 100) / 200 * 100, 0, 100);
document.getElementById('scrBar').style.width = scrPercentage + '%';
// Update risk breakdown
const uwRisk = allocation.filter(c => ['Property CAT', 'Motor', 'Marine'].includes(c.name))
.reduce((sum, c) => sum + c.allocation, 0);
const resRisk = allocation.filter(c => ['Liability', 'Health'].includes(c.name))
.reduce((sum, c) => sum + c.allocation, 0);
const catExp = allocation.filter(c => ['Property CAT', 'Crop'].includes(c.name))
.reduce((sum, c) => sum + c.allocation, 0);
document.getElementById('uwRisk').textContent = formatCurrency(uwRisk);
document.getElementById('resRisk').textContent = formatCurrency(resRisk);
document.getElementById('catExp').textContent = formatCurrency(catExp);
// Update VaR warning
const varWarning = document.getElementById('varWarning');
const scenario = insuranceData.scenarios[currentScenario];
if (scenario.temp >= 3.0) {
varWarning.textContent = 'Severe tail risk';
varWarning.style.color = '#ef4444';
} else if (scenario.temp >= 2.0) {
varWarning.textContent = 'Elevated tail risk';
varWarning.style.color = '#f59e0b';
} else {
varWarning.textContent = 'Moderate tail risk';
varWarning.style.color = '#00d4aa';
}
// Update capital change indicator
const capitalChange = document.getElementById('capitalChange');
const changePercent = (scenario.capitalAdjustment * 100).toFixed(1);
if (scenario.capitalAdjustment > 0) {
capitalChange.textContent = '+' + changePercent + '%';
capitalChange.className = 'text-xs px-2 py-0.5 rounded bg-red-500/20 text-red-400';
} else {
capitalChange.textContent = '+2.4%';
capitalChange.className = 'text-xs px-2 py-0.5 rounded bg-emerald-500/20 text-emerald-400';
}
// Update stress tests
updateStressResults();
// Redraw charts
drawAllocationChart();
drawReinsuranceChart();
}
function updateStressResults() {
const container = document.getElementById('stressResults');
const scenario = insuranceData.scenarios[currentScenario];
const adjustedTests = insuranceData.stressTests.map(test => ({
...test,
adjustedLoss: test.loss * scenario.catMultiplier,
adjustedScrImpact: test.scrImpact * scenario.catMultiplier
}));
container.innerHTML = adjustedTests.map(test => `
<div class="flex items-center gap-4 p-3 bg-[var(--bg-elevated)] rounded-lg">
<div class="w-2 h-8 rounded-full" style="background: ${test.color}"></div>
<div class="flex-1">
<div class="flex justify-between items-center">
<span class="text-sm font-medium">${test.name}</span>
<span class="mono text-sm">${formatCurrency(test.adjustedLoss)}</span>
</div>
<div class="flex justify-between items-center mt-1">
<span class="text-xs text-[var(--fg-muted)]">Probability: ${test.probability}</span>
<span class="text-xs ${test.adjustedScrImpact < -30 ? 'text-red-400' : 'text-yellow-400'}">
SCR: ${test.adjustedScrImpact.toFixed(0)}%
</span>
</div>
</div>
<div class="w-20 h-2 bg-[var(--border)] rounded-full overflow-hidden">
<div class="h-full rounded-full transition-all duration-500"
style="width: ${Math.min(100, Math.abs(test.adjustedScrImpact) * 2)}%; background: ${test.color}"></div>
</div>
</div>
`).join('');
}
// ============================================
// EVENT HANDLERS
// ============================================
function setupEventListeners() {
// Scenario buttons
document.querySelectorAll('.scenario-btn').forEach(btn => {
btn.addEventListener('click', () => {
document.querySelectorAll('.scenario-btn').forEach(b => {
b.classList.remove('active');
b.setAttribute('aria-checked', 'false');
});
btn.classList.add('active');
btn.setAttribute('aria-checked', 'true');
currentScenario = btn.dataset.scenario;
updateDashboard();
});
});
// Tab buttons
document.querySelectorAll('.tab-btn').forEach(btn => {
btn.addEventListener('click', () => {
document.querySelectorAll('.tab-btn').forEach(b => {
b.classList.remove('bg-[var(--accent)]', 'text-[var(--bg)]');
b.classList.add('border', 'border-[var(--border)]', 'text-[var(--fg-muted)]');
});
btn.classList.add('bg-[var(--accent)]', 'text-[var(--bg)]');
btn.classList.remove('border', 'border-[var(--border)]', 'text-[var(--fg-muted)]');
chartView = btn.dataset.view;
drawAllocationChart();
});
});
// Sliders
document.getElementById('catLoad').addEventListener('input', (e) => {
catLoad = parseInt(e.target.value);
document.getElementById('catLoadValue').textContent = catLoad + '%';
updateDashboard();
});
document.getElementById('reinsRetention').addEventListener('input', (e) => {
retention = parseInt(e.target.value);
document.getElementById('retentionValue').textContent = '$' + retention + 'M';
updateDashboard();
});
document.getElementById('riskAppetite').addEventListener('input', (e) => {
riskAppetite = parseInt(e.target.value);
const labels = ['Very Low', 'Low', 'Medium', 'High', 'Very High'];
document.getElementById('appetiteValue').textContent = labels[riskAppetite - 1];
updateDashboard();
});
// Resize handler
let resizeTimeout;
window.addEventListener('resize', () => {
clearTimeout(resizeTimeout);
resizeTimeout = setTimeout(() => {
drawAllocationChart();
drawReinsuranceChart();
}, 100);
});
}
function recalculateCapital() {
// Simulate recalculation with animation
const btn = event.currentTarget;
btn.disabled = true;
btn.innerHTML = `
<svg class="animate-spin" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M21 12a9 9 0 1 1-6.219-8.56"/>
</svg>
Calculating...
`;
setTimeout(() => {
updateDashboard();
const now = new Date();
document.getElementById('lastUpdate').textContent = now.toISOString().replace('T', ' ').substr(0, 19);
btn.disabled = false;
btn.innerHTML = `
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<path d="M21 12a9 9 0 0 0-9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"/>
<path d="M3 3v5h5"/>
<path d="M3 12a9 9 0 0 0 9 9 9.75 9.75 0 0 0 6.74-2.74L21 16"/>
<path d="M16 21h5v-5"/>
</svg>
Recalculate
`;
}, 1500);
}
// ============================================
// INITIALIZATION
// ============================================
function init() {
setupEventListeners();
updateDashboard();
// Update timestamp every second
setInterval(() => {
const now = new Date();
// Only update if not recently recalculated
}, 1000);
}
// Start the application
document.addEventListener('DOMContentLoaded', init);
</script>
</body>
</html>