Last active
December 7, 2017 19:40
-
-
Save wwright999/582ba7daa6e459e5a56df5f1d0160d9b to your computer and use it in GitHub Desktop.
Download Continuous Futures EOD data from Quandl.com and save in SQLlite database
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 quandl | |
import pandas as pd | |
from sqlalchemy import create_engine | |
# Link to list of symbols | |
https://www.quandl.com/data/SCF-Continuous-Futures/documentation/documentation | |
# Sign up at Quandl.com to get Auth Token | |
token = 'your auth token from quandl.com' | |
# Select Symbols for Download (symbols stored in pandas data frame) | |
ty = quandl.get("SCF/CME_TY1_OR", authtoken=token) | |
us = quandl.get("SCF/CME_US1_OR", authtoken=token) | |
fv = quandl.get("SCF/CME_FV1_OR", authtoken=token) | |
tu = quandl.get("SCF/CME_TU1_OR", authtoken=token) | |
vix = quandl.get("SCF/CBOE_VX1_OR", authtoken=token) | |
sp = quandl.get("SCF/CME_ES1_OR", authtoken=token) | |
dax = quandl.get("SCF/EUREX_FDAX1_OR", authtoken=token) | |
bund = quandl.get("SCF/EUREX_FGBL1_OR", authtoken=token) | |
gilt = quandl.get("SCF/LIFFE_R1_OR", authtoken=token) | |
gold = quandl.get("SCF/CME_GC1_OR", authtoken=token) | |
crude = quandl.get("SCF/CME_CL1_OR", authtoken=token) | |
ym = quandl.get("SCF/CME_YM1_OR", authtoken=token) | |
russ2k = quandl.get("SCF/ICE_TF1_OR", authtoken=token) | |
dol = quandl.get("SCF/ICE_DX1_OR", authtoken=token) | |
eurodollar = quandl.get("SCF/CME_ED1_OR", authtoken=token) | |
ffunds = quandl.get("SCF/CME_FF1_OR", authtoken=token) | |
# List of Symbols | |
dfs = [ty, us, fv,tu,vix,sp,dax,bund,gilt,gold,crude,ym,russ2k,dol,eurodollar,ffunds] | |
# Text List of Symbols | |
names = ["ty", "us", "fv","tu","vix","sp","dax","bund","gilt","gold","crude","ym","russ2k","dol","eurodollar","ffunds"] | |
# ADD SYMBOL COLUMN FOR IDENTIFICATION | |
for d,n in zip(dfs,names): | |
d["Symbol"]= n | |
# APPEND(END TO END) ALL DATA INTO SINGLE DATA FRAME | |
fut = pd.concat(dfs) | |
# IMPORT SQL ALCHEMY AND LOAD DATA INTO DATABASE CALLED futures.db | |
path = "./data/" | |
engine = create_engine('sqlite:///futures.db') | |
fut.to_sql('futures', engine, if_exists='append') | |
# READ TABLE INTO DATA FRAME | |
df = pd.read_sql_table('futures', engine) | |
# OTHER IO WITH PANDAS | |
def test_hdf_fixed_write(df): | |
df.to_hdf('test_fixed.hdf','test',mode='w') | |
def test_hdf_fixed_read(): | |
pd.read_hdf('test_fixed.hdf','test') | |
def test_hdf_fixed_write_compress(df): | |
df.to_hdf('test_fixed_compress.hdf','test',mode='w',complib='blosc') | |
def test_hdf_fixed_read_compress(): | |
pd.read_hdf('test_fixed_compress.hdf','test') | |
def test_hdf_table_write(df): | |
df.to_hdf('test_table.hdf','test',mode='w',format='table') | |
def test_hdf_table_read(): | |
pd.read_hdf('test_table.hdf','test') | |
def test_hdf_table_write_compress(df): | |
df.to_hdf('test_table_compress.hdf','test',mode='w',complib='blosc',format='table') | |
def test_hdf_table_read_compress(): | |
pd.read_hdf('test_table_compress.hdf','test') | |
def test_csv_write(df): | |
df.to_csv('test.csv',mode='w') | |
def test_csv_read(): | |
pd.read_csv('test.csv',index_col=0) | |
def test_feather_write(df): | |
df.to_feather('test.feather') | |
def test_feather_read(): | |
pd.read_feather('test.feather') | |
def test_pickle_write(df): | |
df.to_pickle('test.pkl') | |
def test_pickle_read(): | |
pd.read_pickle('test.pkl') | |
def test_pickle_write_compress(df): | |
df.to_pickle('test.pkl.compress', compression='xz') | |
def test_pickle_read_compress(): | |
pd.read_pickle('test.pkl.compress', compression='xz') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment