import random
import pandas as pd
from frmbook_funcs import LastYearEnd
from frmbook_funcs import GetFREDMatrix
from frmbook_funcs import TenorsFromNames
from frmbook_funcs import InterpolateCurve
#PLot 10 Hull-White paths based on yearend US Treasury curve

lastday = LastYearEnd()

seriesnames = [
    'DGS1MO', 'DGS3MO', 'DGS6MO', 'DGS1', 'DGS2', 'DGS3', 'DGS5', 'DGS7',
    'DGS10', 'DGS20', 'DGS30'
]
cdates, ratematrix = GetFREDMatrix(seriesnames,
                                   startdate=lastday,
                                   enddate=lastday)
tenorsfromtsy = TenorsFromNames(seriesnames)

#Get monhtly interpolated curve and short rate curve
tenors, curvemonthly, shortrates = InterpolateCurve(tenorsfromtsy,
                                                    ratematrix[0])

#do one graph with sigma=.05 and another
#with sigma=.2
#keep track of range
minrate, maxrate = 0, 0
fig, (ax1, ax2) = plt.subplots(1, 2, sharey=True)
fig.suptitle("10 Hull-White Curves, σ=.05 and .2")
random.seed(3.14159265)
Beispiel #2
0
import matplotlib.pyplot as plt
import pandas as pd
from frmbook_funcs import GetFREDMatrix
from frmbook_funcs import LastYearEnd
from frmbook_funds import TenorsFromNames
#Plot the 2010, 2012, and most recent yearend
#US Treasury curves
seriesnames = [
    'DGS1MO', 'DGS3MO', 'DGS6MO', 'DGS1', 'DGS2', 'DGS3', 'DGS5', 'DGS7',
    'DGS10', 'DGS20', 'DGS30'
]
cdates, ratematrix = GetFREDMatrix(seriesnames)

#Form the list of curve dates to display
displaydates = ['2010-12-31', '2012-12-31']
displaydates.append(LastYearEnd())
tenors = TenorsFromNames(seriesnames)

#Plot the three lines
for i in range(3):
    year = displaydates[i][:4]
    plt.plot(tenors, ratematrix[cdates.index(displaydates[i])], label=year)

## Configure the graph
plt.title('US Yearend Treasury Curves')
plt.xlabel('Tenor (years)')
plt.ylabel('Rate (%/year)')
plt.legend()
plt.grid(True)
plt.annotate('Upward sloping',
             xy=(25, 2.5),
import matplotlib.pyplot as plt
import numpy as np
import scipy.stats
import pandas as pd
from frmbook_funcs import LastYearEnd
from frmbook_funcs import GetFREDMatrix
#Get Moody's AAA and BBB yields from FRED.
#Splice together long-term US Treasury rate series,
#and subtract them off to form credit spreads.
#Display and correlate with VIX

lastday = LastYearEnd()
seriesnames=['AAA','BAA','M1333AUSM156NNBR', \
             'LTGOVTBD','IRLTCT01USM156N']
cdates, ratematrix = GetFREDMatrix(seriesnames, enddate=lastday)

#Splice together the three overlapping long-term
#Treasury series. They agree at the first overlap points
longterm = [x[2] for x in ratematrix[:72]]
longterm += [x[3] for x in ratematrix[72:492]]
longterm += [x[4] for x in ratematrix[492:]]

n = len(longterm)

#Get VIX index which is daily
vxnames = ['VXOCLS', 'VIXCLS']
vxdates, vxmatrix = GetFREDMatrix(vxnames, enddate=lastday)

#Align VIX's; monthly dates for bond yields look like
#YYYY-MM-01 but they're really the last business day
vixstart = cdates.index(vxdates[0][:8] + '01')
import matplotlib.pyplot as plt
import pandas as pd
from frmbook_funcs import GetFREDMatrix
from frmbook_funcs import TenorsFromNames
#Show the inverted Treasury curve from 2001-01-02

targetdate='2001-01-02'
#Note no one-month rate on this date
seriesnames=['DGS3MO','DGS6MO','DGS1',
             'DGS2','DGS3','DGS5','DGS7',
             'DGS10','DGS20','DGS30']
cdates,ratematrix=GetFREDMatrix(seriesnames,startdate=targetdate,enddate=targetdate)

plt.plot(TenorsFromNames(seriesnames), ratematrix[0])
## Configure the graph
plt.title('US Treasury Curve '+targetdate)
plt.ylim(0,max([x for x in ratematrix[0] if pd.notna(x)])+.5)
plt.xlabel('Tenor (years)')
plt.ylabel('Rate (%/year)')
plt.grid(True)
plt.show