Skip to content Skip to sidebar Skip to footer

Plotting Treasury Yield Curve, How To Overlay Two Yield Curves Using Matplotlib

I am trying to create a graph of the treasury yield curve to compare the rates from two separate dates. I am having difficulty with combining the two curves and creating a clean gr

Solution 1:

Is this what you were looking for?

import matplotlib.pyplot as plt
import pandas as pd
import quandl as ql
#import Quandl as ql
%matplotlib inline

yield_ = ql.get("USTREASURY/YIELD")
today = yield_.iloc[-1,:]
month_ago = yield_.iloc[-30,:]
df = pd.concat([today, month_ago], axis=1)
df.columns = ['today', 'month_ago']

df.plot(style={'today': 'ro-', 'month_ago': 'bx--'}
        ,title='Treasury Yield Curve, %');

enter image description here

Solution 2:

FYI: I'm using python 3.8 and spyder with anaconda. I spent a lot of time troubleshooting the 'module not found error for Quandl only to discover it should be quandl (lowercase).

Post a Comment for "Plotting Treasury Yield Curve, How To Overlay Two Yield Curves Using Matplotlib"