Skip to content

Instantly share code, notes, and snippets.

@huseinzol05
Created January 12, 2018 08:19
Show Gist options
  • Save huseinzol05/983e652664e55b172f24f390ab2fdfa0 to your computer and use it in GitHub Desktop.
Save huseinzol05/983e652664e55b172f24f390ab2fdfa0 to your computer and use it in GitHub Desktop.
download historical commodities (crude oil, gold, kerosene, propane, natural gas, heating oil, gasoline)
import urllib
print 'downloading crude oil data'
urllib.urlretrieve("https://fred.stlouisfed.org/graph/fredgraph.csv?chart_type=line&recession_bars=on&log_scales=&bgcolor=%23e1e9f0&graph_bgcolor=%23ffffff&fo=Open+Sans&ts=12&tts=12&txtcolor=%23444444&show_legend=yes&show_axis_titles=yes&height=450&stacking=&range=1yr&mode=fred&id=DCOILWTICO&transformation=lin&nd=1986-01-02&ost=-99999&oet=99999&lsv=&lev=&mma=0&fml=a&fgst=lin&fgsnd=2009-06-01&fq=Daily&fam=avg&vintage_date=&revision_date=&line_color=%234572a7&line_style=solid&lw=2&scale=left&mark_type=none&mw=2&width=1168", "crude-oil.csv")
print 'downloading diesel data'
urllib.urlretrieve("https://fred.stlouisfed.org/graph/fredgraph.csv?chart_type=line&recession_bars=on&log_scales=&bgcolor=%23e1e9f0&graph_bgcolor=%23ffffff&fo=Open+Sans&ts=12&tts=12&txtcolor=%23444444&show_legend=yes&show_axis_titles=yes&drp=0&cosd=2017-01-08&coed=2018-01-08&height=450&stacking=&range=1yr&mode=fred&id=DDFUELUSGULF&transformation=lin&nd=2006-06-14&ost=-99999&oet=99999&lsv=&lev=&mma=0&fml=a&fgst=lin&fgsnd=2009-06-01&fq=Daily&fam=avg&vintage_date=&revision_date=&line_color=%234572a7&line_style=solid&lw=2&scale=left&mark_type=none&mw=2&width=1168", "Diesel-Fuel.csv")
print 'downloading gasoline data'
urllib.urlretrieve("https://fred.stlouisfed.org/graph/fredgraph.csv?chart_type=line&recession_bars=on&log_scales=&bgcolor=%23e1e9f0&graph_bgcolor=%23ffffff&fo=Open+Sans&ts=12&tts=12&txtcolor=%23444444&show_legend=yes&show_axis_titles=yes&drp=0&cosd=2017-01-08&coed=2018-01-08&height=450&stacking=&range=1yr&mode=fred&id=DGASUSGULF&transformation=lin&nd=1986-06-02&ost=-99999&oet=99999&lsv=&lev=&mma=0&fml=a&fgst=lin&fgsnd=2009-06-01&fq=Daily&fam=avg&vintage_date=&revision_date=&line_color=%234572a7&line_style=solid&lw=2&scale=left&mark_type=none&mw=2&width=1168", "Gasoline.csv")
print 'downloading gold data'
urllib.urlretrieve("https://fred.stlouisfed.org/graph/fredgraph.csv?chart_type=line&recession_bars=on&log_scales=&bgcolor=%23e1e9f0&graph_bgcolor=%23ffffff&fo=Open+Sans&ts=12&tts=12&txtcolor=%23444444&show_legend=yes&show_axis_titles=yes&drp=0&cosd=2017-01-11&coed=2018-01-11&height=450&stacking=&range=1yr&mode=fred&id=GOLDAMGBD228NLBM&transformation=lin&nd=1968-04-01&ost=-99999&oet=99999&lsv=&lev=&mma=0&fml=a&fgst=lin&fgsnd=2009-06-01&fq=Daily&fam=avg&vintage_date=&revision_date=&line_color=%234572a7&line_style=solid&lw=2&scale=left&mark_type=none&mw=2&width=1168", "gold.csv")
print 'downloading heating oil data'
urllib.urlretrieve("https://fred.stlouisfed.org/graph/fredgraph.csv?chart_type=line&recession_bars=on&log_scales=&bgcolor=%23e1e9f0&graph_bgcolor=%23ffffff&fo=Open+Sans&ts=12&tts=12&txtcolor=%23444444&show_legend=yes&show_axis_titles=yes&drp=0&cosd=2017-01-05&coed=2018-01-05&height=450&stacking=&range=1yr&mode=fred&id=WHOILNYH&transformation=lin&nd=1986-06-06&ost=-99999&oet=99999&lsv=&lev=&mma=0&fml=a&fgst=lin&fgsnd=2009-06-01&fq=Weekly%2C+Ending+Friday&fam=avg&vintage_date=&revision_date=&line_color=%234572a7&line_style=solid&lw=2&scale=left&mark_type=none&mw=2&width=1168", "Heating-Oil.csv")
print 'downloading kerosene data'
urllib.urlretrieve("https://fred.stlouisfed.org/graph/fredgraph.csv?chart_type=line&recession_bars=on&log_scales=&bgcolor=%23e1e9f0&graph_bgcolor=%23ffffff&fo=Open+Sans&ts=12&tts=12&txtcolor=%23444444&show_legend=yes&show_axis_titles=yes&drp=0&cosd=2017-01-05&coed=2018-01-05&height=450&stacking=&range=1yr&mode=fred&id=WJFUELUSGULF&transformation=lin&nd=1990-04-06&ost=-99999&oet=99999&lsv=&lev=&mma=0&fml=a&fgst=lin&fgsnd=2009-06-01&fq=Weekly%2C+Ending+Friday&fam=avg&vintage_date=&revision_date=&line_color=%234572a7&line_style=solid&lw=2&scale=left&mark_type=none&mw=2&width=1168", "Kerosene-Type-Jet-Fuel.csv")
print 'downloading natural gas data'
urllib.urlretrieve("https://fred.stlouisfed.org/graph/fredgraph.csv?chart_type=line&recession_bars=on&log_scales=&bgcolor=%23e1e9f0&graph_bgcolor=%23ffffff&fo=Open+Sans&ts=12&tts=12&txtcolor=%23444444&show_legend=yes&show_axis_titles=yes&drp=0&cosd=2017-01-08&coed=2018-01-08&height=450&stacking=&range=1yr&mode=fred&id=DHHNGSP&transformation=lin&nd=1997-01-07&ost=-99999&oet=99999&lsv=&lev=&mma=0&fml=a&fgst=lin&fgsnd=2009-06-01&fq=Daily&fam=avg&vintage_date=&revision_date=&line_color=%234572a7&line_style=solid&lw=2&scale=left&mark_type=none&mw=2&width=1168", "Natural-Gas-Spot.csv")
print 'downloading propane data'
urllib.urlretrieve("https://fred.stlouisfed.org/graph/fredgraph.csv?chart_type=line&recession_bars=on&log_scales=&bgcolor=%23e1e9f0&graph_bgcolor=%23ffffff&fo=Open+Sans&ts=12&tts=12&txtcolor=%23444444&show_legend=yes&show_axis_titles=yes&drp=0&cosd=2017-01-08&coed=2018-01-08&height=450&stacking=&range=1yr&mode=fred&id=DPROPANEMBTX&transformation=lin&nd=1992-07-09&ost=-99999&oet=99999&lsv=&lev=&mma=0&fml=a&fgst=lin&fgsnd=2009-06-01&fq=Daily&fam=avg&vintage_date=&revision_date=&line_color=%234572a7&line_style=solid&lw=2&scale=left&mark_type=none&mw=2&width=1168", "propane.csv")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment