Created
December 20, 2020 22:05
-
-
Save druce/5db9f90aaa6ea4156cb2beff9c8b65d4 to your computer and use it in GitHub Desktop.
po2.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import pandas_datareader as pdr | |
| # load gold data from FRED API & save copy locally to CSV file | |
| series = ['GOLDAMGBD228NLBM'] | |
| gold_download = pdr.data.DataReader(series, | |
| 'fred', | |
| start='1968-12-31') | |
| # convert daily to annual | |
| gold_download = gold_download.resample('A').last().reset_index() | |
| gold_download.set_index(pd.DatetimeIndex(gold_download['DATE']).year, inplace=True) | |
| gold_download['return'] = gold_download['GOLDAMGBD228NLBM'].pct_change() | |
| gold_download.to_csv('gold_fred.csv') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment