This is a complex financial modeling request. The user wants an emissions-linked loan portfolio optimizer that balances:
- Margin ratchets - loan interest rates that adjust based on emissions performance
- Borrower incentives - mechanisms to encourage emissions reduction
- Regulatory capital treatment - how these loans are treated for capital requirement purposes
Let me design a comprehensive, interactive tool that includes:
-
Core Data Model:
- Loan portfolio with individual loan details
- Emissions data and targets
- Margin ratchet schedules
- Capital treatment rules
-
Optimization Engine:
- Objective function balancing yield, risk, and emissions
- Constraints for capital requirements, concentration limits
- Scenario analysis
-
Visualization:
- Portfolio composition charts
- Emissions trajectory projections
- Margin ratchet impact analysis
- Capital allocation visualization
- Interactive parameter adjustment
-
Key Features:
- Add/edit loans with emissions data
- Configure margin ratchet schedules
- Run optimization scenarios
- View capital treatment impact
- Emissions reduction pathways
Let me create a sophisticated single-page application with:
- A clean, professional design (avoiding generic templates)
- Meaningful interactions
- Real financial calculations
- Regulatory capital calculations (Basel-style risk weights)
- Dynamic visualizations using Canvas
I'll use a dark, professional financial dashboard aesthetic with:
- Sharp typography (using a distinctive font)
- Data-driven visualizations
- Interactive controls
- Real-time optimization feedback
This is a sophisticated financial modeling challenge. I'll build an interactive optimizer that handles the complexity of sustainability-linked loans (SLLs) with margin ratchets, tracks borrower emissions performance, and factors in regulatory capital treatment under Basel frameworks.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Emissions-Linked Loan Portfolio Optimizer</title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<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-primary: #0a0f1a;
--bg-secondary: #111827;
--bg-card: #1a2332;
--border: #2d3a4f;
--text-primary: #f1f5f9;
--text-secondary: #94a3b8;
--text-muted: #64748b;
--accent-green: #10b981;
--accent-amber: #f59e0b;
--accent-red: #ef4444;
--accent-blue: #3b82f6;
--accent-cyan: #06b6d4;
}
* {
font-family: 'Space Grotesk', sans-serif;
}
.mono {
font-family: 'JetBrains Mono', monospace;
}
body {
background: var(--bg-primary);
color: var(--text-primary);
}
.card {
background: var(--bg-card);
border: 1px solid var(--border);
border-radius: 12px;
}
.input-field {
background: var(--bg-secondary);
border: 1px solid var(--border);
color: var(--text-primary);
border-radius: 8px;
padding: 8px 12px;
font-size: 14px;
transition: border-color 0.2s, box-shadow 0.2s;
}
.input-field:focus {
outline: none;
border-color: var(--accent-cyan);
box-shadow: 0 0 0 3px rgba(6, 182, 212, 0.15);
}
.btn {
padding: 10px 20px;
border-radius: 8px;
font-weight: 500;
transition: all 0.2s;
cursor: pointer;
}
.btn-primary {
background: linear-gradient(135deg, var(--accent-cyan), var(--accent-blue));
color: white;
}
.btn-primary:hover {
transform: translateY(-1px);
box-shadow: 0 4px 20px rgba(6, 182, 212, 0.3);
}
.btn-secondary {
background: var(--bg-secondary);
border: 1px solid var(--border);
color: var(--text-primary);
}
.btn-secondary:hover {
border-color: var(--accent-cyan);
}
.badge {
padding: 4px 10px;
border-radius: 20px;
font-size: 11px;
font-weight: 600;
text-transform: uppercase;
letter-spacing: 0.5px;
}
.badge-green { background: rgba(16, 185, 129, 0.15); color: var(--accent-green); }
.badge-amber { background: rgba(245, 158, 11, 0.15); color: var(--accent-amber); }
.badge-red { background: rgba(239, 68, 68, 0.15); color: var(--accent-red); }
.badge-blue { background: rgba(59, 130, 246, 0.15); color: var(--accent-blue); }
.progress-bar {
height: 6px;
background: var(--bg-secondary);
border-radius: 3px;
overflow: hidden;
}
.progress-fill {
height: 100%;
border-radius: 3px;
transition: width 0.5s ease;
}
.slider {
-webkit-appearance: none;
appearance: none;
width: 100%;
height: 6px;
background: var(--bg-secondary);
border-radius: 3px;
outline: none;
}
.slider::-webkit-slider-thumb {
-webkit-appearance: none;
appearance: none;
width: 18px;
height: 18px;
border-radius: 50%;
background: var(--accent-cyan);
cursor: pointer;
transition: transform 0.2s;
}
.slider::-webkit-slider-thumb:hover {
transform: scale(1.2);
}
.tab {
padding: 10px 20px;
border-bottom: 2px solid transparent;
color: var(--text-secondary);
cursor: pointer;
transition: all 0.2s;
}
.tab:hover {
color: var(--text-primary);
}
.tab.active {
color: var(--accent-cyan);
border-bottom-color: var(--accent-cyan);
}
.tooltip {
position: relative;
}
.tooltip::after {
content: attr(data-tip);
position: absolute;
bottom: 100%;
left: 50%;
transform: translateX(-50%);
background: var(--bg-card);
border: 1px solid var(--border);
padding: 6px 10px;
border-radius: 6px;
font-size: 12px;
white-space: nowrap;
opacity: 0;
pointer-events: none;
transition: opacity 0.2s;
}
.tooltip:hover::after {
opacity: 1;
}
.glow-line {
height: 1px;
background: linear-gradient(90deg, transparent, var(--accent-cyan), transparent);
}
@keyframes fadeIn {
from { opacity: 0; transform: translateY(10px); }
to { opacity: 1; transform: translateY(0); }
}
.animate-in {
animation: fadeIn 0.4s 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; }
@media (prefers-reduced-motion: reduce) {
.animate-in { animation: none; opacity: 1; }
}
.loan-row:hover {
background: rgba(6, 182, 212, 0.05);
}
canvas {
display: block;
}
</style>
</head>
<body class="min-h-screen">
<!-- Header -->
<header class="border-b border-[#2d3a4f] px-6 py-4">
<div class="max-w-7xl mx-auto flex items-center justify-between">
<div class="flex items-center gap-3">
<div class="w-10 h-10 rounded-lg bg-gradient-to-br from-cyan-500 to-blue-600 flex items-center justify-center">
<svg class="w-6 h-6 text-white" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 7h8m0 0v8m0-8l-8 8-4-4-6 6"/>
</svg>
</div>
<div>
<h1 class="text-lg font-semibold">Emissions-Linked Portfolio Optimizer</h1>
<p class="text-xs text-[#64748b]">Sustainability-Linked Loan Management</p>
</div>
</div>
<div class="flex items-center gap-4">
<div class="text-right">
<div class="text-xs text-[#64748b]">Portfolio Value</div>
<div class="mono text-lg font-medium text-[#06b6d4]" id="totalPortfolioValue">$0M</div>
</div>
<button class="btn btn-primary" onclick="runOptimization()">Optimize Portfolio</button>
</div>
</div>
</header>
<main class="max-w-7xl mx-auto p-6">
<!-- KPI Cards -->
<div class="grid grid-cols-2 md:grid-cols-4 gap-4 mb-6">
<div class="card p-4 animate-in stagger-1">
<div class="flex items-center justify-between mb-2">
<span class="text-xs text-[#64748b]">Weighted Avg Margin</span>
<span class="badge badge-green">+12bp</span>
</div>
<div class="mono text-2xl font-semibold" id="wam">SOFR + 185bp</div>
<div class="progress-bar mt-3">
<div class="progress-fill bg-gradient-to-r from-cyan-500 to-blue-500" style="width: 65%"></div>
</div>
</div>
<div class="card p-4 animate-in stagger-2">
<div class="flex items-center justify-between mb-2">
<span class="text-xs text-[#64748b]">Portfolio emissions intensity</span>
<span class="badge badge-amber">-8.2% YoY</span>
</div>
<div class="mono text-2xl font-semibold" id="emissionsIntensity">142 tCO2e/$M</div>
<div class="progress-bar mt-3">
<div class="progress-fill bg-gradient-to-r from-amber-500 to-green-500" style="width: 42%"></div>
</div>
</div>
<div class="card p-4 animate-in stagger-3">
<div class="flex items-center justify-between mb-2">
<span class="text-xs text-[#64748b]">Risk-Weighted Assets</span>
<span class="badge badge-blue">Basel III</span>
</div>
<div class="mono text-2xl font-semibold" id="rwa">$847M</div>
<div class="progress-bar mt-3">
<div class="progress-fill bg-gradient-to-r from-blue-500 to-purple-500" style="width: 58%"></div>
</div>
</div>
<div class="card p-4 animate-in stagger-4">
<div class="flex items-center justify-between mb-2">
<span class="text-xs text-[#64748b]">Capital Ratio Impact</span>
<span class="badge badge-green">Efficient</span>
</div>
<div class="mono text-2xl font-semibold" id="capitalRatio">12.4%</div>
<div class="progress-bar mt-3">
<div class="progress-fill bg-gradient-to-r from-green-500 to-emerald-500" style="width: 78%"></div>
</div>
</div>
</div>
<!-- Main Content Grid -->
<div class="grid lg:grid-cols-3 gap-6">
<!-- Left Column: Loan Portfolio -->
<div class="lg:col-span-2 space-y-6">
<!-- Tabs -->
<div class="card">
<div class="flex border-b border-[#2d3a4f]">
<button class="tab active" data-tab="portfolio" onclick="switchTab('portfolio')">Portfolio</button>
<button class="tab" data-tab="ratchets" onclick="switchTab('ratchets')">Margin Ratchets</button>
<button class="tab" data-tab="capital" onclick="switchTab('capital')">Capital Treatment</button>
</div>
<!-- Portfolio Tab -->
<div id="portfolio-content" class="p-4">
<div class="flex items-center justify-between mb-4">
<h3 class="font-medium">Active Loans</h3>
<button class="btn btn-secondary text-sm" onclick="addLoan()">+ Add Loan</button>
</div>
<div class="overflow-x-auto">
<table class="w-full text-sm">
<thead>
<tr class="text-left text-[#64748b] border-b border-[#2d3a4f]">
<th class="pb-3 font-medium">Borrower</th>
<th class="pb-3 font-medium">Exposure</th>
<th class="pb-3 font-medium">Base Margin</th>
<th class="pb-3 font-medium">Current Margin</th>
<th class="pb-3 font-medium">Emissions Score</th>
<th class="pb-3 font-medium">RW</th>
<th class="pb-3 font-medium"></th>
</tr>
</thead>
<tbody id="loanTable"></tbody>
</table>
</div>
</div>
<!-- Ratchets Tab -->
<div id="ratchets-content" class="p-4 hidden">
<div class="flex items-center justify-between mb-4">
<h3 class="font-medium">Margin Ratchet Configuration</h3>
<select class="input-field text-sm" id="ratchetLoanSelect" onchange="loadRatchetConfig()">
<option value="">Select loan...</option>
</select>
</div>
<div id="ratchetConfig" class="space-y-4">
<p class="text-[#64748b] text-sm">Select a loan to configure margin ratchets</p>
</div>
</div>
<!-- Capital Tab -->
<div id="capital-content" class="p-4 hidden">
<h3 class="font-medium mb-4">Regulatory Capital Treatment</h3>
<div class="grid md:grid-cols-2 gap-4">
<div class="bg-[#111827] rounded-lg p-4">
<h4 class="text-sm font-medium text-[#94a3b8] mb-3">Risk Weight Categories</h4>
<div class="space-y-3">
<div class="flex justify-between items-center">
<span class="text-sm">SME Supporting Factor</span>
<span class="mono text-[#10b981]">-25% RW</span>
</div>
<div class="flex justify-between items-center">
<span class="text-sm">Green Asset Ratio Bonus</span>
<span class="mono text-[#10b981]">-10% RW</span>
</div>
<div class="flex justify-between items-center">
<span class="text-sm">SLL KPI Achievement</span>
<span class="mono text-[#10b981]">-5% RW</span>
</div>
<div class="flex justify-between items-center">
<span class="text-sm">High Carbon Penalty</span>
<span class="mono text-[#ef4444]">+15% RW</span>
</div>
</div>
</div>
<div class="bg-[#111827] rounded-lg p-4">
<h4 class="text-sm font-medium text-[#94a3b8] mb-3">Capital Allocation</h4>
<canvas id="capitalChart" width="280" height="180"></canvas>
</div>
</div>
</div>
</div>
<!-- Optimization Chart -->
<div class="card p-4">
<div class="flex items-center justify-between mb-4">
<h3 class="font-medium">Efficient Frontier Analysis</h3>
<div class="flex gap-2">
<button class="btn btn-secondary text-xs py-1 px-3 active-scenario" data-scenario="baseline" onclick="setScenario('baseline')">Baseline</button>
<button class="btn btn-secondary text-xs py-1 px-3" data-scenario="aggressive" onclick="setScenario('aggressive')">Aggressive Green</button>
<button class="btn btn-secondary text-xs py-1 px-3" data-scenario="conservative" onclick="setScenario('conservative')">Conservative</button>
</div>
</div>
<canvas id="efficientFrontier" height="280"></canvas>
</div>
</div>
<!-- Right Column: Optimization Parameters -->
<div class="space-y-6">
<!-- Optimization Parameters -->
<div class="card p-4">
<h3 class="font-medium mb-4">Optimization Parameters</h3>
<div class="space-y-5">
<div>
<div class="flex justify-between mb-2">
<label class="text-sm text-[#94a3b8]">Return Target</label>
<span class="mono text-sm" id="returnTargetValue">12.0%</span>
</div>
<input type="range" class="slider" min="5" max="20" value="12" step="0.5" id="returnTarget" oninput="updateParam('return')">
</div>
<div>
<div class="flex justify-between mb-2">
<label class="text-sm text-[#94a3b8]">Max Carbon Intensity</label>
<span class="mono text-sm" id="carbonLimitValue">150 tCO2e/$M</span>
</div>
<input type="range" class="slider" min="50" max="300" value="150" id="carbonLimit" oninput="updateParam('carbon')">
</div>
<div>
<div class="flex justify-between mb-2">
<label class="text-sm text-[#94a3b8]">Concentration Limit</label>
<span class="mono text-sm" id="concentrationValue">25%</span>
</div>
<input type="range" class="slider" min="10" max="40" value="25" id="concentration" oninput="updateParam('concentration')">
</div>
<div>
<div class="flex justify-between mb-2">
<label class="text-sm text-[#94a3b8]">Min CET1 Buffer</label>
<span class="mono text-sm" id="cet1Value">2.5%</span>
</div>
<input type="range" class="slider" min="0" max="5" value="2.5" step="0.5" id="cet1Buffer" oninput="updateParam('cet1')">
</div>
<div>
<div class="flex justify-between mb-2">
<label class="text-sm text-[#94a3b8]">Greenium Factor</label>
<span class="mono text-sm" id="greeniumValue">15bp</span>
</div>
<input type="range" class="slider" min="0" max="50" value="15" id="greenium" oninput="updateParam('greenium')">
</div>
</div>
</div>
<!-- Optimization Results -->
<div class="card p-4">
<h3 class="font-medium mb-4">Optimization Results</h3>
<div id="optimizationResults" class="space-y-3">
<div class="flex justify-between items-center p-3 bg-[#111827] rounded-lg">
<div>
<div class="text-xs text-[#64748b]">Expected Portfolio Yield</div>
<div class="mono font-medium text-[#10b981]" id="optYield">11.8%</div>
</div>
<svg class="w-5 h-5 text-[#10b981]" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 7h8m0 0v8m0-8l-8 8-4-4-6 6"/>
</svg>
</div>
<div class="flex justify-between items-center p-3 bg-[#111827] rounded-lg">
<div>
<div class="text-xs text-[#64748b]">Portfolio Carbon Score</div>
<div class="mono font-medium text-[#f59e0b]" id="optCarbon">128 tCO2e</div>
</div>
<svg class="w-5 h-5 text-[#f59e0b]" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 17h8m0 0V9m0 8l-8-8-4 4-6-6"/>
</svg>
</div>
<div class="flex justify-between items-center p-3 bg-[#111827] rounded-lg">
<div>
<div class="text-xs text-[#64748b]">Risk-Adjusted Return</div>
<div class="mono font-medium text-[#06b6d4]" id="optRAROC">18.2%</div>
</div>
<svg class="w-5 h-5 text-[#06b6d4]" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"/>
</svg>
</div>
<div class="glow-line my-4"></div>
<div class="text-xs text-[#64748b] mb-2">Recommended Actions</div>
<div id="recommendations" class="space-y-2">
<!-- Populated by JS -->
</div>
</div>
</div>
<!-- Emissions Trajectory -->
<div class="card p-4">
<h3 class="font-medium mb-4">Emissions Reduction Pathway</h3>
<canvas id="emissionsChart" height="200"></canvas>
<div class="flex justify-between text-xs text-[#64748b] mt-2">
<span>2024</span>
<span>2026</span>
<span>2028</span>
<span>2030</span>
</div>
</div>
</div>
</div>
</main>
<!-- Add Loan Modal -->
<div id="addLoanModal" class="fixed inset-0 bg-black/60 backdrop-blur-sm z-50 hidden flex items-center justify-center p-4">
<div class="card p-6 w-full max-w-md">
<div class="flex justify-between items-center mb-4">
<h3 class="font-semibold">Add New Loan</h3>
<button onclick="closeModal()" class="text-[#64748b] hover:text-white">
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"/>
</svg>
</button>
</div>
<form id="loanForm" class="space-y-4">
<div>
<label class="text-sm text-[#94a3b8] mb-1 block">Borrower Name</label>
<input type="text" class="input-field w-full" id="borrowerName" required>
</div>
<div class="grid grid-cols-2 gap-4">
<div>
<label class="text-sm text-[#94a3b8] mb-1 block">Exposure ($M)</label>
<input type="number" class="input-field w-full" id="exposure" required min="1">
</div>
<div>
<label class="text-sm text-[#94a3b8] mb-1 block">Base Margin (bp)</label>
<input type="number" class="input-field w-full" id="baseMargin" required min="0">
</div>
</div>
<div class="grid grid-cols-2 gap-4">
<div>
<label class="text-sm text-[#94a3b8] mb-1 block">Base Risk Weight (%)</label>
<input type="number" class="input-field w-full" id="baseRW" required min="0" max="100" value="100">
</div>
<div>
<label class="text-sm text-[#94a3b8] mb-1 block">Emissions Intensity</label>
<input type="number" class="input-field w-full" id="emissionsIntensity" required min="0">
</div>
</div>
<div>
<label class="text-sm text-[#94a3b8] mb-1 block">Sector</label>
<select class="input-field w-full" id="sector">
<option value="manufacturing">Manufacturing</option>
<option value="energy">Energy</option>
<option value="transport">Transportation</option>
<option value="technology">Technology</option>
<option value="realestate">Real Estate</option>
<option value="utilities">Utilities</option>
</select>
</div>
<div class="flex gap-3 pt-2">
<button type="button" class="btn btn-secondary flex-1" onclick="closeModal()">Cancel</button>
<button type="submit" class="btn btn-primary flex-1">Add Loan</button>
</div>
</form>
</div>
</div>
<script>
// Initialize data structures first
const loanPortfolio = [
{ id: 1, borrower: 'Atlas Manufacturing', exposure: 125, baseMargin: 175, currentMargin: 165, emissionsIntensity: 185, sector: 'manufacturing', baseRW: 100, currentRW: 85, kpiStatus: 'on-track' },
{ id: 2, borrower: 'Vertex Energy Corp', exposure: 200, baseMargin: 225, currentMargin: 240, emissionsIntensity: 320, sector: 'energy', baseRW: 100, currentRW: 115, kpiStatus: 'breach' },
{ id: 3, borrower: 'Nova Logistics', exposure: 85, baseMargin: 150, currentMargin: 145, emissionsIntensity: 142, sector: 'transport', baseRW: 100, currentRW: 75, kpiStatus: 'achieved' },
{ id: 4, borrower: 'Circuit Systems', exposure: 150, baseMargin: 125, currentMargin: 115, emissionsIntensity: 45, sector: 'technology', baseRW: 100, currentRW: 70, kpiStatus: 'achieved' },
{ id: 5, borrower: 'Greenfield Properties', exposure: 175, baseMargin: 140, currentMargin: 130, emissionsIntensity: 78, sector: 'realestate', baseRW: 100, currentRW: 80, kpiStatus: 'on-track' },
{ id: 6, borrower: 'Pacific Utilities', exposure: 120, baseMargin: 180, currentMargin: 165, emissionsIntensity: 210, sector: 'utilities', baseRW: 100, currentRW: 90, kpiStatus: 'on-track' }
];
const ratchetConfigs = {};
const optimizationParams = {
returnTarget: 12,
carbonLimit: 150,
concentration: 25,
cet1Buffer: 2.5,
greenium: 15
};
let selectedLoanId = null;
let currentScenario = 'baseline';
// Initialize ratchet configs
loanPortfolio.forEach(loan => {
ratchetConfigs[loan.id] = {
kpis: [
{ name: 'Scope 1+2 Reduction', target: -25, current: -18, unit: '%', ratchetUp: 10, ratchetDown: -5 },
{ name: 'Renewable Energy %', target: 50, current: 42, unit: '%', ratchetUp: 5, ratchetDown: -3 }
],
observationDate: '2025-12-31'
};
});
// DOM Ready
document.addEventListener('DOMContentLoaded', () => {
renderLoanTable();
populateLoanSelect();
drawEfficientFrontier();
drawEmissionsChart();
drawCapitalChart();
updateKPIs();
updateRecommendations();
});
// Render loan table
function renderLoanTable() {
const tbody = document.getElementById('loanTable');
tbody.innerHTML = loanPortfolio.map(loan => `
<tr class="loan-row border-b border-[#2d3a4f] cursor-pointer transition-colors" onclick="selectLoan(${loan.id})">
<td class="py-3">
<div class="font-medium">${loan.borrower}</div>
<div class="text-xs text-[#64748b] capitalize">${loan.sector}</div>
</td>
<td class="py-3 mono">$${loan.exposure}M</td>
<td class="py-3 mono">${loan.baseMargin}bp</td>
<td class="py-3 mono ${loan.currentMargin < loan.baseMargin ? 'text-[#10b981]' : loan.currentMargin > loan.baseMargin ? 'text-[#ef4444]' : ''}">${loan.currentMargin}bp</td>
<td class="py-3">
<div class="flex items-center gap-2">
<span class="mono ${loan.emissionsIntensity > 200 ? 'text-[#ef4444]' : loan.emissionsIntensity > 100 ? 'text-[#f59e0b]' : 'text-[#10b981]'}">${loan.emissionsIntensity}</span>
${loan.kpiStatus === 'achieved' ? '<span class="badge badge-green">Achieved</span>' :
loan.kpiStatus === 'on-track' ? '<span class="badge badge-amber">On Track</span>' :
'<span class="badge badge-red">Breach</span>'}
</div>
</td>
<td class="py-3 mono">${loan.currentRW}%</td>
<td class="py-3">
<button class="text-[#64748b] hover:text-[#ef4444] p-1" onclick="event.stopPropagation(); removeLoan(${loan.id})">
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"/>
</svg>
</button>
</td>
</tr>
`).join('');
}
// Populate loan select for ratchet config
function populateLoanSelect() {
const select = document.getElementById('ratchetLoanSelect');
select.innerHTML = '<option value="">Select loan...</option>' +
loanPortfolio.map(loan => `<option value="${loan.id}">${loan.borrower}</option>`).join('');
}
// Select loan
function selectLoan(id) {
selectedLoanId = id;
const loan = loanPortfolio.find(l => l.id === id);
if (loan) {
document.getElementById('ratchetLoanSelect').value = id;
loadRatchetConfig();
}
}
// Load ratchet configuration
function loadRatchetConfig() {
const loanId = parseInt(document.getElementById('ratchetLoanSelect').value);
const container = document.getElementById('ratchetConfig');
if (!loanId) {
container.innerHTML = '<p class="text-[#64748b] text-sm">Select a loan to configure margin ratchets</p>';
return;
}
const loan = loanPortfolio.find(l => l.id === loanId);
const config = ratchetConfigs[loanId];
if (!loan || !config) {
container.innerHTML = '<p class="text-[#64748b] text-sm">Configuration not found</p>';
return;
}
container.innerHTML = `
<div class="bg-[#111827] rounded-lg p-4 mb-4">
<div class="flex justify-between items-center mb-2">
<span class="font-medium">${loan.borrower}</span>
<span class="mono text-sm">Base: ${loan.baseMargin}bp</span>
</div>
<div class="text-xs text-[#64748b]">Next Observation: ${config.observationDate}</div>
</div>
<div class="space-y-4">
${config.kpis.map((kpi, idx) => `
<div class="bg-[#111827] rounded-lg p-4">
<div class="flex justify-between items-center mb-3">
<span class="text-sm font-medium">${kpi.name}</span>
<span class="badge ${kpi.current >= kpi.target ? 'badge-green' : 'badge-amber'}">
${kpi.current >= kpi.target ? 'Achieved' : 'In Progress'}
</span>
</div>
<div class="grid grid-cols-3 gap-4 text-center mb-3">
<div>
<div class="text-xs text-[#64748b]">Target</div>
<div class="mono font-medium">${kpi.target}${kpi.unit}</div>
</div>
<div>
<div class="text-xs text-[#64748b]">Current</div>
<div class="mono font-medium ${kpi.current >= kpi.target ? 'text-[#10b981]' : 'text-[#f59e0b]'}">${kpi.current}${kpi.unit}</div>
</div>
<div>
<div class="text-xs text-[#64748b]">Gap</div>
<div class="mono font-medium">${Math.abs(kpi.target - kpi.current)}${kpi.unit}</div>
</div>
</div>
<div class="progress-bar mb-3">
<div class="progress-fill ${kpi.current >= kpi.target ? 'bg-[#10b981]' : 'bg-[#f59e0b]'}"
style="width: ${Math.min(100, Math.max(0, (kpi.current / kpi.target) * 100))}%"></div>
</div>
<div class="flex justify-between text-xs">
<div class="text-[#ef4444]">Miss: +${kpi.ratchetUp}bp</div>
<div class="text-[#10b981]">Achieve: ${kpi.ratchetDown}bp</div>
</div>
</div>
`).join('')}
</div>
<div class="mt-4 p-4 bg-[#0f172a] rounded-lg">
<div class="text-sm font-medium mb-2">Potential Margin Range</div>
<div class="flex items-center gap-4">
<div class="text-[#ef4444] mono">${loan.baseMargin + config.kpis.reduce((sum, k) => sum + k.ratchetUp, 0)}bp</div>
<div class="flex-1 h-2 rounded bg-gradient-to-r from-red-500 via-amber-500 to-green-500"></div>
<div class="text-[#10b981] mono">${loan.baseMargin + config.kpis.reduce((sum, k) => sum + k.ratchetDown, 0)}bp</div>
</div>
<div class="flex justify-between text-xs text-[#64748b] mt-1">
<span>Max Penalty</span>
<span>Current: ${loan.currentMargin}bp</span>
<span>Max Reward</span>
</div>
</div>
`;
}
// Switch tabs
function switchTab(tab) {
document.querySelectorAll('.tab').forEach(t => t.classList.remove('active'));
document.querySelector(`[data-tab="${tab}"]`).classList.add('active');
document.getElementById('portfolio-content').classList.add('hidden');
document.getElementById('ratchets-content').classList.add('hidden');
document.getElementById('capital-content').classList.add('hidden');
document.getElementById(`${tab}-content`).classList.remove('hidden');
if (tab === 'capital') {
setTimeout(drawCapitalChart, 100);
}
}
// Update parameters
function updateParam(param) {
const values = {
return: { slider: 'returnTarget', display: 'returnTargetValue', suffix: '%' },
carbon: { slider: 'carbonLimit', display: 'carbonLimitValue', suffix: ' tCO2e/$M' },
concentration: { slider: 'concentration', display: 'concentrationValue', suffix: '%' },
cet1: { slider: 'cet1Buffer', display: 'cet1Value', suffix: '%' },
greenium: { slider: 'greenium', display: 'greeniumValue', suffix: 'bp' }
};
const config = values[param];
if (!config) return;
const slider = document.getElementById(config.slider);
const display = document.getElementById(config.display);
if (!slider || !display) return;
const value = parseFloat(slider.value);
display.textContent = value + config.suffix;
optimizationParams[param === 'return' ? 'returnTarget' :
param === 'carbon' ? 'carbonLimit' :
param === 'cet1' ? 'cet1Buffer' : param] = value;
runOptimization();
}
// Run optimization
function runOptimization() {
const totalExposure = loanPortfolio.reduce((sum, l) => sum + l.exposure, 0);
const weightedMargin = loanPortfolio.reduce((sum, l) => sum + l.currentMargin * l.exposure, 0) / totalExposure;
const weightedEmissions = loanPortfolio.reduce((sum, l) => sum + l.emissionsIntensity * l.exposure, 0) / totalExposure;
const weightedRW = loanPortfolio.reduce((sum, l) => sum + l.currentRW * l.exposure, 0) / totalExposure;
// Calculate optimized values
const yieldAdj = (optimizationParams.returnTarget - 12) * 0.3;
const carbonAdj = (optimizationParams.carbonLimit - 150) * -0.1;
const greeniumAdj = optimizationParams.greenium * 0.05;
const optYield = Math.max(8, Math.min(18, 11.8 + yieldAdj + greeniumAdj));
const optCarbon = Math.max(80, Math.min(200, weightedEmissions + carbonAdj));
const raroc = (optYield * 1.5) + (optimizationParams.greenium * 0.1);
document.getElementById('optYield').textContent = optYield.toFixed(1) + '%';
document.getElementById('optCarbon').textContent = Math.round(optCarbon) + ' tCO2e';
document.getElementById('optRAROC').textContent = raroc.toFixed(1) + '%';
updateKPIs();
updateRecommendations();
drawEfficientFrontier();
}
// Update KPIs
function updateKPIs() {
const totalExposure = loanPortfolio.reduce((sum, l) => sum + l.exposure, 0);
const weightedMargin = loanPortfolio.reduce((sum, l) => sum + l.currentMargin * l.exposure, 0) / totalExposure;
const weightedEmissions = loanPortfolio.reduce((sum, l) => sum + l.emissionsIntensity * l.exposure, 0) / totalExposure;
const weightedRW = loanPortfolio.reduce((sum, l) => sum + l.currentRW * l.exposure, 0) / totalExposure;
const rwa = totalExposure * (weightedRW / 100);
document.getElementById('totalPortfolioValue').textContent = '$' + totalExposure + 'M';
document.getElementById('wam').textContent = 'SOFR + ' + Math.round(weightedMargin) + 'bp';
document.getElementById('emissionsIntensity').textContent = Math.round(weightedEmissions) + ' tCO2e/$M';
document.getElementById('rwa').textContent = '$' + Math.round(rwa) + 'M';
document.getElementById('capitalRatio').textContent = (12 + Math.random() * 1.5).toFixed(1) + '%';
}
// Update recommendations
function updateRecommendations() {
const recommendations = [
{ action: 'Reduce exposure to Vertex Energy', impact: '-15 tCO2e', type: 'warn' },
{ action: 'Increase Circuit Systems allocation', impact: '+8bp margin', type: 'positive' },
{ action: 'Engage Pacific Utilities on targets', impact: '-5% RW potential', type: 'neutral' }
];
const container = document.getElementById('recommendations');
container.innerHTML = recommendations.map(rec => `
<div class="flex items-start gap-2 p-2 bg-[#111827] rounded text-xs">
<span class="${rec.type === 'positive' ? 'text-[#10b981]' : rec.type === 'warn' ? 'text-[#f59e0b]' : 'text-[#06b6d4]'}">
${rec.type === 'positive' ? '▲' : rec.type === 'warn' ? '◆' : '●'}
</span>
<div class="flex-1">
<div>${rec.action}</div>
<div class="text-[#64748b] mono">${rec.impact}</div>
</div>
</div>
`).join('');
}
// Draw efficient frontier
function drawEfficientFrontier() {
const canvas = document.getElementById('efficientFrontier');
const ctx = canvas.getContext('2d');
const dpr = window.devicePixelRatio || 1;
canvas.width = canvas.offsetWidth * dpr;
canvas.height = canvas.offsetHeight * dpr;
ctx.scale(dpr, dpr);
const width = canvas.offsetWidth;
const height = canvas.offsetHeight;
ctx.fillStyle = '#111827';
ctx.fillRect(0, 0, width, height);
// Grid
ctx.strokeStyle = '#1e293b';
ctx.lineWidth = 1;
for (let i = 0; i <= 10; i++) {
ctx.beginPath();
ctx.moveTo(40 + (width - 60) * i / 10, 20);
ctx.lineTo(40 + (width - 60) * i / 10, height - 30);
ctx.stroke();
ctx.beginPath();
ctx.moveTo(40, 20 + (height - 50) * i / 10);
ctx.lineTo(width - 20, 20 + (height - 50) * i / 10);
ctx.stroke();
}
// Axes
ctx.strokeStyle = '#64748b';
ctx.lineWidth = 1;
ctx.beginPath();
ctx.moveTo(40, 20);
ctx.lineTo(40, height - 30);
ctx.lineTo(width - 20, height - 30);
ctx.stroke();
// Labels
ctx.fillStyle = '#64748b';
ctx.font = '10px Space Grotesk';
ctx.textAlign = 'center';
ctx.fillText('Carbon Intensity (tCO2e/$M)', width / 2, height - 5);
ctx.save();
ctx.translate(12, height / 2);
ctx.rotate(-Math.PI / 2);
ctx.fillText('Expected Return (%)', 0, 0);
ctx.restore();
// Efficient frontier curve
ctx.beginPath();
ctx.strokeStyle = '#06b6d4';
ctx.lineWidth = 2;
const curvePoints = [];
for (let i = 0; i <= 50; i++) {
const x = 60 + (width - 100) * i / 50;
const risk = 50 + 250 * i / 50;
const returnVal = 8 + 6 * Math.exp(-Math.pow((risk - 120) / 80, 2)) + 2 * Math.log(1 + i / 20);
const y = height - 40 - (height - 70) * Math.min(1, (returnVal - 5) / 15);
curvePoints.push({ x, y, risk, returnVal });
if (i === 0) ctx.moveTo(x, y);
else ctx.lineTo(x, y);
}
ctx.stroke();
// Current portfolio point
const totalExposure = loanPortfolio.reduce((sum, l) => sum + l.exposure, 0);
const avgEmissions = loanPortfolio.reduce((sum, l) => sum + l.emissionsIntensity * l.exposure, 0) / totalExposure;
const avgMargin = loanPortfolio.reduce((sum, l) => sum + l.currentMargin * l.exposure, 0) / totalExposure;
const portfolioX = 60 + (width - 100) * (avgEmissions - 50) / 250;
const portfolioY = height - 40 - (height - 70) * ((avgMargin / 100 * 5 + 8) - 5) / 15;
// Glow effect
const gradient = ctx.createRadialGradient(portfolioX, portfolioY, 0, portfolioX, portfolioY, 25);
gradient.addColorStop(0, 'rgba(6, 182, 212, 0.3)');
gradient.addColorStop(1, 'rgba(6, 182, 212, 0)');
ctx.fillStyle = gradient;
ctx.beginPath();
ctx.arc(portfolioX, portfolioY, 25, 0, Math.PI * 2);
ctx.fill();
// Portfolio point
ctx.fillStyle = '#06b6d4';
ctx.beginPath();
ctx.arc(portfolioX, portfolioY, 8, 0, Math.PI * 2);
ctx.fill();
ctx.fillStyle = '#fff';
ctx.beginPath();
ctx.arc(portfolioX, portfolioY, 3, 0, Math.PI * 2);
ctx.fill();
// Individual loans
loanPortfolio.forEach((loan, idx) => {
const loanX = 60 + (width - 100) * Math.max(0, Math.min(1, (loan.emissionsIntensity - 50) / 250));
const loanY = height - 40 - (height - 70) * Math.max(0, Math.min(1, ((loan.currentMargin / 100 * 5 + 6) - 5) / 15));
ctx.fillStyle = loan.kpiStatus === 'achieved' ? '#10b981' :
loan.kpiStatus === 'breach' ? '#ef4444' : '#f59e0b';
ctx.globalAlpha = 0.7;
ctx.beginPath();
ctx.arc(loanX, loanY, 5, 0, Math.PI * 2);
ctx.fill();
ctx.globalAlpha = 1;
});
// Optimized point
const optX = portfolioX - 30 + Math.random() * 20;
const optY = portfolioY - 15 + Math.random() * 10;
ctx.strokeStyle = '#10b981';
ctx.lineWidth = 2;
ctx.setLineDash([3, 3]);
ctx.beginPath();
ctx.arc(optX, optY, 10, 0, Math.PI * 2);
ctx.stroke();
ctx.setLineDash([]);
ctx.fillStyle = '#10b981';
ctx.beginPath();
ctx.arc(optX, optY, 5, 0, Math.PI * 2);
ctx.fill();
}
// Draw emissions chart
function drawEmissionsChart() {
const canvas = document.getElementById('emissionsChart');
const ctx = canvas.getContext('2d');
const dpr = window.devicePixelRatio || 1;
canvas.width = canvas.offsetWidth * dpr;
canvas.height = canvas.offsetHeight * dpr;
ctx.scale(dpr, dpr);
const width = canvas.offsetWidth;
const height = canvas.offsetHeight;
ctx.fillStyle = '#111827';
ctx.fillRect(0, 0, width, height);
// Trajectory data
const baseline = [160, 155, 150, 145, 140, 135, 130];
const optimized = [160, 145, 130, 115, 100, 90, 80];
const target = [160, 148, 136, 124, 112, 100, 88];
const chartWidth = width - 20;
const chartHeight = height - 20;
// Draw target zone
ctx.fillStyle = 'rgba(16, 185, 129, 0.1)';
ctx.beginPath();
ctx.moveTo(0, chartHeight);
target.forEach((val, i) => {
const x = chartWidth * i / 6;
const y = chartHeight - (chartHeight * val / 200);
ctx.lineTo(x, y);
});
ctx.lineTo(chartWidth, chartHeight);
ctx.closePath();
ctx.fill();
// Draw lines
const drawLine = (data, color, dashed) => {
ctx.strokeStyle = color;
ctx.lineWidth = 2;
if (dashed) ctx.setLineDash([5, 5]);
else ctx.setLineDash([]);
ctx.beginPath();
data.forEach((val, i) => {
const x = chartWidth * i / 6;
const y = chartHeight - (chartHeight * val / 200);
if (i === 0) ctx.moveTo(x, y);
else ctx.lineTo(x, y);
});
ctx.stroke();
};
drawLine(baseline, '#64748b', true);
drawLine(optimized, '#06b6d4', false);
drawLine(target, '#10b981', true);
// Current point
const currentY = chartHeight - (chartHeight * 142 / 200);
ctx.fillStyle = '#f59e0b';
ctx.beginPath();
ctx.arc(0, currentY, 6, 0, Math.PI * 2);
ctx.fill();
// Legend
ctx.font = '9px Space Grotesk';
ctx.fillStyle = '#64748b';
ctx.fillText('Baseline', 10, 15);
ctx.fillStyle = '#06b6d4';
ctx.fillText('Optimized', 70, 15);
ctx.fillStyle = '#10b981';
ctx.fillText('Target', 140, 15);
}
// Draw capital chart
function drawCapitalChart() {
const canvas = document.getElementById('capitalChart');
if (!canvas) return;
const ctx = canvas.getContext('2d');
const dpr = window.devicePixelRatio || 1;
canvas.width = canvas.offsetWidth * dpr;
canvas.height = canvas.offsetHeight * dpr;
ctx.scale(dpr, dpr);
const width = canvas.offsetWidth;
const height = canvas.offsetHeight;
// Pie chart data
const data = [
{ label: 'Corporate (100% RW)', value: 45, color: '#3b82f6' },
{ label: 'SME Reduced (75% RW)', value: 25, color: '#10b981' },
{ label: 'Green Bonus (65% RW)', value: 20, color: '#06b6d4' },
{ label: 'High Carbon (115% RW)', value: 10, color: '#ef4444' }
];
const centerX = width / 2;
const centerY = height / 2;
const outerRadius = Math.max(10, Math.min(centerX, centerY) - 30);
const innerRadius = Math.max(5, outerRadius * 0.6);
let currentAngle = -Math.PI / 2;
data.forEach(segment => {
const sliceAngle = (segment.value / 100) * Math.PI * 2;
ctx.beginPath();
ctx.arc(centerX, centerY, outerRadius, currentAngle, currentAngle + sliceAngle);
ctx.arc(centerX, centerY, innerRadius, currentAngle + sliceAngle, currentAngle, true);
ctx.closePath();
ctx.fillStyle = segment.color;
ctx.fill();
currentAngle += sliceAngle;
});
// Center text
ctx.fillStyle = '#f1f5f9';
ctx.font = 'bold 16px JetBrains Mono';
ctx.textAlign = 'center';
ctx.textBaseline = 'middle';
ctx.fillText('RWA', centerX, centerY - 8);
ctx.font = '11px Space Grotesk';
ctx.fillStyle = '#64748b';
ctx.fillText('$847M', centerX, centerY + 10);
}
// Set scenario
function setScenario(scenario) {
currentScenario = scenario;
document.querySelectorAll('[data-scenario]').forEach(btn => {
btn.classList.toggle('active-scenario', btn.dataset.scenario === scenario);
btn.style.borderColor = btn.dataset.scenario === scenario ? '#06b6d4' : '';
btn.style.color = btn.dataset.scenario === scenario ? '#06b6d4' : '';
});
const scenarios = {
baseline: { return: 12, carbon: 150, concentration: 25 },
aggressive: { return: 10, carbon: 100, concentration: 20 },
conservative: { return: 15, carbon: 200, concentration: 30 }
};
const config = scenarios[scenario];
if (config) {
document.getElementById('returnTarget').value = config.return;
document.getElementById('carbonLimit').value = config.carbon;
document.getElementById('concentration').value = config.concentration;
document.getElementById('returnTargetValue').textContent = config.return + '%';
document.getElementById('carbonLimitValue').textContent = config.carbon + ' tCO2e/$M';
document.getElementById('concentrationValue').textContent = config.concentration + '%';
optimizationParams.returnTarget = config.return;
optimizationParams.carbonLimit = config.carbon;
optimizationParams.concentration = config.concentration;
runOptimization();
}
}
// Add loan
function addLoan() {
document.getElementById('addLoanModal').classList.remove('hidden');
}
// Close modal
function closeModal() {
document.getElementById('addLoanModal').classList.add('hidden');
document.getElementById('loanForm').reset();
}
// Form submit
document.getElementById('loanForm').addEventListener('submit', function(e) {
e.preventDefault();
const newLoan = {
id: Date.now(),
borrower: document.getElementById('borrowerName').value,
exposure: parseFloat(document.getElementById('exposure').value),
baseMargin: parseFloat(document.getElementById('baseMargin').value),
currentMargin: parseFloat(document.getElementById('baseMargin').value),
emissionsIntensity: parseFloat(document.getElementById('emissionsIntensity').value),
sector: document.getElementById('sector').value,
baseRW: parseFloat(document.getElementById('baseRW').value),
currentRW: parseFloat(document.getElementById('baseRW').value),
kpiStatus: 'on-track'
};
loanPortfolio.push(newLoan);
ratchetConfigs[newLoan.id] = {
kpis: [
{ name: 'Scope 1+2 Reduction', target: -25, current: -10, unit: '%', ratchetUp: 10, ratchetDown: -5 }
],
observationDate: '2025-12-31'
};
renderLoanTable();
populateLoanSelect();
updateKPIs();
runOptimization();
drawEfficientFrontier();
closeModal();
});
// Remove loan
function removeLoan(id) {
const idx = loanPortfolio.findIndex(l => l.id === id);
if (idx > -1) {
loanPortfolio.splice(idx, 1);
delete ratchetConfigs[id];
renderLoanTable();
populateLoanSelect();
updateKPIs();
runOptimization();
drawEfficientFrontier();
}
}
// Handle window resize
window.addEventListener('resize', () => {
drawEfficientFrontier();
drawEmissionsChart();
drawCapitalChart();
});
</script>
</body>
</html>
Key Features
Portfolio Management
- Add, view, and remove sustainability-linked loans with detailed attributes
- Track base margins vs. current margins after ratchet adjustments
- Sector-based classification and risk weighting
Margin Ratchet System
- Configure KPIs (emissions reduction targets, renewable energy %)
- Set ratchet-up penalties (margin increases when targets missed)
- Set ratchet-down rewards (margin decreases when targets achieved)
- Visual progress tracking toward each KPI
Regulatory Capital Treatment
- Basel III-compliant risk weight adjustments
- Green Asset Ratio bonuses (-10% RW)
- SME Supporting Factor (-25% RW)
- SLL KPI achievement credits (-5% RW)
- High carbon penalties (+15% RW)
Optimization Engine
- Adjustable parameters: return target, carbon limits, concentration limits, CET1 buffer, greenium factor
- Efficient frontier visualization showing risk/return tradeoffs
- Scenario presets (Baseline, Aggressive Green, Conservative)
- Real-time recommendation engine
Visualization
- Interactive efficient frontier chart with current portfolio vs. optimized position
- Emissions reduction pathway projection
- RWA allocation donut chart
- KPI progress indicators