Yield Curve Spread
Calculates the spread between pairs of points on a yield curve, e.g. the widely followed 10-year minus 2-year Treasury spread. A positive spread indicates a “normal” upward-sloping curve, while a negative spread (“inversion”) has historically been used as a leading indicator of an economic slowdown.
The rate for each maturity is obtained by linearly interpolating the supplied curve, so long_maturity and short_maturity do not need to coincide exactly with a maturity present in spot_rates.
The yield curve spread is calculated using the following formula:
\[\text{Yield Curve Spread} = \text{Long-Term Yield} - \text{Short-Term Yield}\]Also known as: term spread, yield curve slope.
No programming experience? With the Finance Toolkit MCP server, AI assistants such as Claude and ChatGPT can calculate the Yield Curve Spread for you. Just ask in plain English.
Calculate the Yield Curve Spread in Python
The Yield Curve Spread is available in the Fixed Income module of the open-source Finance Toolkit. Install it with:
pip install financetoolkit -U
Then call get_yield_curve_spread as shown below.
from financetoolkit import FixedIncome
fixedincome = FixedIncome()
fixedincome.get_yield_curve_spread(
long_maturity=[10, 30],
short_maturity=[1, 2],
show_input_info=False,
)
Which returns:
| Long Maturity | 1 | 2 |
|---|---|---|
| 10 | 0.014 | 0.012 |
| 30 | 0.02 | 0.018 |
Parameters
get_yield_curve_spread accepts the following parameters:
- spot_rates (pd.Series | dict, optional): The yield curve, indexed by maturity in years (in decimal). Defaults to a sample curve.
- long_maturity (float | list, optional): The longer maturity (or maturities), in years. If not provided, a range of long maturities will be used.
- short_maturity (float | list, optional): The shorter maturity (or maturities), in years. If not provided, a range of short maturities will be used.
- show_input_info (bool, optional): Whether to display input information. Defaults to True.
Related Bond Valuations
The Fixed Income module page introduces the module, and the sidebar lists all of its functions.