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.

Yield Curve Spread in Python

get_yield_curve_spread is part of 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.
Share