CRYPTO LENDING
A Flask dashboard for bank credit risk analysts working under IFRS 9 - combining a live crypto market monitor with an interactive ECL calculator for BTC-collateralised loans. Four valuation approaches, Newton-Raphson EIR solving, full stage classification, and real-time CoinGecko market data.
Go to Repo
THE IDEA
Banks extending loans collateralised by Bitcoin face a measurement problem that IFRS 9 was not designed for: the collateral is extraordinarily volatile, margin calls are real-time, and a single BTC price path can move a loan from Stage 1 to Stage 3 in days. Standard ECL models built on historical LGD tables miss all of this.
This dashboard builds four ECL approaches side-by-side - from a conservative static baseline to a full scenario-weighted model - so analysts can see exactly how much the collateral treatment changes the allowance, EIR, and balance-sheet impact.
FOUR ECL APPROACHES
| # | Approach | Description |
|---|---|---|
| A1 | Static LGD | Fixed LGD ignoring collateral — baseline / most conservative |
| A2 | Dynamic LTV-Adjusted LGD | LGD derived from current BTC price with liquidation haircut |
| A3 | BTC Scenario-Weighted ECL | Three price scenarios (base / optimistic / adverse) probability-weighted per IFRS 9.B5.5.42 |
| A4 | Stressed LGD Floor | Regulatory-style floor applied across all scenarios |
For each approach the calculator outputs the ECL allowance (12-month Stage 1 or lifetime Stage 2/3), the EIR solved via Newton-Raphson on the bullet loan cash flows, a full amortised cost schedule, SICR assessment, stage classification with justification, balance-sheet entry, and year-1 P&L impact.
IFRS 9 MECHANICS
The SICR assessment flags four triggers simultaneously: absolute PD breach, relative PD increase, LTV covenant breach, and margin call status. Any trigger moves the loan to Stage 2 and switches the allowance from 12-month to lifetime ECL. Stage 3 is set when the loan is credit-impaired and switches interest accrual from gross to net carrying amount.
The EIR is solved iteratively using Newton-Raphson on the discounted cash flow equation, incorporating the origination fee and transaction costs into the effective yield. This feeds into both the amortised cost schedule and the P&L interest income line, giving a complete picture of how collateral quality shifts reported profitability.
CRYPTO MARKET MONITOR
The second tab streams live market data from CoinGecko for BTC, ETH, SOL, and XRP with a 5-minute in-memory cache to stay within rate limits. Each coin shows YTD price and 30-day rolling annualised volatility, drawdown from YTD peak (current and maximum), Sharpe ratio, market cap, 24h volume, and a bid-ask spread proxy. An exchange depth chart breaks down 24h volume by venue, giving a microstructure view of where collateral liquidation would need to occur.
ARCHITECTURE NOTES
- Client-side ECL engine: the entire IFRS 9 calculator runs in vanilla JavaScript with no backend round-trips. Any parameter change triggers a 180ms debounced full recalculation across all four approaches simultaneously.
- Newton-Raphson EIR: the solver iterates on the NPV equation for bullet loan cash flows, converging to basis-point precision in under 10 iterations for typical inputs.
- Plotly charts: all visualisations use
Plotly.reactfor efficient in-place updates - the LGD sensitivity chart re-renders with scenario markers as BTC price changes. - Flask routing: IFRS 9 at
/ifrs9/and crypto markets at/crypto/, with the root redirecting to the calculator.