L2Aadj = L2Araw * 0.85
L2Badj = L2Braw * 0.50
// Level 2B may not exceed 15% of HQLA; Level 2 in total may not exceed 40% of HQLA.
// Both bind as multiples of Level 1: L2 <= (2/3) x L1.
L2Badm = Math.min(L2Badj, (15 / 85) * (L1 + L2Aadj))
L2adm = Math.min(L2Aadj + L2Badm, (2 / 3) * L1)
hqla = L1 + L2adm
capBinds = (L2Aadj + L2Badm) > (2 / 3) * L1 + 1e-9
netOut = outflow - Math.min(inflow, 0.75 * outflow)
lcr = 100 * hqla / netOut
stackPlot = Plot.plot({
width: 300, height: 235, marginLeft: 45, marginBottom: 55,
x: {label: null, domain: ["counted", "discarded"]},
y: {label: "\\$m", grid: true},
color: {legend: true, domain: ["Level 1", "Level 2 admitted", "Cut by haircut or cap"],
range: ["#A6192E", "#d98d97", "#d9d9d9"]},
marks: [
Plot.barY([
{g: "counted", k: "Level 1", v: L1},
{g: "counted", k: "Level 2 admitted", v: L2adm},
{g: "discarded", k: "Cut by haircut or cap", v: (L2Araw + L2Braw) - L2adm}
], {x: "g", y: "v", fill: "k"}),
Plot.ruleY([0])
]
})
flowPlot = Plot.plot({
width: 300, height: 235, marginLeft: 45, marginBottom: 55,
x: {label: null},
y: {label: "\\$m", grid: true},
marks: [
Plot.barY([
{k: "HQLA", v: hqla},
{k: "Net outflows", v: netOut}
], {x: "k", y: "v", fill: d => d.k === "HQLA" ? "#A6192E" : "#7a7a7a"}),
Plot.ruleY([0])
]
})
html`
<div style="font-size:1.05em; margin-bottom:6px;">
HQLA <b>\$${hqla.toFixed(1)}m</b> ·
net outflows <b>\$${netOut.toFixed(2)}m</b> ·
LCR <b style="color:${lcr >= 100 ? '#1a7f37' : '#A6192E'}">${lcr.toFixed(1)}%</b>
${capBinds ? '<br><span style="color:#A6192E">Level 2 cap is binding: extra Level 2 adds nothing.</span>'
: '<br><span style="color:#777">Level 2 cap is not binding.</span>'}
</div>
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 6px;">
<div>${stackPlot}</div>
<div>${flowPlot}</div>
</div>
`