Fixed Income Risk Analytics  ·  PCA  ·  Scenario Analysis

How much does a portfolio lose
when interest rates move?

This project uses 20 years of US Treasury yield data to identify the three patterns that drive almost all yield-curve movements — then stress-tests a fixed income portfolio against each of them.

Dataset
9 Tenors · 20 Yrs
1M through 30Y · Daily FRED data
Variance captured
89.8%
Explained by just 3 principal components
Portfolio DV01
$3,053
Dollar loss per 1 basis-point rate rise
Worst-case scenario
−$28,978
2-sigma parallel rate rise across all tenors

Two decades of the US Treasury yield curve

We pull daily yields for nine maturities from the Federal Reserve's FRED database — everything from one-month T-bills to the 30-year long bond. That gives us a complete picture of how the curve has shifted through multiple cycles: the 2008 financial crisis, COVID-era zero rates, and the 2022 hiking cycle that moved faster than almost any in history.

US Treasury Yield History
Fig 1 20+ years of 2Y, 5Y, 10Y and 30Y Treasury yields, with three key macro events marked.

The chart above shows the kind of volatility this analysis has to account for. Yields went from near zero in 2021 to over 5% by 2023 — a move of hundreds of basis points in under two years. A portfolio that wasn't stress-tested for that kind of shock would have been caught off guard.

Three shapes explain almost everything

Rather than treating each of the nine yields as a separate risk, we asked: what are the most common shapes of yield-curve movement? Principal Component Analysis answers exactly that question by finding the directions in which the curve tends to move most.

PC1 — 58.2% of all moves
The Level Shift
Parallel shift across all tenors
58.2%
variance explained
All yields move up or down together. When the Fed raises or cuts rates, this is what you see. It is the single biggest driver of bond portfolio gains and losses.
PC2 — 22.6% of all moves
The Slope Shift
Short end vs. long end
22.6%
variance explained
Short rates and long rates move in opposite directions. A "steepening" curve (long rates up, short rates down) often signals recession fears. A "flattening" suggests the Fed is hiking aggressively.
PC3 — 9.0% of all moves
The Curvature Shift
Belly vs. wings
9.0%
variance explained
The middle of the curve (the "belly") moves relative to the short and long ends. This is the classic "butterfly" trade in fixed income, and it matters for instruments like 5-year swaps positioned in that belly.
PCA Factor Loadings
Fig 2 How each PC loads across the nine tenors — the "shape" of each yield-curve move.
Explained Variance
Fig 3 Three components reach 89.8% cumulative variance. The fourth adds less than 4%.

Why does PC1 explain "only" 58%? In textbook examples you often see PC1 explaining 80%+ of yield-curve variance. The reason it is lower here is the 2022–2023 hiking cycle, which created unusually large slope movements as the short end rose far faster than the long end. Those big slope swings boosted PC2's share of total variance significantly.

$4 million across four instruments

The portfolio is designed to span the entire yield curve — from short-dated notes through to the 30-year long bond — plus an interest-rate swap to represent the derivatives exposure that most real-world fixed income books carry. Each position is $1 million notional, giving a $4 million total portfolio.

Short end — 2Y Treasury Note
2-Year Note
YTM 3.48% · $1M notional
The anchor of the short end. Two-year yields move most directly with Fed rate expectations — when the market prices in rate cuts or hikes, this is the first part of the curve to react. Its low duration (1.92 years) means it is relatively insensitive to rate moves, but it is the clearest signal of where policy is heading.
Belly — 10Y Treasury Note
10-Year Note
YTM 4.08% · $1M notional
The most-watched bond in the world. The 10-year yield is the global benchmark for borrowing costs — it drives mortgage rates, corporate credit, and equity valuations. With a duration of 8.14 years it carries four times the rate sensitivity of the 2Y, making it a substantial source of P&L volatility.
Long end — 30Y Treasury Bond
30-Year Bond
YTM 4.72% · $1M notional
The highest-duration instrument in the portfolio at 15.96 years — and by far the largest single source of rate risk, contributing $1,594 of the $3,053 total DV01. Its convexity of 370 also means it benefits disproportionately when rates fall sharply, a property known as positive convexity.
Derivatives — 5Y Interest Rate Swap
5-Year Receive-Fixed Swap
Fixed rate 3.65% · $1M notional
A receive-fixed, pay-floating swap means we collect a fixed 3.65% coupon and pay a floating rate. If rates rise, the fixed leg we receive becomes less valuable relative to the floating leg we pay, so the swap loses money — just like a bond. At inception it has zero market value, and its P&L is measured against notional.
DV01 Contribution by Instrument — Total $3,052.86
30Y Treasury Bond $1,594 — 52.2%
10Y Treasury Note $814 — 26.7%
5Y Receive-Fixed Swap $453 — 14.8%
2Y Treasury Note $192 — 6.3%

The 30Y bond alone accounts for over half the portfolio's rate sensitivity, even though it is just one of four equal-notional positions. This is the inevitable consequence of duration: longer-maturity bonds are simply far more sensitive to rate moves.

Instrument Notional YTM DV01 ($) Duration (yrs) Convexity
2Y Treasury Note $1,000,000 3.48% 191.57 1.92 4.67
10Y Treasury Note $1,000,000 4.08% 814.03 8.14 78.46
30Y Treasury Bond $1,000,000 4.72% 1,594.11 15.96 369.87
5Y Receive-Fixed Swap $1,000,000 3.65% 453.15 4.53 23.82
Portfolio Total $4,000,000 3,052.86
DV01

Dollar loss for a 1 basis-point (0.01%) rise in yield. The 30Y bond's DV01 of $1,594 means it alone loses $1,594 if the 30Y yield ticks up by just one hundredth of a percent. The total DV01 of $3,053 is the first number any risk manager looks at.

Modified Duration

Percentage price change per 1% yield move. The 30Y bond's duration of 15.96 years means a 1% rate rise wipes roughly 16% off its value — $160,000 on $1M notional.

Convexity

The second-order rate effect. High convexity (30Y bond: 370) means gains from a rate fall are slightly larger than losses from an equal rate rise. In large shocks this asymmetry becomes real money.

What happens when the curve shifts?

We apply each principal component as a shock to the yield curve — scaled to historical 1-sigma and 2-sigma magnitudes — and reprice the entire portfolio. The chart below shows what the curve looks like under each scenario before we even touch the portfolio.

Shifted Yield Curves
Fig 4 Base curve vs ±1 and ±2 sigma shocks for each of the three principal components.
Portfolio P&L by Scenario
PC1 — Rates Rise
Parallel shift up (+2σ)
−$28,978
All yields jump by roughly 50 basis points together. Every position loses, with the 30Y bond and 10Y note hit hardest. This is the portfolio's biggest single risk.
PC1 — Rates Fall
Parallel shift down (−2σ)
+$29,381
The mirror of rates-rise — and slightly larger because convexity on the 30Y adds a small cushion on the upside that doesn't exist on the downside.
PC2 — Steepening
Long rates up, short rates down (+2σ)
−$12,171
The long end rises while the short end falls slightly. The 30Y and 10Y lose more than the 2Y and swap gain, leaving a net loss of $12K.
PC2 — Flattening
Short rates up, long rates down (−2σ)
+$11,791
Long-end rates fall, boosting the 30Y and 10Y. Short-end losses on the 2Y are much smaller because duration is lower at the short end.
PC3 — Belly Up
Middle of curve rises (+2σ)
+$4,396
The 2Y–5Y belly rises relative to the wings. The 5Y swap loses, but the 2Y note and 30Y bond benefit from their wing positions. Small net gain.
PC3 — Belly Down
Middle of curve falls (−2σ)
−$4,498
Inverse butterfly. Belly falls relative to wings. The swap gains but long-end losses dominate marginally. Small net loss.
P&L Heatmap
Fig 5 Portfolio P&L ($000s) across all PC1 × PC2 shock combinations. Green = gain, red = loss.
P&L Attribution
Fig 6 Per-instrument and total P&L for the five key scenarios. The 30Y bond dominates.

The key insight: the portfolio is net long duration. A parallel rate rise is the dominant risk at ~$29K per 2-sigma event. Slope risk is the second-largest driver at ~$12K. Curvature risk is a distant third at ~$4.5K. This ordering — level, slope, then curvature — is exactly how professional fixed income desks think about and hedge their books.

A six-step pipeline, end to end

The entire analysis runs as a Python pipeline: from raw FRED CSVs through PCA, shock calibration, portfolio pricing, scenario repricing, and finally chart generation. Each step is a self-contained script.

01
Load & Clean Data

Read nine FRED CSV files, replace missing-value markers, forward-fill isolated gaps (weekends, holidays), and drop dates where data is too sparse.

02
PCA Decomposition

Compute daily yield changes (not levels), standardise across tenors, run sklearn's PCA. Flip component signs so each PC is economically interpretable.

03
Shock Calibration

Measure the historical distribution of daily PC scores. Define ±1 and ±2 standard deviation shocks per component and convert back into basis-point moves at every tenor.

04
Portfolio Pricing

Price each instrument using discounted cash-flow maths against the current interpolated yield curve. Compute DV01, Modified Duration, and Convexity via central-difference bumping.

05
Scenario Repricing

Apply each shock, reprice every instrument, and record the P&L. Decompose P&L into a first-order duration effect and a second-order convexity contribution.

06
Visualisation

Generate six publication-quality charts covering yield history, PCA factor shapes, explained variance, shocked curves, a P&L heatmap, and per-instrument attribution.

Tech Stack

Python · pandas · NumPy · scikit-learn (PCA) · matplotlib · seaborn · SciPy (interpolation)

Data Source

Federal Reserve Economic Data (FRED) — series DGS1MO through DGS30. Daily observations, approximately 5,000+ trading days.

Bond Pricing

Standard semi-annual coupon DCF. Par bonds (coupon = YTM at base curve). Yield interpolated at each maturity using scipy's cubic spline.

Swap Pricing

Receive-fixed, pay-floating. NPV = PV of fixed leg − notional. At inception the fixed rate equals the 5Y par swap rate so NPV starts at zero; P&L is measured relative to notional for risk scaling.