#!/usr/bin/env python # coding: utf-8 # # Sources of Open Data # In[1]: import addutils.toc ; addutils.toc.js(ipy_notebook=True) # In[2]: import datetime import scipy.io import numpy as np import pandas as pd import pandas_datareader.data as web import bokeh.plotting as bk from IPython.display import display bk.output_notebook() # In[3]: from addutils import css_notebook css_notebook() # ## 1 Yahoo! Finance # In[4]: start = datetime.datetime(2000, 1, 1) end = datetime.datetime(2014, 5, 14) AAPL_yahoo = web.DataReader("AAPL", 'yahoo', start, end) IBM_yahoo = web.DataReader("IBM", 'yahoo', start, end) # ### 1.1 Plotting timeseries with bokeh: # In[5]: fig = bk.figure(x_axis_type = "datetime", tools="pan,box_zoom,reset", title = 'Closing Prices - From Yahoo! Finance', plot_width=750, plot_height=400) fig.line(AAPL_yahoo.index, AAPL_yahoo['Adj Close'], line_width=2, color='darkred', legend='Apple') fig.line(IBM_yahoo.index, IBM_yahoo['Adj Close'], line_width=2, color='royalblue', legend='IBM') fig.legend.location = "top_left" bk.show(fig) # In[6]: df = AAPL_yahoo[-100:] mids = (df['High']+df['Low'])/2 spans = df['Close']-df['Open'] inc = df['Close']>=df['Open'] dec = df['Close']) for more tutorials and updates. # # This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.