-
Notifications
You must be signed in to change notification settings - Fork 67
/
treasuries.py
28 lines (23 loc) · 964 Bytes
/
treasuries.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import matplotlib.pyplot as plt
import requests, pandas as pd
def getRates(limit):
base = 'https://www.transparency.treasury.gov/services/api/fiscal_service/v1/'
url = base + 'accounting/od/avg_interest_rates'
params = {'sort':'-reporting_date', 'limit':limit}
r = requests.get(url, params=params)
js = r.json()
df = pd.DataFrame(js['data'])
return df
data = getRates(10000)
plt.style.use('dark_background')
fig, ax = plt.subplots(figsize=(12,6))
tipos = ['Treasury Bills','Treasury Notes','Treasury Bonds']
for tipo in tipos:
serie = data.loc[data.security_desc==tipo]
serie = serie.loc[:,['reporting_date','avg_interest_rate_amt']]
serie.set_index('reporting_date', inplace=True)
serie.index = pd.to_datetime(serie.index)
serie.avg_interest_rate_amt = pd.to_numeric(serie.avg_interest_rate_amt)
ax.plot(serie, label=tipo)
ax.legend(loc='upper right', fontsize=14)
plt.show()