Quandl is an aggregation of many financial data sources. Much of the data is free and some is available on a subscription basis. It is perhaps the best place to get started with when looking for micro or macroeconomic data. Below is an example of the Quandl functionality and usage.
%matplotlib inline
from datetime import datetime
from pandas_datareader.data import DataReader
from pandas import DataFrame
from pandas.tseries.offsets import BMonthEnd, Week
# Data and function definitions
dtEnd = datetime.today()
dtStart = datetime(dtEnd.year - 1, dtEnd.month, dtEnd.day)
maWindow = 50
def print_current_value(source, data):
''' Output the last value of the series passed by data '''
header = data.columns[0]
print("In {3} {0} = {1} for {2}.".format(header, data[header].values[0], data.index[0].date(), source))
def print_describe(df, option):
''' Ouput detailes about the data '''
for key, value in df.items():
details = df[key].describe()
if option == 'detailed':
print(details)
else:
print("min = {}".format(details['min']))
print("max = {}".format(details['max']))
print("mean = {}".format(details['mean']))
import quandl
auth_tok = "yourkey"
#Set up dict with Dataset names, Quandl Codes, and empty lists for our data
diTickers = {'CBOE/VIX': 'VIX Close'}
dataDict = {}
source = "Quandl"
# ----------------------------------------------
# Load Fund Price and Return Data
# ----------------------------------------------
for fund, metric in diTickers.items():
if (metric is not None):
dataDict[fund] = quandl.get(fund, authtoken=auth_tok, trim_start=dtStart, trim_end=dtEnd)[metric]
else:
dataDict[fund] = quandl.get(fund, authtoken=auth_tok, trim_start=dtStart, trim_end=dtEnd)
# output graph
for key, value in dataDict.items():
dfValues = DataFrame(dataDict).dropna(how='any', axis=0)
dfValues["{} day MA".format(maWindow)] = dfValues.rolling(window=maWindow, center=False).mean()
# Output information about the data
print_current_value(source, dfValues.tail(1))
print_describe(dataDict, option='lean')
# Show a graph of the data
ax = dfValues.plot(figsize=(10,5), grid=True, title='{0} Price in {1}'.format(key, source), color=["b","r"])
ax.set_ylabel("%")
# Print describe information
print_describe(dataDict, option='detailed')