{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "from bokeh.sampledata.stocks import AAPL, FB, GOOG, IBM, MSFT\n",
    "from bokeh.plotting import figure, show, output_notebook"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "output_notebook()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "p1 = figure(x_axis_type = \"datetime\")\n",
    "\n",
    "p1.line(np.array(AAPL['date'], 'M64'), AAPL['adj_close'], color='#A6CEE3', legend='AAPL')\n",
    "p1.line(np.array(FB['date'], 'M64'), FB['adj_close'], color='#1F78B4', legend='FB')\n",
    "p1.line(np.array(GOOG['date'], 'M64'), GOOG['adj_close'], color='#B2DF8A', legend='GOOG')\n",
    "p1.line(np.array(IBM['date'], 'M64'), IBM['adj_close'], color='#33A02C', legend='IBM')\n",
    "p1.line(np.array(MSFT['date'], 'M64'), MSFT['adj_close'], color='#FB9A99', legend='MSFT')\n",
    "\n",
    "p1.title = \"Stock Closing Prices\"\n",
    "p1.grid.grid_line_alpha=0.3\n",
    "\n",
    "show(p1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "aapl = np.array(AAPL['adj_close'])\n",
    "aapl_dates = np.array(AAPL['date'], dtype=np.datetime64)\n",
    "\n",
    "window_size = 30\n",
    "window = np.ones(window_size)/float(window_size)\n",
    "aapl_avg = np.convolve(aapl, window, 'same')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "p2 = figure(x_axis_type=\"datetime\")\n",
    "\n",
    "p2.circle(aapl_dates, aapl, size=4, color='darkgrey', alpha=0.2, legend='close')\n",
    "p2.line(aapl_dates, aapl_avg, color='navy', legend='avg')\n",
    "\n",
    "p2.title = \"AAPL One-Month Average\"\n",
    "p2.grid.grid_line_alpha=0\n",
    "p2.ygrid.band_fill_color=\"olive\"\n",
    "p2.ygrid.band_fill_alpha = 0.1\n",
    "\n",
    "show(p2) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
