{
 "metadata": {
  "name": "",
  "signature": "sha256:591f36e7081f6a4ac7dbab01be04d964772a4176ee945bfb272823285ce13b7c"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import numpy as np\n",
      "from bokeh.sampledata.stocks import AAPL, FB, GOOG, IBM, MSFT\n",
      "from bokeh.plotting import *"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "output_notebook()"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "figure(x_axis_type=\"datetime\", tools=\"pan,wheel_zoom,box_zoom,reset,previewsave\")"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "hold()"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "figure(x_axis_type = \"datetime\")\n",
      "\n",
      "line(np.array(AAPL['date'], 'M64'), AAPL['adj_close'], color='#A6CEE3', legend='AAPL')\n",
      "line(np.array(FB['date'], 'M64'), FB['adj_close'], color='#1F78B4', legend='FB')\n",
      "line(np.array(GOOG['date'], 'M64'), GOOG['adj_close'], color='#B2DF8A', legend='GOOG')\n",
      "line(np.array(IBM['date'], 'M64'), IBM['adj_close'], color='#33A02C', legend='IBM')\n",
      "line(np.array(MSFT['date'], 'M64'), MSFT['adj_close'], color='#FB9A99', legend='MSFT')\n",
      "\n",
      "curplot().title = \"Stock Closing Prices\"\n",
      "grid().grid_line_alpha=0.3\n",
      "\n",
      "show()"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "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')"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "figure(x_axis_type=\"datetime\")\n",
      "\n",
      "scatter(aapl_dates, aapl, size=4, color='#A6CEE3', legend='close')\n",
      "line(aapl_dates, aapl_avg, color='red', legend='avg')\n",
      "\n",
      "curplot().title = \"AAPL One-Month Average\"\n",
      "grid().grid_line_alpha=0.3\n",
      "\n",
      "show()  # open a browser"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [],
     "language": "python",
     "metadata": {},
     "outputs": []
    }
   ],
   "metadata": {}
  }
 ]
}