Skip to content

Instantly share code, notes, and snippets.

@druce
Created December 20, 2020 22:05
Show Gist options
  • Select an option

  • Save druce/5db9f90aaa6ea4156cb2beff9c8b65d4 to your computer and use it in GitHub Desktop.

Select an option

Save druce/5db9f90aaa6ea4156cb2beff9c8b65d4 to your computer and use it in GitHub Desktop.
po2.py
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