Yield Curve Principal Components
Calculates the principal components of a country’s government bond yield curve: the few independent movements that explain nearly all of how the curve changes. Litterman and Scheinkman (1991) found that three components explain over 95% of the changes of Treasury yields: a parallel shift (level, PC1, loading about equally on every maturity), a steepening (slope, PC2, with opposite signs at the short and long end) and a bending (curvature, PC3, moving the middle against both ends). Hedging a bond portfolio against the first two covers most of its interest rate risk.
The components are the eigenvectors of the covariance matrix of the yield changes (or levels), sorted by the share of the variance they explain. Their sign is arbitrary, so PC1 is oriented as a rise in all yields (its loadings sum to a positive number), PC2 as a steepening (the longest maturity loads above the shortest) and the others so that their loadings sum to a positive number. Maturities that are only published for part of the period (such as the 4-month Treasury bill from 2022) are left out, so that the analysis covers the full period.
For more information, see the following paper:
- Litterman, R. and Scheinkman, J. (1991). “Common Factors Affecting Bond Returns.” The Journal of Fixed Income, 1(1), 54-61.
Also known as: PCA of the yield curve, level slope curvature, term structure factors.
Yield Curve Principal Components in Python or via the MCP
Install the Finance Toolkit with:
pip install financetoolkit -U
Then call get_yield_curve_principal_components as shown below.
from financetoolkit import FixedIncome
fixedincome = FixedIncome(start_date='2016-01-01', end_date='2025-12-31')
fixedincome.get_yield_curve_principal_components(period='monthly')
Or, after setting up the Finance Toolkit MCP, ask:
How much of the monthly moves in the US yield curve from 2016 to 2025 did the level, slope and curvature components explain, and how did each maturity load on them?
Which returns:
| Maturity | PC1 | PC2 | PC3 |
|---|---|---|---|
| 1M | 0.1332 | -0.6209 | 0.3084 |
| 3M | 0.1713 | -0.4809 | 0.1636 |
| 6M | 0.225 | -0.3809 | -0.0592 |
| 1Y | 0.2789 | -0.2545 | -0.2647 |
| 2Y | 0.3538 | -0.0249 | -0.4383 |
| 3Y | 0.3676 | 0.0701 | -0.3617 |
| 5Y | 0.3733 | 0.1595 | -0.1347 |
| 7Y | 0.3636 | 0.1907 | 0.0399 |
| 10Y | 0.3434 | 0.1972 | 0.2136 |
| 20Y | 0.3052 | 0.1888 | 0.4277 |
| 30Y | 0.2855 | 0.1773 | 0.4831 |
| Explained Variance | 0.732 | 0.1938 | 0.0501 |
Parameters
get_yield_curve_principal_components accepts the following parameters.
| Parameter | Type | Description | Example |
|---|---|---|---|
country | str | The country, see get_government_bond_yield_curve. Defaults to “United States”. | "US" |
period | str | Whether to use the daily, weekly or monthly curves. Defaults to “daily”. | "weekly" |
components | int | The number of components. Defaults to 3. | 3 |
changes | bool | Whether to analyze the changes of the yields, the usual choice as yields themselves are not stationary, or their levels. Defaults to True. | True |
scores | bool | Whether to return the value of every component per date (the scores) instead of the loadings. Defaults to False. | False |
rounding | int | None | The number of decimals to round the results to. Defaults to None. | 2 |