-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmacro_indicators_toolkit.py
236 lines (204 loc) · 5.97 KB
/
macro_indicators_toolkit.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
from fredapi import Fred
fred = Fred(api_key='YOUR API')
def treasury_ten_year():
"""
Returns: 10-Year Treasury Constant Maturity Rate; Unit: percent per annum
"""
treasury_lt = fred.get_series('DGS10')
return treasury_lt
def treasury_one_year():
"""
Returns: 1-Year Treasury Constant Maturity Rate; Unit: percent per annum
"""
treasury_st = fred.get_series('DGS1')
return treasury_st
def treasury_three_month():
"""
Returns: 3-Month Treasury Constant Maturity Rate; Unit: percent per annum
"""
treasury_stm = fred.get_series('DGS3MO')
return treasury_stm
def unemployment_rate_us():
"""
Return: Unemployment Rate
"""
unempl = fred.get_series('UNRATE')
return unempl
def unemployment_rate_by_state(start_date = '2020-01-01'):
"""
Input: start date of the observations
Returns: Unemployment Rate by State
"""
states = ["AL", "AK", "AZ", "AR", "CA", "CO", "CT", "DC", "DE", "FL", "GA", "HI", "ID", "IL", "IN", "IA", "KS", "KY", "LA", "ME", "MD", "MA", "MI", "MN", "MS", "MO", "MT", "NE", "NV", "NH", "NJ", "NM", "NY", "NC", "ND", "OH", "OK", "OR", "PA", "RI", "SC", "SD", "TN", "TX", "UT", "VT", "VA", "WA", "WV", "WI", "WY"]
by_state = []
for st in states:
data = fred.get_series(f'{st}UR', observation_start=start_date)
by_state.append(data)
df_ur = pd.concat(by_state, axis=1)
df_ur.columns = states
return df_ur
def sp_500():
"""
Returns: S&P 500 for last 10 years, Index
"""
sp = fred.get_series('SP500')
return sp
def gdp_us():
"""
Returns: Real US GDP, Billions of Dollars
"""
gdp = fred.get_series('GDPC1')
gdp.dropna(inplace=True)
return gdp
def inflation_breakeven_10yrs():
"""
Returns: 10-Year Breakeven Inflation Rate
Note: forward looking rate (10 years)
"""
infl = fred.get_series('T10YIE')
return infl
def inflation_breakeven_5yrs():
"""
Returns: 5-Year Breakeven Inflation Rate
Note: forward looking rate (5 years)
"""
infl = fred.get_series('T5YIE')
return infl
def consumption():
"""
Returns: Real Personal Consumption Expenditures, Billions of Dollars
"""
consmp = fred.get_series('PCEC96')
consmp.dropna(inplace=True)
return consmp
def consumer_price_index():
"""
Returns: Consumer Price Index for All Urban Consumers: All Items in U.S. City Average
"""
cpi = fred.get_series('CPIAUCSL')
cpi.dropna(inplace=True)
return cpi
def recession_nber():
"""
Returns: NBER based Recession Indicators for the United States from the Period following the Peak through the Trough
"""
nber = fred.get_series('USREC')
nber.dropna(inplace=True)
return nber
def plot_spread_recession():
"""
Returns: plot of Term Spread (10-year minus 3-month) and NBER recessions from 1981
"""
ten = treasury_ten_year()
ten = ten['1981-09-01':]
thr = treasury_three_month()
thr = thr['1981-09-01':]
spr = ten - thr
rec = recession_nber()
ax = spr.plot(figsize=(12,6))
(rec['1981':]*5).plot(ax=ax, style="--", linewidth=3)
def tenyear_cm_minus_fedfunds():
"""
10-Year Treasury Constant Maturity Minus Federal Funds Rate, Monthly
"""
ttenyffm = fred.get_series('T10YFFM')
ttenyffm.dropna(inplace=True)
return ttenyffm
def three_month_tbill_minus_fedfunds():
"""
3-Month Treasury Bill Minus Federal Funds Rate, Monthly
"""
tbthreemffm = fred.get_series('TB3SMFFM')
tbthreemffm.dropna(inplace=True)
return tbthreemffm
def all_employee():
"""
All Employees, Total Nonfarm
"""
nonfpayems = fred.get_series('PAYEMS')
nonfpayems.dropna(inplace=True)
return nonfpayems
def job_open():
"""
Job Openings: Total Nonfarm, Monthly
"""
jobopen = fred.get_series('JTSJOL')
jobopen.dropna(inplace=True)
return jobopen
def five_year_cm_minus_fedfund():
"""
5-Year Treasury Constant Maturity Minus Federal Funds Rate, Monthly
"""
fiveyffm = fred.get_series('T5YFFM')
fiveyffm.dropna(inplace=True)
return fiveyffm
def one_year_cm_minus_fedfund():
"""
1-Year Treasury Constant Maturity Minus Federal Funds Rate, Monthly
"""
oneyffm = fred.get_series('T1YFFM')
oneyffm.dropna(inplace=True)
return oneyffm
def us_uk_fx():
"""
U.S. / U.K. Foreign Exchange Rate, U.S. Dollars to One British Pound, Monthly
"""
usukexch = fred.get_series('EXUSUK')
usukexch.dropna(inplace=True)
return usukexch
def housing_stats_west_census():
"""
Housing Starts in West Census Region, Thousands of Units, Monthly
"""
house = fred.get_series('HOUSTW')
house.dropna(inplace=True)
return house
def three_month_trs_secondary():
"""
3-Month Treasury Bill: Secondary Market Rate, Monthly
"""
threems = fred.get_series('TB3MS')
threems.dropna(inplace=True)
return threems
def employee_constr():
"""
All Employees, Construction, Monthly
"""
usconstr = fred.get_series('USCONS')
usconstr.dropna(inplace=True)
return usconstr
def overtime_manuf():
"""
Average Weekly Overtime Hours of Production and Nonsupervisory Employees, Manufacturing, Monthly
"""
overtime = fred.get_series('AWOTMAN')
overtime.dropna(inplace=True)
return overtime
def housing_owened():
"""
Housing Starts: Total: New Privately Owned Housing Units Started, Monthly
"""
housest = fred.get_series('HOUST')
housest.dropna(inplace=True)
return housest
def employee_durable():
"""
All Employees, Durable Goods, Monthly
"""
durgood = fred.get_series('DMANEMP')
durgood.dropna(inplace=True)
return durgood
def employee_service():
"""
All Employees, Service-Providing, Monthly
"""
survp = fred.get_series('SRVPRD')
survp.dropna(inplace=True)
return survp
def initial_claims():
"""
Initial Claims, Monthly
"""
claim = fred.get_series('ICSA')
claim.dropna(inplace=True)
return claim