Notebook
In [82]:
from quantopian.pipeline import Pipeline
from quantopian.pipeline.data.alpha_vertex import (
    # Top 100 Securities
    precog_top_100 as dataset_100,
    # Top 500 Securities|
    precog_top_500 as dataset_500
)
from quantopian.research import run_pipeline
import alphalens
from quantopian.pipeline.filters.morningstar import Q1500US
from quantopian.pipeline.data.builtin import USEquityPricing
from quantopian.pipeline.factors import SimpleMovingAverage,RSI
from quantopian.interactive.data.zacks import earnings_surprises_free as dataset
from odo import odo
import pandas as pd
In [89]:
def make_pipeline():

    sma_10 = SimpleMovingAverage(inputs=[USEquityPricing.close], window_length=10)
    sma_20 = SimpleMovingAverage(inputs=[USEquityPricing.close], window_length=20)
    EPS_mean_estimate = dataset.eps_mean_est
    EPS_std_est = dataset.eps_std_dev_est
    eps_act = dataset.eps_act
    
    
    percent_diff = (sma_10 - sma_20)/sma_20
    
    top_bottom_scores = (
        percent_diff.top(350) | percent_diff.bottom(350)
    )                           
    
    universe = (Q1500US &
                top_bottom_scores & 
                dataset.eps_mean_est.notnull() &
                dataset.eps_std_dev_est.notnull() &
                dataset.eps_act.notnull())
    return Pipeline(
        columns={
            "percent diff" : percent_diff,
            'EPS mean estimate': EPS_mean_estimate,
            'EPS std est': EPS_std_est,
            'eps_act':eps_act,
            'SUE': (eps_act - EPS_mean_estimate)/EPS_std_est,
            'score': percent_diff
        },
        screen=universe
    ) 
In [90]:
results = run_pipeline(make_pipeline(), start_date='2007-01-01', end_date='2010-01-01')

TypeErrorTraceback (most recent call last)
<ipython-input-90-47f1bf42d04f> in <module>()
----> 1 results = run_pipeline(make_pipeline(), start_date='2007-01-01', end_date='2010-01-01')

<ipython-input-89-ab5917bf44fc> in make_pipeline()
     17                 top_bottom_scores &
     18                 dataset.eps_mean_est.notnull() &
---> 19                 dataset.eps_std_dev_est.notnull() &
     20                 dataset.eps_act.notnull())
     21     return Pipeline(

/build/src/qexec_repo/zipline_repo/zipline/pipeline/filters/filter.pyc in binary_operator(self, other)
     75         if isinstance(self, NumericalExpression):
     76             self_expr, other_expr, new_inputs = self.build_binary_op(
---> 77                 op, other,
     78             )
     79             return NumExprFilter.create(

/build/src/qexec_repo/zipline_repo/zipline/pipeline/expression.pyc in build_binary_op(self, op, other)
    308             new_inputs = self.inputs
    309         else:
--> 310             raise BadBinaryOperator(op, other)
    311         return self_expr, other_expr, new_inputs
    312 

TypeError: __init__() takes exactly 4 arguments (3 given)
In [86]:
results.head()

NameErrorTraceback (most recent call last)
<ipython-input-86-0f9ba5b4964d> in <module>()
----> 1 results.head()

NameError: name 'results' is not defined
In [6]:
assets = results.index.levels[1].unique()
pricing = get_pricing(assets, start_date='2005-12-01', end_date='2012-02-01', fields='open_price')
In [8]:
factor_data = alphalens.utils.get_clean_factor_and_forward_returns(factor = results['percent diff'], 
                                                     prices = pricing, 
                                                     quantiles=3, 
                                                     periods=(5,10,20,30),
                                                     max_loss = 0.60)
alphalens.tears.create_full_tear_sheet(factor_data)
Dropped 55.9% entries from factor data: 0.0% in forward returns computation and 55.9% in binning phase (set max_loss=0 to see potentially suppressed Exceptions).
max_loss is 60.0%, not exceeded: OK!
Quantiles Statistics
min max mean std count count %
factor_quantile
1.0 -0.319945 0.213576 -0.081035 0.151293 59 46.825397
2.0 -0.200952 0.224897 0.079853 0.166307 13 10.317460
3.0 -0.218304 0.332132 0.089737 0.155898 54 42.857143
Returns Analysis
5D 10D 20D 30D
Ann. alpha -0.043 -0.142 0.165 -0.180
beta -0.271 -0.433 -0.323 0.038
Mean Period Wise Return Top Quantile (bps) -137.188 -91.487 -12.206 -16.881
Mean Period Wise Return Bottom Quantile (bps) 103.833 124.519 16.983 12.794
Mean Period Wise Spread (bps) -221.080 -264.679 -53.337 -25.347
<matplotlib.figure.Figure at 0x7ff8b5d31190>
Information Analysis
5D 10D 20D 30D
IC Mean -0.008 -0.185 0.006 -0.136
IC Std. 0.923 0.901 0.934 0.927
Risk-Adjusted IC -0.008 -0.205 0.006 -0.147
t-stat(IC) -0.060 -1.493 0.044 -1.067
p-value(IC) 0.953 0.141 0.965 0.291
IC Skew 0.023 0.319 -0.061 0.289
IC Kurtosis -1.856 -1.746 -1.870 -1.777
Turnover Analysis
10D 20D 30D 5D
Quantile 1 Mean Turnover 0.965 1.00 1.000 0.854
Quantile 2 Mean Turnover 1.000 NaN NaN 0.750
Quantile 3 Mean Turnover 1.000 0.97 0.957 0.938
5D 10D 20D 30D
Mean Factor Rank Autocorrelation 0.429 NaN NaN NaN