ml-finance-python

python scripts for finance machine learning

git clone https://9o.is/git/ml-finance-python.git

notebook.ipynb

(23907B)


      1 {
      2  "cells": [
      3   {
      4    "cell_type": "markdown",
      5    "metadata": {
      6     "collapsed": true
      7    },
      8    "source": [
      9     "# EventVestor: Index Changes\n",
     10     "\n",
     11     "In this notebook, we'll take a look at EventVestor's *Index Changes* dataset, available on the [Quantopian Store](https://www.quantopian.com/store). This dataset spans January 01, 2007 through the current day, and documents index additions and deletions to major S&P, Russell, and Nasdaq 100 indexes.\n",
     12     "\n",
     13     "### Blaze\n",
     14     "Before we dig into the data, we want to tell you about how  you generally access Quantopian Store data sets. These datasets are available through an API service known as [Blaze](http://blaze.pydata.org). Blaze provides the Quantopian user with a convenient interface to access very large datasets.\n",
     15     "\n",
     16     "Blaze provides an important function for accessing these datasets. Some of these sets are many millions of records. Bringing that data directly into Quantopian Research directly just is not viable. So Blaze allows us to provide a simple querying interface and shift the burden over to the server side.\n",
     17     "\n",
     18     "It is common to use Blaze to reduce your dataset in size, convert it over to Pandas and then to use Pandas for further computation, manipulation and visualization.\n",
     19     "\n",
     20     "Helpful links:\n",
     21     "* [Query building for Blaze](http://blaze.pydata.org/en/latest/queries.html)\n",
     22     "* [Pandas-to-Blaze dictionary](http://blaze.pydata.org/en/latest/rosetta-pandas.html)\n",
     23     "* [SQL-to-Blaze dictionary](http://blaze.pydata.org/en/latest/rosetta-sql.html).\n",
     24     "\n",
     25     "Once you've limited the size of your Blaze object, you can convert it to a Pandas DataFrames using:\n",
     26     "> `from odo import odo`  \n",
     27     "> `odo(expr, pandas.DataFrame)`\n",
     28     "\n",
     29     "### Free samples and limits\n",
     30     "One other key caveat: we limit the number of results returned from any given expression to 10,000 to protect against runaway memory usage. To be clear, you have access to all the data server side. We are limiting the size of the responses back from Blaze.\n",
     31     "\n",
     32     "There is a *free* version of this dataset as well as a paid one. The free one includes about three years of historical data, though not up to the current day.\n",
     33     "\n",
     34     "With preamble in place, let's get started:"
     35    ]
     36   },
     37   {
     38    "cell_type": "code",
     39    "execution_count": 1,
     40    "metadata": {
     41     "collapsed": false
     42    },
     43    "outputs": [],
     44    "source": [
     45     "# import the dataset\n",
     46     "from quantopian.interactive.data.eventvestor import index_changes\n",
     47     "# or if you want to import the free dataset, use:\n",
     48     "# from quantopian.interactive.data.eventvestor import index_changes_free\n",
     49     "\n",
     50     "# import data operations\n",
     51     "from odo import odo\n",
     52     "# import other libraries we will use\n",
     53     "import pandas as pd"
     54    ]
     55   },
     56   {
     57    "cell_type": "code",
     58    "execution_count": 2,
     59    "metadata": {
     60     "collapsed": false
     61    },
     62    "outputs": [
     63     {
     64      "data": {
     65       "text/plain": [
     66        "dshape(\"\"\"var * {\n",
     67        "  event_id: ?float64,\n",
     68        "  asof_date: datetime,\n",
     69        "  trade_date: ?datetime,\n",
     70        "  symbol: ?string,\n",
     71        "  event_type: ?string,\n",
     72        "  event_headline: ?string,\n",
     73        "  index_name: ?string,\n",
     74        "  change_type: ?string,\n",
     75        "  change_reason: ?string,\n",
     76        "  event_rating: ?float64,\n",
     77        "  timestamp: datetime,\n",
     78        "  sid: ?int64\n",
     79        "  }\"\"\")"
     80       ]
     81      },
     82      "execution_count": 2,
     83      "metadata": {},
     84      "output_type": "execute_result"
     85     }
     86    ],
     87    "source": [
     88     "# Let's use blaze to understand the data a bit using Blaze dshape()\n",
     89     "index_changes.dshape"
     90    ]
     91   },
     92   {
     93    "cell_type": "code",
     94    "execution_count": 3,
     95    "metadata": {
     96     "collapsed": false
     97    },
     98    "outputs": [
     99     {
    100      "data": {
    101       "text/html": [
    102        "2510"
    103       ],
    104       "text/plain": [
    105        "2510"
    106       ]
    107      },
    108      "execution_count": 3,
    109      "metadata": {},
    110      "output_type": "execute_result"
    111     }
    112    ],
    113    "source": [
    114     "# And how many rows are there?\n",
    115     "# N.B. we're using a Blaze function to do this, not len()\n",
    116     "index_changes.count()"
    117    ]
    118   },
    119   {
    120    "cell_type": "code",
    121    "execution_count": 4,
    122    "metadata": {
    123     "collapsed": false
    124    },
    125    "outputs": [
    126     {
    127      "data": {
    128       "text/html": [
    129        "<table border=\"1\" class=\"dataframe\">\n",
    130        "  <thead>\n",
    131        "    <tr style=\"text-align: right;\">\n",
    132        "      <th></th>\n",
    133        "      <th>event_id</th>\n",
    134        "      <th>asof_date</th>\n",
    135        "      <th>trade_date</th>\n",
    136        "      <th>symbol</th>\n",
    137        "      <th>event_type</th>\n",
    138        "      <th>event_headline</th>\n",
    139        "      <th>index_name</th>\n",
    140        "      <th>change_type</th>\n",
    141        "      <th>change_reason</th>\n",
    142        "      <th>event_rating</th>\n",
    143        "      <th>timestamp</th>\n",
    144        "      <th>sid</th>\n",
    145        "    </tr>\n",
    146        "  </thead>\n",
    147        "  <tbody>\n",
    148        "    <tr>\n",
    149        "      <th>0</th>\n",
    150        "      <td>174074</td>\n",
    151        "      <td>2007-01-02</td>\n",
    152        "      <td>2007-01-03</td>\n",
    153        "      <td>BLS</td>\n",
    154        "      <td>Index Change</td>\n",
    155        "      <td>BellSouth Corp. (BLS) removed from S&amp;P 500</td>\n",
    156        "      <td>S&amp;P 500</td>\n",
    157        "      <td>Deletion</td>\n",
    158        "      <td>NaN</td>\n",
    159        "      <td>1</td>\n",
    160        "      <td>2007-01-03</td>\n",
    161        "      <td>948</td>\n",
    162        "    </tr>\n",
    163        "    <tr>\n",
    164        "      <th>1</th>\n",
    165        "      <td>174076</td>\n",
    166        "      <td>2007-01-02</td>\n",
    167        "      <td>2007-01-03</td>\n",
    168        "      <td>ESV</td>\n",
    169        "      <td>Index Change</td>\n",
    170        "      <td>ENSCO, Int'l (ESV) removed from S&amp;P 400</td>\n",
    171        "      <td>S&amp;P 400</td>\n",
    172        "      <td>Deletion</td>\n",
    173        "      <td>NaN</td>\n",
    174        "      <td>1</td>\n",
    175        "      <td>2007-01-03</td>\n",
    176        "      <td>2621</td>\n",
    177        "    </tr>\n",
    178        "    <tr>\n",
    179        "      <th>2</th>\n",
    180        "      <td>174071</td>\n",
    181        "      <td>2007-01-02</td>\n",
    182        "      <td>2007-01-03</td>\n",
    183        "      <td>ESV</td>\n",
    184        "      <td>Index Change</td>\n",
    185        "      <td>ENSCO International (ESV) added to S&amp;P 500</td>\n",
    186        "      <td>S&amp;P 500</td>\n",
    187        "      <td>Addition</td>\n",
    188        "      <td>NaN</td>\n",
    189        "      <td>1</td>\n",
    190        "      <td>2007-01-03</td>\n",
    191        "      <td>2621</td>\n",
    192        "    </tr>\n",
    193        "  </tbody>\n",
    194        "</table>"
    195       ],
    196       "text/plain": [
    197        "   event_id  asof_date trade_date symbol    event_type  \\\n",
    198        "0    174074 2007-01-02 2007-01-03    BLS  Index Change   \n",
    199        "1    174076 2007-01-02 2007-01-03    ESV  Index Change   \n",
    200        "2    174071 2007-01-02 2007-01-03    ESV  Index Change   \n",
    201        "\n",
    202        "                               event_headline index_name change_type  \\\n",
    203        "0  BellSouth Corp. (BLS) removed from S&P 500    S&P 500    Deletion   \n",
    204        "1     ENSCO, Int'l (ESV) removed from S&P 400    S&P 400    Deletion   \n",
    205        "2  ENSCO International (ESV) added to S&P 500    S&P 500    Addition   \n",
    206        "\n",
    207        "  change_reason  event_rating  timestamp   sid  \n",
    208        "0           NaN             1 2007-01-03   948  \n",
    209        "1           NaN             1 2007-01-03  2621  \n",
    210        "2           NaN             1 2007-01-03  2621  "
    211       ]
    212      },
    213      "execution_count": 4,
    214      "metadata": {},
    215      "output_type": "execute_result"
    216     }
    217    ],
    218    "source": [
    219     "# Let's see what the data looks like. We'll grab the first three rows.\n",
    220     "index_changes[:3]"
    221    ]
    222   },
    223   {
    224    "cell_type": "markdown",
    225    "metadata": {},
    226    "source": [
    227     "Let's go over the columns:\n",
    228     "- **event_id**: the unique identifier for this event.\n",
    229     "- **asof_date**: EventVestor's timestamp of event capture.\n",
    230     "- **trade_date**: for event announcements made before trading ends, trade_date is the same as event_date. For announcements issued after market close, trade_date is next market open day.\n",
    231     "- **symbol**: stock ticker symbol of the affected company.\n",
    232     "- **event_type**: this should always be *Index Change*.\n",
    233     "- **event_headline**: a brief description of the event\n",
    234     "- **index_name**: name of the index affected. Values include *S&P 400, S&P 500, S&P 600*\n",
    235     "- **change_type**: Addition/Deletion of equity\n",
    236     "- **change_reason**: reason for addition/deletion of the equity from the index. Reasons include *Acquired, Market Cap, Other*.\n",
    237     "- **event_rating**: this is always 1. The meaning of this is uncertain.\n",
    238     "- **timestamp**: this is our timestamp on when we registered the data.\n",
    239     "- **sid**: the equity's unique identifier. Use this instead of the symbol. Note: this sid represents the  company the shares of which are being purchased, not the acquiring entity."
    240    ]
    241   },
    242   {
    243    "cell_type": "markdown",
    244    "metadata": {},
    245    "source": [
    246     "We've done much of the data processing for you. Fields like `timestamp` and `sid` are standardized across all our Store Datasets, so the datasets are easy to combine. We have standardized the `sid` across all our equity databases.\n",
    247     "\n",
    248     "We can select columns and rows with ease. Below, we'll fetch all 2015 deletions due to market cap."
    249    ]
    250   },
    251   {
    252    "cell_type": "code",
    253    "execution_count": 5,
    254    "metadata": {
    255     "collapsed": false,
    256     "scrolled": true
    257    },
    258    "outputs": [
    259     {
    260      "data": {
    261       "text/html": [
    262        "<table border=\"1\" class=\"dataframe\">\n",
    263        "  <thead>\n",
    264        "    <tr style=\"text-align: right;\">\n",
    265        "      <th></th>\n",
    266        "      <th>event_id</th>\n",
    267        "      <th>asof_date</th>\n",
    268        "      <th>trade_date</th>\n",
    269        "      <th>symbol</th>\n",
    270        "      <th>event_type</th>\n",
    271        "      <th>event_headline</th>\n",
    272        "      <th>index_name</th>\n",
    273        "      <th>change_type</th>\n",
    274        "      <th>change_reason</th>\n",
    275        "      <th>event_rating</th>\n",
    276        "      <th>timestamp</th>\n",
    277        "      <th>sid</th>\n",
    278        "    </tr>\n",
    279        "  </thead>\n",
    280        "  <tbody>\n",
    281        "    <tr>\n",
    282        "      <th>0</th>\n",
    283        "      <td>1885908</td>\n",
    284        "      <td>2015-05-21</td>\n",
    285        "      <td>2015-05-22</td>\n",
    286        "      <td>WIN</td>\n",
    287        "      <td>Index Change</td>\n",
    288        "      <td>Windstream Holdings to be Removed from S&amp;P Mid...</td>\n",
    289        "      <td>S&amp;P 400</td>\n",
    290        "      <td>Deletion</td>\n",
    291        "      <td>Market Cap</td>\n",
    292        "      <td>1</td>\n",
    293        "      <td>2015-05-22</td>\n",
    294        "      <td>27019</td>\n",
    295        "    </tr>\n",
    296        "    <tr>\n",
    297        "      <th>1</th>\n",
    298        "      <td>1894211</td>\n",
    299        "      <td>2015-06-24</td>\n",
    300        "      <td>2015-06-24</td>\n",
    301        "      <td>ATI</td>\n",
    302        "      <td>Index Change</td>\n",
    303        "      <td>Allegheny Technologies to be Removed from S&amp;P ...</td>\n",
    304        "      <td>S&amp;P 500</td>\n",
    305        "      <td>Deletion</td>\n",
    306        "      <td>Market Cap</td>\n",
    307        "      <td>1</td>\n",
    308        "      <td>2015-06-25</td>\n",
    309        "      <td>24840</td>\n",
    310        "    </tr>\n",
    311        "    <tr>\n",
    312        "      <th>2</th>\n",
    313        "      <td>1894270</td>\n",
    314        "      <td>2015-06-24</td>\n",
    315        "      <td>2015-06-24</td>\n",
    316        "      <td>SMTC</td>\n",
    317        "      <td>Index Change</td>\n",
    318        "      <td>Semtech Corp. to be Removed from S&amp;P MidCap 40...</td>\n",
    319        "      <td>S&amp;P 400</td>\n",
    320        "      <td>Deletion</td>\n",
    321        "      <td>Market Cap</td>\n",
    322        "      <td>1</td>\n",
    323        "      <td>2015-06-25</td>\n",
    324        "      <td>6961</td>\n",
    325        "    </tr>\n",
    326        "    <tr>\n",
    327        "      <th>3</th>\n",
    328        "      <td>1894266</td>\n",
    329        "      <td>2015-06-24</td>\n",
    330        "      <td>2015-06-24</td>\n",
    331        "      <td>BTU</td>\n",
    332        "      <td>Index Change</td>\n",
    333        "      <td>Peabody Energy Corp. to be Removed from S&amp;P Mi...</td>\n",
    334        "      <td>S&amp;P 400</td>\n",
    335        "      <td>Deletion</td>\n",
    336        "      <td>Market Cap</td>\n",
    337        "      <td>1</td>\n",
    338        "      <td>2015-06-25</td>\n",
    339        "      <td>22660</td>\n",
    340        "    </tr>\n",
    341        "    <tr>\n",
    342        "      <th>4</th>\n",
    343        "      <td>1894278</td>\n",
    344        "      <td>2015-06-24</td>\n",
    345        "      <td>2015-06-24</td>\n",
    346        "      <td>HSC</td>\n",
    347        "      <td>Index Change</td>\n",
    348        "      <td>Harsco Corp. to be Removed from S&amp;P MidCap 400...</td>\n",
    349        "      <td>S&amp;P 400</td>\n",
    350        "      <td>Deletion</td>\n",
    351        "      <td>Market Cap</td>\n",
    352        "      <td>1</td>\n",
    353        "      <td>2015-06-25</td>\n",
    354        "      <td>3686</td>\n",
    355        "    </tr>\n",
    356        "    <tr>\n",
    357        "      <th>5</th>\n",
    358        "      <td>1894221</td>\n",
    359        "      <td>2015-06-24</td>\n",
    360        "      <td>2015-06-24</td>\n",
    361        "      <td>PQ</td>\n",
    362        "      <td>Index Change</td>\n",
    363        "      <td>PetroQuest Energy to be Removed from S&amp;P Small...</td>\n",
    364        "      <td>S&amp;P 600</td>\n",
    365        "      <td>Deletion</td>\n",
    366        "      <td>Market Cap</td>\n",
    367        "      <td>1</td>\n",
    368        "      <td>2015-06-25</td>\n",
    369        "      <td>19326</td>\n",
    370        "    </tr>\n",
    371        "    <tr>\n",
    372        "      <th>6</th>\n",
    373        "      <td>1894247</td>\n",
    374        "      <td>2015-06-24</td>\n",
    375        "      <td>2015-06-24</td>\n",
    376        "      <td>ARO</td>\n",
    377        "      <td>Index Change</td>\n",
    378        "      <td>Aeropostale to be Removed from S&amp;P SmallCap 60...</td>\n",
    379        "      <td>S&amp;P 600</td>\n",
    380        "      <td>Deletion</td>\n",
    381        "      <td>Market Cap</td>\n",
    382        "      <td>1</td>\n",
    383        "      <td>2015-06-25</td>\n",
    384        "      <td>23650</td>\n",
    385        "    </tr>\n",
    386        "    <tr>\n",
    387        "      <th>7</th>\n",
    388        "      <td>1894217</td>\n",
    389        "      <td>2015-06-24</td>\n",
    390        "      <td>2015-06-24</td>\n",
    391        "      <td>UNT</td>\n",
    392        "      <td>Index Change</td>\n",
    393        "      <td>Unit Corp. to be Removed from S&amp;P MidCap 400 I...</td>\n",
    394        "      <td>S&amp;P 400</td>\n",
    395        "      <td>Deletion</td>\n",
    396        "      <td>Market Cap</td>\n",
    397        "      <td>1</td>\n",
    398        "      <td>2015-06-25</td>\n",
    399        "      <td>7806</td>\n",
    400        "    </tr>\n",
    401        "    <tr>\n",
    402        "      <th>8</th>\n",
    403        "      <td>1894258</td>\n",
    404        "      <td>2015-06-24</td>\n",
    405        "      <td>2015-06-24</td>\n",
    406        "      <td>ZQK</td>\n",
    407        "      <td>Index Change</td>\n",
    408        "      <td>Quiksilver to be Removed from S&amp;P SmallCap 600...</td>\n",
    409        "      <td>S&amp;P 600</td>\n",
    410        "      <td>Deletion</td>\n",
    411        "      <td>Market Cap</td>\n",
    412        "      <td>1</td>\n",
    413        "      <td>2015-06-25</td>\n",
    414        "      <td>6317</td>\n",
    415        "    </tr>\n",
    416        "    <tr>\n",
    417        "      <th>9</th>\n",
    418        "      <td>1894293</td>\n",
    419        "      <td>2015-06-24</td>\n",
    420        "      <td>2015-06-24</td>\n",
    421        "      <td>FXCM</td>\n",
    422        "      <td>Index Change</td>\n",
    423        "      <td>FXCM to be Removed from S&amp;P SmallCap 600 Index</td>\n",
    424        "      <td>S&amp;P 600</td>\n",
    425        "      <td>Deletion</td>\n",
    426        "      <td>Market Cap</td>\n",
    427        "      <td>1</td>\n",
    428        "      <td>2015-06-25</td>\n",
    429        "      <td>40531</td>\n",
    430        "    </tr>\n",
    431        "    <tr>\n",
    432        "      <th>10</th>\n",
    433        "      <td>1895235</td>\n",
    434        "      <td>2015-06-26</td>\n",
    435        "      <td>2015-06-29</td>\n",
    436        "      <td>JBHT</td>\n",
    437        "      <td>Index Change</td>\n",
    438        "      <td>J.B. Hunt Transport Services to be Removed fro...</td>\n",
    439        "      <td>S&amp;P 400</td>\n",
    440        "      <td>Deletion</td>\n",
    441        "      <td>Market Cap</td>\n",
    442        "      <td>1</td>\n",
    443        "      <td>2015-06-27</td>\n",
    444        "      <td>4108</td>\n",
    445        "    </tr>\n",
    446        "  </tbody>\n",
    447        "</table>"
    448       ],
    449       "text/plain": [
    450        "    event_id  asof_date trade_date symbol    event_type  \\\n",
    451        "0    1885908 2015-05-21 2015-05-22    WIN  Index Change   \n",
    452        "1    1894211 2015-06-24 2015-06-24    ATI  Index Change   \n",
    453        "2    1894270 2015-06-24 2015-06-24   SMTC  Index Change   \n",
    454        "3    1894266 2015-06-24 2015-06-24    BTU  Index Change   \n",
    455        "4    1894278 2015-06-24 2015-06-24    HSC  Index Change   \n",
    456        "5    1894221 2015-06-24 2015-06-24     PQ  Index Change   \n",
    457        "6    1894247 2015-06-24 2015-06-24    ARO  Index Change   \n",
    458        "7    1894217 2015-06-24 2015-06-24    UNT  Index Change   \n",
    459        "8    1894258 2015-06-24 2015-06-24    ZQK  Index Change   \n",
    460        "9    1894293 2015-06-24 2015-06-24   FXCM  Index Change   \n",
    461        "10   1895235 2015-06-26 2015-06-29   JBHT  Index Change   \n",
    462        "\n",
    463        "                                       event_headline index_name change_type  \\\n",
    464        "0   Windstream Holdings to be Removed from S&P Mid...    S&P 400    Deletion   \n",
    465        "1   Allegheny Technologies to be Removed from S&P ...    S&P 500    Deletion   \n",
    466        "2   Semtech Corp. to be Removed from S&P MidCap 40...    S&P 400    Deletion   \n",
    467        "3   Peabody Energy Corp. to be Removed from S&P Mi...    S&P 400    Deletion   \n",
    468        "4   Harsco Corp. to be Removed from S&P MidCap 400...    S&P 400    Deletion   \n",
    469        "5   PetroQuest Energy to be Removed from S&P Small...    S&P 600    Deletion   \n",
    470        "6   Aeropostale to be Removed from S&P SmallCap 60...    S&P 600    Deletion   \n",
    471        "7   Unit Corp. to be Removed from S&P MidCap 400 I...    S&P 400    Deletion   \n",
    472        "8   Quiksilver to be Removed from S&P SmallCap 600...    S&P 600    Deletion   \n",
    473        "9      FXCM to be Removed from S&P SmallCap 600 Index    S&P 600    Deletion   \n",
    474        "10  J.B. Hunt Transport Services to be Removed fro...    S&P 400    Deletion   \n",
    475        "\n",
    476        "   change_reason  event_rating  timestamp    sid  \n",
    477        "0     Market Cap             1 2015-05-22  27019  \n",
    478        "1     Market Cap             1 2015-06-25  24840  \n",
    479        "2     Market Cap             1 2015-06-25   6961  \n",
    480        "3     Market Cap             1 2015-06-25  22660  \n",
    481        "4     Market Cap             1 2015-06-25   3686  \n",
    482        "5     Market Cap             1 2015-06-25  19326  \n",
    483        "6     Market Cap             1 2015-06-25  23650  \n",
    484        "7     Market Cap             1 2015-06-25   7806  \n",
    485        "8     Market Cap             1 2015-06-25   6317  \n",
    486        "9     Market Cap             1 2015-06-25  40531  \n",
    487        "..."
    488       ]
    489      },
    490      "execution_count": 5,
    491      "metadata": {},
    492      "output_type": "execute_result"
    493     }
    494    ],
    495    "source": [
    496     "deletions = index_changes[('2014-12-31' < index_changes['asof_date']) & \n",
    497     "                                        (index_changes['asof_date'] <'2016-01-01') & \n",
    498     "                                        (index_changes.change_type == \"Deletion\")&\n",
    499     "                                        (index_changes.change_reason  == \"Market Cap\")]\n",
    500     "# When displaying a Blaze Data Object, the printout is automatically truncated to ten rows.\n",
    501     "deletions.sort('asof_date')"
    502    ]
    503   },
    504   {
    505    "cell_type": "markdown",
    506    "metadata": {},
    507    "source": [
    508     "Now suppose we want a DataFrame of the Blaze Data Object above, want to filter it further down to the S&P 600, and we only want the sid and the asof_date."
    509    ]
    510   },
    511   {
    512    "cell_type": "code",
    513    "execution_count": 6,
    514    "metadata": {
    515     "collapsed": false
    516    },
    517    "outputs": [
    518     {
    519      "data": {
    520       "text/html": [
    521        "<div style=\"max-height:1000px;max-width:1500px;overflow:auto;\">\n",
    522        "<table border=\"1\" class=\"dataframe\">\n",
    523        "  <thead>\n",
    524        "    <tr style=\"text-align: right;\">\n",
    525        "      <th></th>\n",
    526        "      <th>sid</th>\n",
    527        "      <th>asof_date</th>\n",
    528        "    </tr>\n",
    529        "  </thead>\n",
    530        "  <tbody>\n",
    531        "    <tr>\n",
    532        "      <th>1</th>\n",
    533        "      <td>23650</td>\n",
    534        "      <td>2015-06-24</td>\n",
    535        "    </tr>\n",
    536        "    <tr>\n",
    537        "      <th>4</th>\n",
    538        "      <td>40531</td>\n",
    539        "      <td>2015-06-24</td>\n",
    540        "    </tr>\n",
    541        "    <tr>\n",
    542        "      <th>6</th>\n",
    543        "      <td>19326</td>\n",
    544        "      <td>2015-06-24</td>\n",
    545        "    </tr>\n",
    546        "    <tr>\n",
    547        "      <th>9</th>\n",
    548        "      <td>6317</td>\n",
    549        "      <td>2015-06-24</td>\n",
    550        "    </tr>\n",
    551        "    <tr>\n",
    552        "      <th>12</th>\n",
    553        "      <td>1308</td>\n",
    554        "      <td>2015-06-29</td>\n",
    555        "    </tr>\n",
    556        "    <tr>\n",
    557        "      <th>15</th>\n",
    558        "      <td>20740</td>\n",
    559        "      <td>2015-07-06</td>\n",
    560        "    </tr>\n",
    561        "    <tr>\n",
    562        "      <th>16</th>\n",
    563        "      <td>8291</td>\n",
    564        "      <td>2015-07-06</td>\n",
    565        "    </tr>\n",
    566        "    <tr>\n",
    567        "      <th>19</th>\n",
    568        "      <td>6825</td>\n",
    569        "      <td>2015-07-14</td>\n",
    570        "    </tr>\n",
    571        "    <tr>\n",
    572        "      <th>20</th>\n",
    573        "      <td>20526</td>\n",
    574        "      <td>2015-07-17</td>\n",
    575        "    </tr>\n",
    576        "    <tr>\n",
    577        "      <th>22</th>\n",
    578        "      <td>1263</td>\n",
    579        "      <td>2015-07-24</td>\n",
    580        "    </tr>\n",
    581        "    <tr>\n",
    582        "      <th>23</th>\n",
    583        "      <td>1663</td>\n",
    584        "      <td>2015-07-24</td>\n",
    585        "    </tr>\n",
    586        "    <tr>\n",
    587        "      <th>24</th>\n",
    588        "      <td>13918</td>\n",
    589        "      <td>2015-07-24</td>\n",
    590        "    </tr>\n",
    591        "    <tr>\n",
    592        "      <th>27</th>\n",
    593        "      <td>24823</td>\n",
    594        "      <td>2015-08-19</td>\n",
    595        "    </tr>\n",
    596        "    <tr>\n",
    597        "      <th>28</th>\n",
    598        "      <td>21736</td>\n",
    599        "      <td>2015-09-21</td>\n",
    600        "    </tr>\n",
    601        "  </tbody>\n",
    602        "</table>\n",
    603        "</div>"
    604       ],
    605       "text/plain": [
    606        "      sid  asof_date\n",
    607        "1   23650 2015-06-24\n",
    608        "4   40531 2015-06-24\n",
    609        "6   19326 2015-06-24\n",
    610        "9    6317 2015-06-24\n",
    611        "12   1308 2015-06-29\n",
    612        "15  20740 2015-07-06\n",
    613        "16   8291 2015-07-06\n",
    614        "19   6825 2015-07-14\n",
    615        "20  20526 2015-07-17\n",
    616        "22   1263 2015-07-24\n",
    617        "23   1663 2015-07-24\n",
    618        "24  13918 2015-07-24\n",
    619        "27  24823 2015-08-19\n",
    620        "28  21736 2015-09-21"
    621       ]
    622      },
    623      "execution_count": 6,
    624      "metadata": {},
    625      "output_type": "execute_result"
    626     }
    627    ],
    628    "source": [
    629     "df = odo(deletions, pd.DataFrame)\n",
    630     "df = df[df.index_name == \"S&P 600\"]\n",
    631     "df = df[['sid', 'asof_date']]\n",
    632     "df"
    633    ]
    634   }
    635  ],
    636  "metadata": {
    637   "kernelspec": {
    638    "display_name": "Python 2",
    639    "language": "python",
    640    "name": "python2"
    641   },
    642   "language_info": {
    643    "codemirror_mode": {
    644     "name": "ipython",
    645     "version": 2
    646    },
    647    "file_extension": ".py",
    648    "mimetype": "text/x-python",
    649    "name": "python",
    650    "nbconvert_exporter": "python",
    651    "pygments_lexer": "ipython2",
    652    "version": "2.7.10"
    653   }
    654  },
    655  "nbformat": 4,
    656  "nbformat_minor": 0
    657 }