ml-finance-python

python scripts for finance machine learning

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

notebook.ipynb

(52758B)


      1 {
      2  "cells": [
      3   {
      4    "cell_type": "code",
      5    "execution_count": 1,
      6    "metadata": {
      7     "collapsed": true
      8    },
      9    "outputs": [],
     10    "source": [
     11     "from quantopian.pipeline import Pipeline\n",
     12     "from quantopian.research import run_pipeline\n",
     13     "from quantopian.pipeline.data.builtin import USEquityPricing\n",
     14     "from quantopian.pipeline.factors import SimpleMovingAverage, AverageDollarVolume"
     15    ]
     16   },
     17   {
     18    "cell_type": "markdown",
     19    "metadata": {},
     20    "source": [
     21     "## Custom Factors\n",
     22     "When we first looked at factors, we explored the set of built-in factors. Frequently, a desired computation isn't included as a built-in factor. One of the most powerful features of the Pipeline API is that it allows us to define our own custom factors. When a desired computation doesn't exist as a built-in, we define a custom factor.\n",
     23     "\n",
     24     "Conceptually, a custom factor is identical to a built-in factor. It accepts `inputs`, `window_length`, and `mask` as constructor arguments, and returns a `Factor` object each day.\n",
     25     "\n",
     26     "Let's take an example of a computation that doesn't exist as a built-in: standard deviation. To create a factor that computes the [standard deviation](https://en.wikipedia.org/wiki/Standard_deviation) over a trailing window, we can subclass `quantopian.pipeline.CustomFactor` and implement a compute method whose signature is:\n",
     27     "\n",
     28     "\n",
     29     "```\n",
     30     "def compute(self, today, asset_ids, out, *inputs):\n",
     31     "    ...\n",
     32     "```\n",
     33     "\n",
     34     "- `*inputs` are M x N [numpy arrays](http://docs.scipy.org/doc/numpy-1.10.1/reference/arrays.ndarray.html), where M is the `window_length` and N is the number of securities (usually around ~8000 unless a `mask` is provided). `*inputs` are trailing data windows. Note that there will be one M x N array for each `BoundColumn` provided in the factor's `inputs` list. The data type of each array will be the `dtype` of the corresponding `BoundColumn`.\n",
     35     "- `out` is an empty array of length N. `out` will be the output of our custom factor each day. The job of compute is to write output values into out.\n",
     36     "- `asset_ids` will be an integer [array](http://docs.scipy.org/doc/numpy-1.10.0/reference/generated/numpy.array.html) of length N containing security ids corresponding to the columns in our `*inputs` arrays.\n",
     37     "- `today` will be a [pandas Timestamp](http://pandas.pydata.org/pandas-docs/stable/timeseries.html#converting-to-timestamps) representing the day for which `compute` is being called.\n",
     38     "\n",
     39     "Of these, `*inputs` and `out` are most commonly used.\n",
     40     "\n",
     41     "An instance of `CustomFactor` that’s been added to a pipeline will have its compute method called every day. For example, let's define a custom factor that computes the standard deviation of the close price over the last 5 days. To start, let's add `CustomFactor` and `numpy` to our import statements."
     42    ]
     43   },
     44   {
     45    "cell_type": "code",
     46    "execution_count": 2,
     47    "metadata": {
     48     "collapsed": true
     49    },
     50    "outputs": [],
     51    "source": [
     52     "from quantopian.pipeline import CustomFactor\n",
     53     "import numpy"
     54    ]
     55   },
     56   {
     57    "cell_type": "markdown",
     58    "metadata": {},
     59    "source": [
     60     "Next, let's define our custom factor to calculate the standard deviation over a trailing window using [numpy.nanstd](http://docs.scipy.org/doc/numpy-dev/reference/generated/numpy.nanstd.html):"
     61    ]
     62   },
     63   {
     64    "cell_type": "code",
     65    "execution_count": 3,
     66    "metadata": {
     67     "collapsed": false
     68    },
     69    "outputs": [],
     70    "source": [
     71     "class StdDev(CustomFactor):\n",
     72     "    def compute(self, today, asset_ids, out, values):\n",
     73     "        # Calculates the column-wise standard deviation, ignoring NaNs\n",
     74     "        out[:] = numpy.nanstd(values, axis=0)"
     75    ]
     76   },
     77   {
     78    "cell_type": "markdown",
     79    "metadata": {},
     80    "source": [
     81     "Finally, let's instantiate our factor in `make_pipeline()`:"
     82    ]
     83   },
     84   {
     85    "cell_type": "code",
     86    "execution_count": 4,
     87    "metadata": {
     88     "collapsed": true
     89    },
     90    "outputs": [],
     91    "source": [
     92     "def make_pipeline():\n",
     93     "    std_dev = StdDev(inputs=[USEquityPricing.close], window_length=5)\n",
     94     "\n",
     95     "    return Pipeline(\n",
     96     "        columns={\n",
     97     "            'std_dev': std_dev\n",
     98     "        }\n",
     99     "    )"
    100    ]
    101   },
    102   {
    103    "cell_type": "markdown",
    104    "metadata": {},
    105    "source": [
    106     "When this pipeline is run, `StdDev.compute()` will be called every day with data as follows:\n",
    107     "\n",
    108     "- `values`: An M x N [numpy array](http://docs.scipy.org/doc/numpy-1.10.1/reference/arrays.ndarray.html), where M is 5 (`window_length`), and N is ~8000 (the number of securities in our database on the day in question).\n",
    109     "- `out`: An empty array of length N (~8000). In this example, the job of `compute` is to populate `out` with an array storing of 5-day close price standard deviations."
    110    ]
    111   },
    112   {
    113    "cell_type": "code",
    114    "execution_count": 5,
    115    "metadata": {
    116     "collapsed": false
    117    },
    118    "outputs": [
    119     {
    120      "name": "stderr",
    121      "output_type": "stream",
    122      "text": [
    123       "/usr/local/lib/python2.7/dist-packages/numpy/lib/nanfunctions.py:1057: RuntimeWarning: Degrees of freedom <= 0 for slice.\n",
    124       "  warnings.warn(\"Degrees of freedom <= 0 for slice.\", RuntimeWarning)\n"
    125      ]
    126     },
    127     {
    128      "data": {
    129       "text/html": [
    130        "<div style=\"max-height: 1000px; max-width: 1500px; overflow: auto;\">\n",
    131        "<table border=\"1\" class=\"dataframe\">\n",
    132        "  <thead>\n",
    133        "    <tr style=\"text-align: right;\">\n",
    134        "      <th></th>\n",
    135        "      <th></th>\n",
    136        "      <th>std_dev</th>\n",
    137        "    </tr>\n",
    138        "  </thead>\n",
    139        "  <tbody>\n",
    140        "    <tr>\n",
    141        "      <th rowspan=\"61\" valign=\"top\">2015-05-05 00:00:00+00:00</th>\n",
    142        "      <th>Equity(2 [AA])</th>\n",
    143        "      <td>0.293428</td>\n",
    144        "    </tr>\n",
    145        "    <tr>\n",
    146        "      <th>Equity(21 [AAME])</th>\n",
    147        "      <td>0.004714</td>\n",
    148        "    </tr>\n",
    149        "    <tr>\n",
    150        "      <th>Equity(24 [AAPL])</th>\n",
    151        "      <td>1.737677</td>\n",
    152        "    </tr>\n",
    153        "    <tr>\n",
    154        "      <th>Equity(25 [AA_PR])</th>\n",
    155        "      <td>0.275000</td>\n",
    156        "    </tr>\n",
    157        "    <tr>\n",
    158        "      <th>Equity(31 [ABAX])</th>\n",
    159        "      <td>4.402971</td>\n",
    160        "    </tr>\n",
    161        "    <tr>\n",
    162        "      <th>Equity(39 [DDC])</th>\n",
    163        "      <td>0.138939</td>\n",
    164        "    </tr>\n",
    165        "    <tr>\n",
    166        "      <th>Equity(41 [ARCB])</th>\n",
    167        "      <td>0.826109</td>\n",
    168        "    </tr>\n",
    169        "    <tr>\n",
    170        "      <th>Equity(52 [ABM])</th>\n",
    171        "      <td>0.093680</td>\n",
    172        "    </tr>\n",
    173        "    <tr>\n",
    174        "      <th>Equity(53 [ABMD])</th>\n",
    175        "      <td>1.293058</td>\n",
    176        "    </tr>\n",
    177        "    <tr>\n",
    178        "      <th>Equity(62 [ABT])</th>\n",
    179        "      <td>0.406546</td>\n",
    180        "    </tr>\n",
    181        "    <tr>\n",
    182        "      <th>Equity(64 [ABX])</th>\n",
    183        "      <td>0.178034</td>\n",
    184        "    </tr>\n",
    185        "    <tr>\n",
    186        "      <th>Equity(66 [AB])</th>\n",
    187        "      <td>0.510427</td>\n",
    188        "    </tr>\n",
    189        "    <tr>\n",
    190        "      <th>Equity(67 [ADSK])</th>\n",
    191        "      <td>1.405754</td>\n",
    192        "    </tr>\n",
    193        "    <tr>\n",
    194        "      <th>Equity(69 [ACAT])</th>\n",
    195        "      <td>0.561413</td>\n",
    196        "    </tr>\n",
    197        "    <tr>\n",
    198        "      <th>Equity(70 [VBF])</th>\n",
    199        "      <td>0.054626</td>\n",
    200        "    </tr>\n",
    201        "    <tr>\n",
    202        "      <th>Equity(76 [TAP])</th>\n",
    203        "      <td>0.411757</td>\n",
    204        "    </tr>\n",
    205        "    <tr>\n",
    206        "      <th>Equity(84 [ACET])</th>\n",
    207        "      <td>0.320624</td>\n",
    208        "    </tr>\n",
    209        "    <tr>\n",
    210        "      <th>Equity(86 [ACG])</th>\n",
    211        "      <td>0.012806</td>\n",
    212        "    </tr>\n",
    213        "    <tr>\n",
    214        "      <th>Equity(88 [ACI])</th>\n",
    215        "      <td>0.026447</td>\n",
    216        "    </tr>\n",
    217        "    <tr>\n",
    218        "      <th>Equity(100 [IEP])</th>\n",
    219        "      <td>0.444189</td>\n",
    220        "    </tr>\n",
    221        "    <tr>\n",
    222        "      <th>Equity(106 [ACU])</th>\n",
    223        "      <td>0.060531</td>\n",
    224        "    </tr>\n",
    225        "    <tr>\n",
    226        "      <th>Equity(110 [ACXM])</th>\n",
    227        "      <td>0.485444</td>\n",
    228        "    </tr>\n",
    229        "    <tr>\n",
    230        "      <th>Equity(112 [ACY])</th>\n",
    231        "      <td>0.207107</td>\n",
    232        "    </tr>\n",
    233        "    <tr>\n",
    234        "      <th>Equity(114 [ADBE])</th>\n",
    235        "      <td>0.280385</td>\n",
    236        "    </tr>\n",
    237        "    <tr>\n",
    238        "      <th>Equity(117 [AEY])</th>\n",
    239        "      <td>0.022471</td>\n",
    240        "    </tr>\n",
    241        "    <tr>\n",
    242        "      <th>Equity(122 [ADI])</th>\n",
    243        "      <td>0.549778</td>\n",
    244        "    </tr>\n",
    245        "    <tr>\n",
    246        "      <th>Equity(128 [ADM])</th>\n",
    247        "      <td>0.605495</td>\n",
    248        "    </tr>\n",
    249        "    <tr>\n",
    250        "      <th>Equity(134 [SXCL])</th>\n",
    251        "      <td>NaN</td>\n",
    252        "    </tr>\n",
    253        "    <tr>\n",
    254        "      <th>Equity(149 [ADX])</th>\n",
    255        "      <td>0.072153</td>\n",
    256        "    </tr>\n",
    257        "    <tr>\n",
    258        "      <th>Equity(153 [AE])</th>\n",
    259        "      <td>3.676240</td>\n",
    260        "    </tr>\n",
    261        "    <tr>\n",
    262        "      <th>...</th>\n",
    263        "      <td>...</td>\n",
    264        "    </tr>\n",
    265        "    <tr>\n",
    266        "      <th>Equity(48961 [NYMT_O])</th>\n",
    267        "      <td>NaN</td>\n",
    268        "    </tr>\n",
    269        "    <tr>\n",
    270        "      <th>Equity(48962 [CSAL])</th>\n",
    271        "      <td>0.285755</td>\n",
    272        "    </tr>\n",
    273        "    <tr>\n",
    274        "      <th>Equity(48963 [PAK])</th>\n",
    275        "      <td>0.034871</td>\n",
    276        "    </tr>\n",
    277        "    <tr>\n",
    278        "      <th>Equity(48969 [NSA])</th>\n",
    279        "      <td>0.144305</td>\n",
    280        "    </tr>\n",
    281        "    <tr>\n",
    282        "      <th>Equity(48971 [BSM])</th>\n",
    283        "      <td>0.245000</td>\n",
    284        "    </tr>\n",
    285        "    <tr>\n",
    286        "      <th>Equity(48972 [EVA])</th>\n",
    287        "      <td>0.207175</td>\n",
    288        "    </tr>\n",
    289        "    <tr>\n",
    290        "      <th>Equity(48981 [APIC])</th>\n",
    291        "      <td>0.364560</td>\n",
    292        "    </tr>\n",
    293        "    <tr>\n",
    294        "      <th>Equity(48989 [UK])</th>\n",
    295        "      <td>0.148399</td>\n",
    296        "    </tr>\n",
    297        "    <tr>\n",
    298        "      <th>Equity(48990 [ACWF])</th>\n",
    299        "      <td>0.000000</td>\n",
    300        "    </tr>\n",
    301        "    <tr>\n",
    302        "      <th>Equity(48991 [ISCF])</th>\n",
    303        "      <td>0.035000</td>\n",
    304        "    </tr>\n",
    305        "    <tr>\n",
    306        "      <th>Equity(48992 [INTF])</th>\n",
    307        "      <td>0.000000</td>\n",
    308        "    </tr>\n",
    309        "    <tr>\n",
    310        "      <th>Equity(48993 [JETS])</th>\n",
    311        "      <td>0.294937</td>\n",
    312        "    </tr>\n",
    313        "    <tr>\n",
    314        "      <th>Equity(48994 [ACTX])</th>\n",
    315        "      <td>0.091365</td>\n",
    316        "    </tr>\n",
    317        "    <tr>\n",
    318        "      <th>Equity(48995 [LRGF])</th>\n",
    319        "      <td>0.172047</td>\n",
    320        "    </tr>\n",
    321        "    <tr>\n",
    322        "      <th>Equity(48996 [SMLF])</th>\n",
    323        "      <td>0.245130</td>\n",
    324        "    </tr>\n",
    325        "    <tr>\n",
    326        "      <th>Equity(48997 [VKTX])</th>\n",
    327        "      <td>0.065000</td>\n",
    328        "    </tr>\n",
    329        "    <tr>\n",
    330        "      <th>Equity(48998 [OPGN])</th>\n",
    331        "      <td>NaN</td>\n",
    332        "    </tr>\n",
    333        "    <tr>\n",
    334        "      <th>Equity(48999 [AAPC])</th>\n",
    335        "      <td>0.000000</td>\n",
    336        "    </tr>\n",
    337        "    <tr>\n",
    338        "      <th>Equity(49000 [BPMC])</th>\n",
    339        "      <td>0.000000</td>\n",
    340        "    </tr>\n",
    341        "    <tr>\n",
    342        "      <th>Equity(49001 [CLCD])</th>\n",
    343        "      <td>NaN</td>\n",
    344        "    </tr>\n",
    345        "    <tr>\n",
    346        "      <th>Equity(49004 [TNP_PRD])</th>\n",
    347        "      <td>0.000000</td>\n",
    348        "    </tr>\n",
    349        "    <tr>\n",
    350        "      <th>Equity(49005 [ARWA_U])</th>\n",
    351        "      <td>NaN</td>\n",
    352        "    </tr>\n",
    353        "    <tr>\n",
    354        "      <th>Equity(49006 [BVXV])</th>\n",
    355        "      <td>NaN</td>\n",
    356        "    </tr>\n",
    357        "    <tr>\n",
    358        "      <th>Equity(49007 [BVXV_W])</th>\n",
    359        "      <td>NaN</td>\n",
    360        "    </tr>\n",
    361        "    <tr>\n",
    362        "      <th>Equity(49008 [OPGN_W])</th>\n",
    363        "      <td>NaN</td>\n",
    364        "    </tr>\n",
    365        "    <tr>\n",
    366        "      <th>Equity(49009 [PRKU])</th>\n",
    367        "      <td>NaN</td>\n",
    368        "    </tr>\n",
    369        "    <tr>\n",
    370        "      <th>Equity(49010 [TBRA])</th>\n",
    371        "      <td>NaN</td>\n",
    372        "    </tr>\n",
    373        "    <tr>\n",
    374        "      <th>Equity(49131 [OESX])</th>\n",
    375        "      <td>NaN</td>\n",
    376        "    </tr>\n",
    377        "    <tr>\n",
    378        "      <th>Equity(49259 [ITUS])</th>\n",
    379        "      <td>NaN</td>\n",
    380        "    </tr>\n",
    381        "    <tr>\n",
    382        "      <th>Equity(49523 [TLGT])</th>\n",
    383        "      <td>NaN</td>\n",
    384        "    </tr>\n",
    385        "  </tbody>\n",
    386        "</table>\n",
    387        "<p>8236 rows × 1 columns</p>\n",
    388        "</div>"
    389       ],
    390       "text/plain": [
    391        "                                                    std_dev\n",
    392        "2015-05-05 00:00:00+00:00 Equity(2 [AA])           0.293428\n",
    393        "                          Equity(21 [AAME])        0.004714\n",
    394        "                          Equity(24 [AAPL])        1.737677\n",
    395        "                          Equity(25 [AA_PR])       0.275000\n",
    396        "                          Equity(31 [ABAX])        4.402971\n",
    397        "                          Equity(39 [DDC])         0.138939\n",
    398        "                          Equity(41 [ARCB])        0.826109\n",
    399        "                          Equity(52 [ABM])         0.093680\n",
    400        "                          Equity(53 [ABMD])        1.293058\n",
    401        "                          Equity(62 [ABT])         0.406546\n",
    402        "                          Equity(64 [ABX])         0.178034\n",
    403        "                          Equity(66 [AB])          0.510427\n",
    404        "                          Equity(67 [ADSK])        1.405754\n",
    405        "                          Equity(69 [ACAT])        0.561413\n",
    406        "                          Equity(70 [VBF])         0.054626\n",
    407        "                          Equity(76 [TAP])         0.411757\n",
    408        "                          Equity(84 [ACET])        0.320624\n",
    409        "                          Equity(86 [ACG])         0.012806\n",
    410        "                          Equity(88 [ACI])         0.026447\n",
    411        "                          Equity(100 [IEP])        0.444189\n",
    412        "                          Equity(106 [ACU])        0.060531\n",
    413        "                          Equity(110 [ACXM])       0.485444\n",
    414        "                          Equity(112 [ACY])        0.207107\n",
    415        "                          Equity(114 [ADBE])       0.280385\n",
    416        "                          Equity(117 [AEY])        0.022471\n",
    417        "                          Equity(122 [ADI])        0.549778\n",
    418        "                          Equity(128 [ADM])        0.605495\n",
    419        "                          Equity(134 [SXCL])            NaN\n",
    420        "                          Equity(149 [ADX])        0.072153\n",
    421        "                          Equity(153 [AE])         3.676240\n",
    422        "...                                                     ...\n",
    423        "                          Equity(48961 [NYMT_O])        NaN\n",
    424        "                          Equity(48962 [CSAL])     0.285755\n",
    425        "                          Equity(48963 [PAK])      0.034871\n",
    426        "                          Equity(48969 [NSA])      0.144305\n",
    427        "                          Equity(48971 [BSM])      0.245000\n",
    428        "                          Equity(48972 [EVA])      0.207175\n",
    429        "                          Equity(48981 [APIC])     0.364560\n",
    430        "                          Equity(48989 [UK])       0.148399\n",
    431        "                          Equity(48990 [ACWF])     0.000000\n",
    432        "                          Equity(48991 [ISCF])     0.035000\n",
    433        "                          Equity(48992 [INTF])     0.000000\n",
    434        "                          Equity(48993 [JETS])     0.294937\n",
    435        "                          Equity(48994 [ACTX])     0.091365\n",
    436        "                          Equity(48995 [LRGF])     0.172047\n",
    437        "                          Equity(48996 [SMLF])     0.245130\n",
    438        "                          Equity(48997 [VKTX])     0.065000\n",
    439        "                          Equity(48998 [OPGN])          NaN\n",
    440        "                          Equity(48999 [AAPC])     0.000000\n",
    441        "                          Equity(49000 [BPMC])     0.000000\n",
    442        "                          Equity(49001 [CLCD])          NaN\n",
    443        "                          Equity(49004 [TNP_PRD])  0.000000\n",
    444        "                          Equity(49005 [ARWA_U])        NaN\n",
    445        "                          Equity(49006 [BVXV])          NaN\n",
    446        "                          Equity(49007 [BVXV_W])        NaN\n",
    447        "                          Equity(49008 [OPGN_W])        NaN\n",
    448        "                          Equity(49009 [PRKU])          NaN\n",
    449        "                          Equity(49010 [TBRA])          NaN\n",
    450        "                          Equity(49131 [OESX])          NaN\n",
    451        "                          Equity(49259 [ITUS])          NaN\n",
    452        "                          Equity(49523 [TLGT])          NaN\n",
    453        "\n",
    454        "[8236 rows x 1 columns]"
    455       ]
    456      },
    457      "execution_count": 5,
    458      "metadata": {},
    459      "output_type": "execute_result"
    460     }
    461    ],
    462    "source": [
    463     "result = run_pipeline(make_pipeline(), '2015-05-05', '2015-05-05')\n",
    464     "result"
    465    ]
    466   },
    467   {
    468    "cell_type": "markdown",
    469    "metadata": {},
    470    "source": [
    471     "### Default Inputs\n",
    472     "When writing a custom factor, we can set default `inputs` and `window_length` in our `CustomFactor` subclass. For example, let's define the `TenDayMeanDifference` custom factor to compute the mean difference between two data columns over a trailing window using [numpy.nanmean](http://docs.scipy.org/doc/numpy-dev/reference/generated/numpy.nanmean.html). Let's set the default `inputs` to `[USEquityPricing.close, USEquityPricing.open]` and the default `window_length` to 10:"
    473    ]
    474   },
    475   {
    476    "cell_type": "code",
    477    "execution_count": 6,
    478    "metadata": {
    479     "collapsed": true
    480    },
    481    "outputs": [],
    482    "source": [
    483     "class TenDayMeanDifference(CustomFactor):\n",
    484     "    # Default inputs.\n",
    485     "    inputs = [USEquityPricing.close, USEquityPricing.open]\n",
    486     "    window_length = 10\n",
    487     "    def compute(self, today, asset_ids, out, close, open):\n",
    488     "        # Calculates the column-wise mean difference, ignoring NaNs\n",
    489     "        out[:] = numpy.nanmean(close - open, axis=0)"
    490    ]
    491   },
    492   {
    493    "cell_type": "markdown",
    494    "metadata": {},
    495    "source": [
    496     "<i>Remember in this case that `close` and `open` are each 10 x ~8000 2D [numpy arrays.](http://docs.scipy.org/doc/numpy-1.10.1/reference/arrays.ndarray.html)</i>\n",
    497     "\n",
    498     "If we call `TenDayMeanDifference` without providing any arguments, it will use the defaults."
    499    ]
    500   },
    501   {
    502    "cell_type": "code",
    503    "execution_count": 7,
    504    "metadata": {
    505     "collapsed": true
    506    },
    507    "outputs": [],
    508    "source": [
    509     "# Computes the 10-day mean difference between the daily open and close prices.\n",
    510     "close_open_diff = TenDayMeanDifference()"
    511    ]
    512   },
    513   {
    514    "cell_type": "markdown",
    515    "metadata": {},
    516    "source": [
    517     "The defaults can be manually overridden by specifying arguments in the constructor call."
    518    ]
    519   },
    520   {
    521    "cell_type": "code",
    522    "execution_count": 8,
    523    "metadata": {
    524     "collapsed": true
    525    },
    526    "outputs": [],
    527    "source": [
    528     "# Computes the 10-day mean difference between the daily high and low prices.\n",
    529     "high_low_diff = TenDayMeanDifference(inputs=[USEquityPricing.high, USEquityPricing.low])"
    530    ]
    531   },
    532   {
    533    "cell_type": "markdown",
    534    "metadata": {},
    535    "source": [
    536     "### Further Example\n",
    537     "Let's take another example where we build a [momentum](http://www.investopedia.com/terms/m/momentum.asp) custom factor and use it to create a filter. We will then use that filter as a `screen` for our pipeline.\n",
    538     "\n",
    539     "Let's start by defining a `Momentum` factor to be the division of the most recent close price by the close price from `n` days ago where `n` is the `window_length`."
    540    ]
    541   },
    542   {
    543    "cell_type": "code",
    544    "execution_count": 9,
    545    "metadata": {
    546     "collapsed": true
    547    },
    548    "outputs": [],
    549    "source": [
    550     "class Momentum(CustomFactor):\n",
    551     "    # Default inputs\n",
    552     "    inputs = [USEquityPricing.close]\n",
    553     "\n",
    554     "    # Compute momentum\n",
    555     "    def compute(self, today, assets, out, close):\n",
    556     "        out[:] = close[-1] / close[0]"
    557    ]
    558   },
    559   {
    560    "cell_type": "markdown",
    561    "metadata": {},
    562    "source": [
    563     "Now, let's instantiate our `Momentum` factor (twice) to create a 10-day momentum factor and a 20-day momentum factor. Let's also create a `positive_momentum` filter returning `True` for securities with both a positive 10-day momentum and a positive 20-day momentum."
    564    ]
    565   },
    566   {
    567    "cell_type": "code",
    568    "execution_count": 10,
    569    "metadata": {
    570     "collapsed": false
    571    },
    572    "outputs": [],
    573    "source": [
    574     "ten_day_momentum = Momentum(window_length=10)\n",
    575     "twenty_day_momentum = Momentum(window_length=20)\n",
    576     "\n",
    577     "positive_momentum = ((ten_day_momentum > 1) & (twenty_day_momentum > 1))"
    578    ]
    579   },
    580   {
    581    "cell_type": "markdown",
    582    "metadata": {},
    583    "source": [
    584     "Next, let's add our momentum factors and our `positive_momentum` filter to `make_pipeline`. Let's also pass `positive_momentum` as a `screen` to our pipeline."
    585    ]
    586   },
    587   {
    588    "cell_type": "code",
    589    "execution_count": 11,
    590    "metadata": {
    591     "collapsed": false
    592    },
    593    "outputs": [],
    594    "source": [
    595     "def make_pipeline():\n",
    596     "\n",
    597     "    ten_day_momentum = Momentum(window_length=10)\n",
    598     "    twenty_day_momentum = Momentum(window_length=20)\n",
    599     "\n",
    600     "    positive_momentum = ((ten_day_momentum > 1) & (twenty_day_momentum > 1))\n",
    601     "\n",
    602     "    std_dev = StdDev(inputs=[USEquityPricing.close], window_length=5)\n",
    603     "\n",
    604     "    return Pipeline(\n",
    605     "        columns={\n",
    606     "            'std_dev': std_dev,\n",
    607     "            'ten_day_momentum': ten_day_momentum,\n",
    608     "            'twenty_day_momentum': twenty_day_momentum\n",
    609     "        },\n",
    610     "        screen=positive_momentum\n",
    611     "    )"
    612    ]
    613   },
    614   {
    615    "cell_type": "markdown",
    616    "metadata": {},
    617    "source": [
    618     "Running this pipeline outputs the standard deviation and each of our momentum computations for securities with positive 10-day and 20-day momentum."
    619    ]
    620   },
    621   {
    622    "cell_type": "code",
    623    "execution_count": 12,
    624    "metadata": {
    625     "collapsed": false
    626    },
    627    "outputs": [
    628     {
    629      "data": {
    630       "text/html": [
    631        "<div style=\"max-height: 1000px; max-width: 1500px; overflow: auto;\">\n",
    632        "<table border=\"1\" class=\"dataframe\">\n",
    633        "  <thead>\n",
    634        "    <tr style=\"text-align: right;\">\n",
    635        "      <th></th>\n",
    636        "      <th></th>\n",
    637        "      <th>std_dev</th>\n",
    638        "      <th>ten_day_momentum</th>\n",
    639        "      <th>twenty_day_momentum</th>\n",
    640        "    </tr>\n",
    641        "  </thead>\n",
    642        "  <tbody>\n",
    643        "    <tr>\n",
    644        "      <th rowspan=\"61\" valign=\"top\">2015-05-05 00:00:00+00:00</th>\n",
    645        "      <th>Equity(2 [AA])</th>\n",
    646        "      <td>0.293428</td>\n",
    647        "      <td>1.036612</td>\n",
    648        "      <td>1.042783</td>\n",
    649        "    </tr>\n",
    650        "    <tr>\n",
    651        "      <th>Equity(24 [AAPL])</th>\n",
    652        "      <td>1.737677</td>\n",
    653        "      <td>1.014256</td>\n",
    654        "      <td>1.021380</td>\n",
    655        "    </tr>\n",
    656        "    <tr>\n",
    657        "      <th>Equity(39 [DDC])</th>\n",
    658        "      <td>0.138939</td>\n",
    659        "      <td>1.062261</td>\n",
    660        "      <td>1.167319</td>\n",
    661        "    </tr>\n",
    662        "    <tr>\n",
    663        "      <th>Equity(52 [ABM])</th>\n",
    664        "      <td>0.093680</td>\n",
    665        "      <td>1.009212</td>\n",
    666        "      <td>1.015075</td>\n",
    667        "    </tr>\n",
    668        "    <tr>\n",
    669        "      <th>Equity(64 [ABX])</th>\n",
    670        "      <td>0.178034</td>\n",
    671        "      <td>1.025721</td>\n",
    672        "      <td>1.065587</td>\n",
    673        "    </tr>\n",
    674        "    <tr>\n",
    675        "      <th>Equity(66 [AB])</th>\n",
    676        "      <td>0.510427</td>\n",
    677        "      <td>1.036137</td>\n",
    678        "      <td>1.067545</td>\n",
    679        "    </tr>\n",
    680        "    <tr>\n",
    681        "      <th>Equity(100 [IEP])</th>\n",
    682        "      <td>0.444189</td>\n",
    683        "      <td>1.008820</td>\n",
    684        "      <td>1.011385</td>\n",
    685        "    </tr>\n",
    686        "    <tr>\n",
    687        "      <th>Equity(114 [ADBE])</th>\n",
    688        "      <td>0.280385</td>\n",
    689        "      <td>1.016618</td>\n",
    690        "      <td>1.002909</td>\n",
    691        "    </tr>\n",
    692        "    <tr>\n",
    693        "      <th>Equity(117 [AEY])</th>\n",
    694        "      <td>0.022471</td>\n",
    695        "      <td>1.004167</td>\n",
    696        "      <td>1.025532</td>\n",
    697        "    </tr>\n",
    698        "    <tr>\n",
    699        "      <th>Equity(128 [ADM])</th>\n",
    700        "      <td>0.605495</td>\n",
    701        "      <td>1.049625</td>\n",
    702        "      <td>1.044832</td>\n",
    703        "    </tr>\n",
    704        "    <tr>\n",
    705        "      <th>Equity(149 [ADX])</th>\n",
    706        "      <td>0.072153</td>\n",
    707        "      <td>1.004607</td>\n",
    708        "      <td>1.016129</td>\n",
    709        "    </tr>\n",
    710        "    <tr>\n",
    711        "      <th>Equity(154 [AEM])</th>\n",
    712        "      <td>0.634920</td>\n",
    713        "      <td>1.032690</td>\n",
    714        "      <td>1.065071</td>\n",
    715        "    </tr>\n",
    716        "    <tr>\n",
    717        "      <th>Equity(161 [AEP])</th>\n",
    718        "      <td>0.458938</td>\n",
    719        "      <td>1.024926</td>\n",
    720        "      <td>1.017563</td>\n",
    721        "    </tr>\n",
    722        "    <tr>\n",
    723        "      <th>Equity(166 [AES])</th>\n",
    724        "      <td>0.164973</td>\n",
    725        "      <td>1.031037</td>\n",
    726        "      <td>1.045946</td>\n",
    727        "    </tr>\n",
    728        "    <tr>\n",
    729        "      <th>Equity(168 [AET])</th>\n",
    730        "      <td>1.166938</td>\n",
    731        "      <td>1.007566</td>\n",
    732        "      <td>1.022472</td>\n",
    733        "    </tr>\n",
    734        "    <tr>\n",
    735        "      <th>Equity(192 [ATAX])</th>\n",
    736        "      <td>0.024819</td>\n",
    737        "      <td>1.009025</td>\n",
    738        "      <td>1.018215</td>\n",
    739        "    </tr>\n",
    740        "    <tr>\n",
    741        "      <th>Equity(197 [AGCO])</th>\n",
    742        "      <td>0.646594</td>\n",
    743        "      <td>1.066522</td>\n",
    744        "      <td>1.098572</td>\n",
    745        "    </tr>\n",
    746        "    <tr>\n",
    747        "      <th>Equity(239 [AIG])</th>\n",
    748        "      <td>0.710307</td>\n",
    749        "      <td>1.027189</td>\n",
    750        "      <td>1.058588</td>\n",
    751        "    </tr>\n",
    752        "    <tr>\n",
    753        "      <th>Equity(253 [AIR])</th>\n",
    754        "      <td>0.156844</td>\n",
    755        "      <td>1.007474</td>\n",
    756        "      <td>1.003818</td>\n",
    757        "    </tr>\n",
    758        "    <tr>\n",
    759        "      <th>Equity(266 [AJG])</th>\n",
    760        "      <td>0.397769</td>\n",
    761        "      <td>1.000839</td>\n",
    762        "      <td>1.018799</td>\n",
    763        "    </tr>\n",
    764        "    <tr>\n",
    765        "      <th>Equity(312 [ALOT])</th>\n",
    766        "      <td>0.182893</td>\n",
    767        "      <td>1.031780</td>\n",
    768        "      <td>1.021352</td>\n",
    769        "    </tr>\n",
    770        "    <tr>\n",
    771        "      <th>Equity(328 [ALTR])</th>\n",
    772        "      <td>2.286573</td>\n",
    773        "      <td>1.041397</td>\n",
    774        "      <td>1.088996</td>\n",
    775        "    </tr>\n",
    776        "    <tr>\n",
    777        "      <th>Equity(353 [AME])</th>\n",
    778        "      <td>0.362513</td>\n",
    779        "      <td>1.023622</td>\n",
    780        "      <td>1.004902</td>\n",
    781        "    </tr>\n",
    782        "    <tr>\n",
    783        "      <th>Equity(357 [TWX])</th>\n",
    784        "      <td>0.502816</td>\n",
    785        "      <td>1.022013</td>\n",
    786        "      <td>1.006976</td>\n",
    787        "    </tr>\n",
    788        "    <tr>\n",
    789        "      <th>Equity(366 [AVD])</th>\n",
    790        "      <td>0.842249</td>\n",
    791        "      <td>1.114111</td>\n",
    792        "      <td>1.093162</td>\n",
    793        "    </tr>\n",
    794        "    <tr>\n",
    795        "      <th>Equity(438 [AON])</th>\n",
    796        "      <td>0.881295</td>\n",
    797        "      <td>1.020732</td>\n",
    798        "      <td>1.018739</td>\n",
    799        "    </tr>\n",
    800        "    <tr>\n",
    801        "      <th>Equity(448 [APA])</th>\n",
    802        "      <td>0.678899</td>\n",
    803        "      <td>1.002193</td>\n",
    804        "      <td>1.051258</td>\n",
    805        "    </tr>\n",
    806        "    <tr>\n",
    807        "      <th>Equity(451 [APB])</th>\n",
    808        "      <td>0.081240</td>\n",
    809        "      <td>1.026542</td>\n",
    810        "      <td>1.105042</td>\n",
    811        "    </tr>\n",
    812        "    <tr>\n",
    813        "      <th>Equity(455 [APC])</th>\n",
    814        "      <td>0.152394</td>\n",
    815        "      <td>1.012312</td>\n",
    816        "      <td>1.097284</td>\n",
    817        "    </tr>\n",
    818        "    <tr>\n",
    819        "      <th>Equity(474 [APOG])</th>\n",
    820        "      <td>0.610410</td>\n",
    821        "      <td>1.030843</td>\n",
    822        "      <td>1.206232</td>\n",
    823        "    </tr>\n",
    824        "    <tr>\n",
    825        "      <th>...</th>\n",
    826        "      <td>...</td>\n",
    827        "      <td>...</td>\n",
    828        "      <td>...</td>\n",
    829        "    </tr>\n",
    830        "    <tr>\n",
    831        "      <th>Equity(48504 [ERUS])</th>\n",
    832        "      <td>0.052688</td>\n",
    833        "      <td>1.030893</td>\n",
    834        "      <td>1.052812</td>\n",
    835        "    </tr>\n",
    836        "    <tr>\n",
    837        "      <th>Equity(48531 [VSTO])</th>\n",
    838        "      <td>0.513443</td>\n",
    839        "      <td>1.029164</td>\n",
    840        "      <td>1.028110</td>\n",
    841        "    </tr>\n",
    842        "    <tr>\n",
    843        "      <th>Equity(48532 [ENTL])</th>\n",
    844        "      <td>0.163756</td>\n",
    845        "      <td>1.043708</td>\n",
    846        "      <td>1.152246</td>\n",
    847        "    </tr>\n",
    848        "    <tr>\n",
    849        "      <th>Equity(48535 [ANH_PRC])</th>\n",
    850        "      <td>0.072388</td>\n",
    851        "      <td>1.010656</td>\n",
    852        "      <td>1.010656</td>\n",
    853        "    </tr>\n",
    854        "    <tr>\n",
    855        "      <th>Equity(48543 [SHAK])</th>\n",
    856        "      <td>2.705316</td>\n",
    857        "      <td>1.262727</td>\n",
    858        "      <td>1.498020</td>\n",
    859        "    </tr>\n",
    860        "    <tr>\n",
    861        "      <th>Equity(48591 [SPYB])</th>\n",
    862        "      <td>0.221848</td>\n",
    863        "      <td>1.001279</td>\n",
    864        "      <td>1.005801</td>\n",
    865        "    </tr>\n",
    866        "    <tr>\n",
    867        "      <th>Equity(48602 [ITEK])</th>\n",
    868        "      <td>0.177042</td>\n",
    869        "      <td>1.213693</td>\n",
    870        "      <td>1.133721</td>\n",
    871        "    </tr>\n",
    872        "    <tr>\n",
    873        "      <th>Equity(48623 [TCCB])</th>\n",
    874        "      <td>0.056148</td>\n",
    875        "      <td>1.003641</td>\n",
    876        "      <td>1.006349</td>\n",
    877        "    </tr>\n",
    878        "    <tr>\n",
    879        "      <th>Equity(48641 [GDJJ])</th>\n",
    880        "      <td>0.530298</td>\n",
    881        "      <td>1.041176</td>\n",
    882        "      <td>1.111809</td>\n",
    883        "    </tr>\n",
    884        "    <tr>\n",
    885        "      <th>Equity(48644 [GDXX])</th>\n",
    886        "      <td>0.401079</td>\n",
    887        "      <td>1.042319</td>\n",
    888        "      <td>1.120948</td>\n",
    889        "    </tr>\n",
    890        "    <tr>\n",
    891        "      <th>Equity(48680 [RODM])</th>\n",
    892        "      <td>0.080455</td>\n",
    893        "      <td>1.005037</td>\n",
    894        "      <td>1.018853</td>\n",
    895        "    </tr>\n",
    896        "    <tr>\n",
    897        "      <th>Equity(48688 [QVM])</th>\n",
    898        "      <td>0.152245</td>\n",
    899        "      <td>1.009996</td>\n",
    900        "      <td>1.021845</td>\n",
    901        "    </tr>\n",
    902        "    <tr>\n",
    903        "      <th>Equity(48701 [AMT_PRB])</th>\n",
    904        "      <td>0.546691</td>\n",
    905        "      <td>1.010356</td>\n",
    906        "      <td>1.023537</td>\n",
    907        "    </tr>\n",
    908        "    <tr>\n",
    909        "      <th>Equity(48706 [GBSN_U])</th>\n",
    910        "      <td>0.442285</td>\n",
    911        "      <td>1.214035</td>\n",
    912        "      <td>1.272059</td>\n",
    913        "    </tr>\n",
    914        "    <tr>\n",
    915        "      <th>Equity(48730 [AGN_PRA])</th>\n",
    916        "      <td>9.614542</td>\n",
    917        "      <td>1.000948</td>\n",
    918        "      <td>1.001694</td>\n",
    919        "    </tr>\n",
    920        "    <tr>\n",
    921        "      <th>Equity(48746 [SUM])</th>\n",
    922        "      <td>0.457585</td>\n",
    923        "      <td>1.024112</td>\n",
    924        "      <td>1.131837</td>\n",
    925        "    </tr>\n",
    926        "    <tr>\n",
    927        "      <th>Equity(48747 [AFTY])</th>\n",
    928        "      <td>0.193080</td>\n",
    929        "      <td>1.032030</td>\n",
    930        "      <td>1.146784</td>\n",
    931        "    </tr>\n",
    932        "    <tr>\n",
    933        "      <th>Equity(48754 [IBDJ])</th>\n",
    934        "      <td>0.048949</td>\n",
    935        "      <td>1.000161</td>\n",
    936        "      <td>1.000561</td>\n",
    937        "    </tr>\n",
    938        "    <tr>\n",
    939        "      <th>Equity(48768 [SDEM])</th>\n",
    940        "      <td>0.102439</td>\n",
    941        "      <td>1.068141</td>\n",
    942        "      <td>1.103535</td>\n",
    943        "    </tr>\n",
    944        "    <tr>\n",
    945        "      <th>Equity(48783 [CHEK_W])</th>\n",
    946        "      <td>0.222528</td>\n",
    947        "      <td>1.466667</td>\n",
    948        "      <td>1.157895</td>\n",
    949        "    </tr>\n",
    950        "    <tr>\n",
    951        "      <th>Equity(48785 [NCOM])</th>\n",
    952        "      <td>0.166885</td>\n",
    953        "      <td>1.018349</td>\n",
    954        "      <td>1.020221</td>\n",
    955        "    </tr>\n",
    956        "    <tr>\n",
    957        "      <th>Equity(48792 [AFSI_PRD])</th>\n",
    958        "      <td>0.062426</td>\n",
    959        "      <td>1.001572</td>\n",
    960        "      <td>1.008307</td>\n",
    961        "    </tr>\n",
    962        "    <tr>\n",
    963        "      <th>Equity(48804 [TANH])</th>\n",
    964        "      <td>0.620471</td>\n",
    965        "      <td>1.179510</td>\n",
    966        "      <td>1.381538</td>\n",
    967        "    </tr>\n",
    968        "    <tr>\n",
    969        "      <th>Equity(48809 [AIC])</th>\n",
    970        "      <td>0.027276</td>\n",
    971        "      <td>1.000399</td>\n",
    972        "      <td>1.008857</td>\n",
    973        "    </tr>\n",
    974        "    <tr>\n",
    975        "      <th>Equity(48821 [CJES])</th>\n",
    976        "      <td>0.851751</td>\n",
    977        "      <td>1.220506</td>\n",
    978        "      <td>1.335895</td>\n",
    979        "    </tr>\n",
    980        "    <tr>\n",
    981        "      <th>Equity(48822 [CLLS])</th>\n",
    982        "      <td>0.230596</td>\n",
    983        "      <td>1.014299</td>\n",
    984        "      <td>1.023526</td>\n",
    985        "    </tr>\n",
    986        "    <tr>\n",
    987        "      <th>Equity(48823 [SEDG])</th>\n",
    988        "      <td>1.228733</td>\n",
    989        "      <td>1.207086</td>\n",
    990        "      <td>1.234685</td>\n",
    991        "    </tr>\n",
    992        "    <tr>\n",
    993        "      <th>Equity(48853 [SGDJ])</th>\n",
    994        "      <td>0.381209</td>\n",
    995        "      <td>1.026782</td>\n",
    996        "      <td>1.060795</td>\n",
    997        "    </tr>\n",
    998        "    <tr>\n",
    999        "      <th>Equity(48863 [GDDY])</th>\n",
   1000        "      <td>0.453669</td>\n",
   1001        "      <td>1.046755</td>\n",
   1002        "      <td>1.029738</td>\n",
   1003        "    </tr>\n",
   1004        "    <tr>\n",
   1005        "      <th>Equity(48875 [HBHC_L])</th>\n",
   1006        "      <td>0.025687</td>\n",
   1007        "      <td>1.001746</td>\n",
   1008        "      <td>1.005010</td>\n",
   1009        "    </tr>\n",
   1010        "  </tbody>\n",
   1011        "</table>\n",
   1012        "<p>2773 rows × 3 columns</p>\n",
   1013        "</div>"
   1014       ],
   1015       "text/plain": [
   1016        "                                                     std_dev  \\\n",
   1017        "2015-05-05 00:00:00+00:00 Equity(2 [AA])            0.293428   \n",
   1018        "                          Equity(24 [AAPL])         1.737677   \n",
   1019        "                          Equity(39 [DDC])          0.138939   \n",
   1020        "                          Equity(52 [ABM])          0.093680   \n",
   1021        "                          Equity(64 [ABX])          0.178034   \n",
   1022        "                          Equity(66 [AB])           0.510427   \n",
   1023        "                          Equity(100 [IEP])         0.444189   \n",
   1024        "                          Equity(114 [ADBE])        0.280385   \n",
   1025        "                          Equity(117 [AEY])         0.022471   \n",
   1026        "                          Equity(128 [ADM])         0.605495   \n",
   1027        "                          Equity(149 [ADX])         0.072153   \n",
   1028        "                          Equity(154 [AEM])         0.634920   \n",
   1029        "                          Equity(161 [AEP])         0.458938   \n",
   1030        "                          Equity(166 [AES])         0.164973   \n",
   1031        "                          Equity(168 [AET])         1.166938   \n",
   1032        "                          Equity(192 [ATAX])        0.024819   \n",
   1033        "                          Equity(197 [AGCO])        0.646594   \n",
   1034        "                          Equity(239 [AIG])         0.710307   \n",
   1035        "                          Equity(253 [AIR])         0.156844   \n",
   1036        "                          Equity(266 [AJG])         0.397769   \n",
   1037        "                          Equity(312 [ALOT])        0.182893   \n",
   1038        "                          Equity(328 [ALTR])        2.286573   \n",
   1039        "                          Equity(353 [AME])         0.362513   \n",
   1040        "                          Equity(357 [TWX])         0.502816   \n",
   1041        "                          Equity(366 [AVD])         0.842249   \n",
   1042        "                          Equity(438 [AON])         0.881295   \n",
   1043        "                          Equity(448 [APA])         0.678899   \n",
   1044        "                          Equity(451 [APB])         0.081240   \n",
   1045        "                          Equity(455 [APC])         0.152394   \n",
   1046        "                          Equity(474 [APOG])        0.610410   \n",
   1047        "...                                                      ...   \n",
   1048        "                          Equity(48504 [ERUS])      0.052688   \n",
   1049        "                          Equity(48531 [VSTO])      0.513443   \n",
   1050        "                          Equity(48532 [ENTL])      0.163756   \n",
   1051        "                          Equity(48535 [ANH_PRC])   0.072388   \n",
   1052        "                          Equity(48543 [SHAK])      2.705316   \n",
   1053        "                          Equity(48591 [SPYB])      0.221848   \n",
   1054        "                          Equity(48602 [ITEK])      0.177042   \n",
   1055        "                          Equity(48623 [TCCB])      0.056148   \n",
   1056        "                          Equity(48641 [GDJJ])      0.530298   \n",
   1057        "                          Equity(48644 [GDXX])      0.401079   \n",
   1058        "                          Equity(48680 [RODM])      0.080455   \n",
   1059        "                          Equity(48688 [QVM])       0.152245   \n",
   1060        "                          Equity(48701 [AMT_PRB])   0.546691   \n",
   1061        "                          Equity(48706 [GBSN_U])    0.442285   \n",
   1062        "                          Equity(48730 [AGN_PRA])   9.614542   \n",
   1063        "                          Equity(48746 [SUM])       0.457585   \n",
   1064        "                          Equity(48747 [AFTY])      0.193080   \n",
   1065        "                          Equity(48754 [IBDJ])      0.048949   \n",
   1066        "                          Equity(48768 [SDEM])      0.102439   \n",
   1067        "                          Equity(48783 [CHEK_W])    0.222528   \n",
   1068        "                          Equity(48785 [NCOM])      0.166885   \n",
   1069        "                          Equity(48792 [AFSI_PRD])  0.062426   \n",
   1070        "                          Equity(48804 [TANH])      0.620471   \n",
   1071        "                          Equity(48809 [AIC])       0.027276   \n",
   1072        "                          Equity(48821 [CJES])      0.851751   \n",
   1073        "                          Equity(48822 [CLLS])      0.230596   \n",
   1074        "                          Equity(48823 [SEDG])      1.228733   \n",
   1075        "                          Equity(48853 [SGDJ])      0.381209   \n",
   1076        "                          Equity(48863 [GDDY])      0.453669   \n",
   1077        "                          Equity(48875 [HBHC_L])    0.025687   \n",
   1078        "\n",
   1079        "                                                    ten_day_momentum  \\\n",
   1080        "2015-05-05 00:00:00+00:00 Equity(2 [AA])                    1.036612   \n",
   1081        "                          Equity(24 [AAPL])                 1.014256   \n",
   1082        "                          Equity(39 [DDC])                  1.062261   \n",
   1083        "                          Equity(52 [ABM])                  1.009212   \n",
   1084        "                          Equity(64 [ABX])                  1.025721   \n",
   1085        "                          Equity(66 [AB])                   1.036137   \n",
   1086        "                          Equity(100 [IEP])                 1.008820   \n",
   1087        "                          Equity(114 [ADBE])                1.016618   \n",
   1088        "                          Equity(117 [AEY])                 1.004167   \n",
   1089        "                          Equity(128 [ADM])                 1.049625   \n",
   1090        "                          Equity(149 [ADX])                 1.004607   \n",
   1091        "                          Equity(154 [AEM])                 1.032690   \n",
   1092        "                          Equity(161 [AEP])                 1.024926   \n",
   1093        "                          Equity(166 [AES])                 1.031037   \n",
   1094        "                          Equity(168 [AET])                 1.007566   \n",
   1095        "                          Equity(192 [ATAX])                1.009025   \n",
   1096        "                          Equity(197 [AGCO])                1.066522   \n",
   1097        "                          Equity(239 [AIG])                 1.027189   \n",
   1098        "                          Equity(253 [AIR])                 1.007474   \n",
   1099        "                          Equity(266 [AJG])                 1.000839   \n",
   1100        "                          Equity(312 [ALOT])                1.031780   \n",
   1101        "                          Equity(328 [ALTR])                1.041397   \n",
   1102        "                          Equity(353 [AME])                 1.023622   \n",
   1103        "                          Equity(357 [TWX])                 1.022013   \n",
   1104        "                          Equity(366 [AVD])                 1.114111   \n",
   1105        "                          Equity(438 [AON])                 1.020732   \n",
   1106        "                          Equity(448 [APA])                 1.002193   \n",
   1107        "                          Equity(451 [APB])                 1.026542   \n",
   1108        "                          Equity(455 [APC])                 1.012312   \n",
   1109        "                          Equity(474 [APOG])                1.030843   \n",
   1110        "...                                                              ...   \n",
   1111        "                          Equity(48504 [ERUS])              1.030893   \n",
   1112        "                          Equity(48531 [VSTO])              1.029164   \n",
   1113        "                          Equity(48532 [ENTL])              1.043708   \n",
   1114        "                          Equity(48535 [ANH_PRC])           1.010656   \n",
   1115        "                          Equity(48543 [SHAK])              1.262727   \n",
   1116        "                          Equity(48591 [SPYB])              1.001279   \n",
   1117        "                          Equity(48602 [ITEK])              1.213693   \n",
   1118        "                          Equity(48623 [TCCB])              1.003641   \n",
   1119        "                          Equity(48641 [GDJJ])              1.041176   \n",
   1120        "                          Equity(48644 [GDXX])              1.042319   \n",
   1121        "                          Equity(48680 [RODM])              1.005037   \n",
   1122        "                          Equity(48688 [QVM])               1.009996   \n",
   1123        "                          Equity(48701 [AMT_PRB])           1.010356   \n",
   1124        "                          Equity(48706 [GBSN_U])            1.214035   \n",
   1125        "                          Equity(48730 [AGN_PRA])           1.000948   \n",
   1126        "                          Equity(48746 [SUM])               1.024112   \n",
   1127        "                          Equity(48747 [AFTY])              1.032030   \n",
   1128        "                          Equity(48754 [IBDJ])              1.000161   \n",
   1129        "                          Equity(48768 [SDEM])              1.068141   \n",
   1130        "                          Equity(48783 [CHEK_W])            1.466667   \n",
   1131        "                          Equity(48785 [NCOM])              1.018349   \n",
   1132        "                          Equity(48792 [AFSI_PRD])          1.001572   \n",
   1133        "                          Equity(48804 [TANH])              1.179510   \n",
   1134        "                          Equity(48809 [AIC])               1.000399   \n",
   1135        "                          Equity(48821 [CJES])              1.220506   \n",
   1136        "                          Equity(48822 [CLLS])              1.014299   \n",
   1137        "                          Equity(48823 [SEDG])              1.207086   \n",
   1138        "                          Equity(48853 [SGDJ])              1.026782   \n",
   1139        "                          Equity(48863 [GDDY])              1.046755   \n",
   1140        "                          Equity(48875 [HBHC_L])            1.001746   \n",
   1141        "\n",
   1142        "                                                    twenty_day_momentum  \n",
   1143        "2015-05-05 00:00:00+00:00 Equity(2 [AA])                       1.042783  \n",
   1144        "                          Equity(24 [AAPL])                    1.021380  \n",
   1145        "                          Equity(39 [DDC])                     1.167319  \n",
   1146        "                          Equity(52 [ABM])                     1.015075  \n",
   1147        "                          Equity(64 [ABX])                     1.065587  \n",
   1148        "                          Equity(66 [AB])                      1.067545  \n",
   1149        "                          Equity(100 [IEP])                    1.011385  \n",
   1150        "                          Equity(114 [ADBE])                   1.002909  \n",
   1151        "                          Equity(117 [AEY])                    1.025532  \n",
   1152        "                          Equity(128 [ADM])                    1.044832  \n",
   1153        "                          Equity(149 [ADX])                    1.016129  \n",
   1154        "                          Equity(154 [AEM])                    1.065071  \n",
   1155        "                          Equity(161 [AEP])                    1.017563  \n",
   1156        "                          Equity(166 [AES])                    1.045946  \n",
   1157        "                          Equity(168 [AET])                    1.022472  \n",
   1158        "                          Equity(192 [ATAX])                   1.018215  \n",
   1159        "                          Equity(197 [AGCO])                   1.098572  \n",
   1160        "                          Equity(239 [AIG])                    1.058588  \n",
   1161        "                          Equity(253 [AIR])                    1.003818  \n",
   1162        "                          Equity(266 [AJG])                    1.018799  \n",
   1163        "                          Equity(312 [ALOT])                   1.021352  \n",
   1164        "                          Equity(328 [ALTR])                   1.088996  \n",
   1165        "                          Equity(353 [AME])                    1.004902  \n",
   1166        "                          Equity(357 [TWX])                    1.006976  \n",
   1167        "                          Equity(366 [AVD])                    1.093162  \n",
   1168        "                          Equity(438 [AON])                    1.018739  \n",
   1169        "                          Equity(448 [APA])                    1.051258  \n",
   1170        "                          Equity(451 [APB])                    1.105042  \n",
   1171        "                          Equity(455 [APC])                    1.097284  \n",
   1172        "                          Equity(474 [APOG])                   1.206232  \n",
   1173        "...                                                                 ...  \n",
   1174        "                          Equity(48504 [ERUS])                 1.052812  \n",
   1175        "                          Equity(48531 [VSTO])                 1.028110  \n",
   1176        "                          Equity(48532 [ENTL])                 1.152246  \n",
   1177        "                          Equity(48535 [ANH_PRC])              1.010656  \n",
   1178        "                          Equity(48543 [SHAK])                 1.498020  \n",
   1179        "                          Equity(48591 [SPYB])                 1.005801  \n",
   1180        "                          Equity(48602 [ITEK])                 1.133721  \n",
   1181        "                          Equity(48623 [TCCB])                 1.006349  \n",
   1182        "                          Equity(48641 [GDJJ])                 1.111809  \n",
   1183        "                          Equity(48644 [GDXX])                 1.120948  \n",
   1184        "                          Equity(48680 [RODM])                 1.018853  \n",
   1185        "                          Equity(48688 [QVM])                  1.021845  \n",
   1186        "                          Equity(48701 [AMT_PRB])              1.023537  \n",
   1187        "                          Equity(48706 [GBSN_U])               1.272059  \n",
   1188        "                          Equity(48730 [AGN_PRA])              1.001694  \n",
   1189        "                          Equity(48746 [SUM])                  1.131837  \n",
   1190        "                          Equity(48747 [AFTY])                 1.146784  \n",
   1191        "                          Equity(48754 [IBDJ])                 1.000561  \n",
   1192        "                          Equity(48768 [SDEM])                 1.103535  \n",
   1193        "                          Equity(48783 [CHEK_W])               1.157895  \n",
   1194        "                          Equity(48785 [NCOM])                 1.020221  \n",
   1195        "                          Equity(48792 [AFSI_PRD])             1.008307  \n",
   1196        "                          Equity(48804 [TANH])                 1.381538  \n",
   1197        "                          Equity(48809 [AIC])                  1.008857  \n",
   1198        "                          Equity(48821 [CJES])                 1.335895  \n",
   1199        "                          Equity(48822 [CLLS])                 1.023526  \n",
   1200        "                          Equity(48823 [SEDG])                 1.234685  \n",
   1201        "                          Equity(48853 [SGDJ])                 1.060795  \n",
   1202        "                          Equity(48863 [GDDY])                 1.029738  \n",
   1203        "                          Equity(48875 [HBHC_L])               1.005010  \n",
   1204        "\n",
   1205        "[2773 rows x 3 columns]"
   1206       ]
   1207      },
   1208      "execution_count": 12,
   1209      "metadata": {},
   1210      "output_type": "execute_result"
   1211     }
   1212    ],
   1213    "source": [
   1214     "result = run_pipeline(make_pipeline(), '2015-05-05', '2015-05-05')\n",
   1215     "result"
   1216    ]
   1217   },
   1218   {
   1219    "cell_type": "markdown",
   1220    "metadata": {},
   1221    "source": [
   1222     "Custom factors allow us to define custom computations in a pipeline. They are frequently the best way to perform computations on [partner datasets](https://www.quantopian.com/data) or on multiple data columns. The full documentation for CustomFactors is available [here](https://www.quantopian.com/help#custom-factors).\n",
   1223     "\n",
   1224     "In the next lesson, we'll use everything we've learned so far to create a pipeline for an algorithm."
   1225    ]
   1226   }
   1227  ],
   1228  "metadata": {
   1229   "kernelspec": {
   1230    "display_name": "Python 2",
   1231    "language": "python",
   1232    "name": "python2"
   1233   },
   1234   "language_info": {
   1235    "codemirror_mode": {
   1236     "name": "ipython",
   1237     "version": 2
   1238    },
   1239    "file_extension": ".py",
   1240    "mimetype": "text/x-python",
   1241    "name": "python",
   1242    "nbconvert_exporter": "python",
   1243    "pygments_lexer": "ipython2",
   1244    "version": "2.7.12"
   1245   }
   1246  },
   1247  "nbformat": 4,
   1248  "nbformat_minor": 0
   1249 }