def compute_factors():
    """Create factor pipeline incl. mean reversion,
        filtered by 30d Dollar Volume; capture factor ranks"""
    mean_reversion = MeanReversion()
    dollar_volume = AverageDollarVolume(window_length=30)
    return Pipeline(columns={'longs'  : mean_reversion.bottom(N_LONGS),
                             'shorts' : mean_reversion.top(N_SHORTS),
                             'ranking': mean_reversion.rank(ascending=False)},
                    screen=dollar_volume.top(VOL_SCREEN))
예제 #2
0
def make_pipeline():
    """Sets up the pipeline"""
    dollar_volume = AverageDollarVolume(window_length=20)
    adv1000 = dollar_volume.top(1000)
    fd = Fundamentals(mask=adv1000)
    market_cap = fd.cshoq * fd.prccq  # this is how to calculate market cap with Computstat fields
    book_equity = fd.seqq - fd.PS  # this is a quick way to calculate book_equity
    book_to_price = book_equity / market_cap
    biggest = market_cap.top(500, mask=adv1000)
    smallest = market_cap.bottom(500, mask=adv1000)

    highpb = book_to_price.top(500, mask=adv1000)
    lowpb = book_to_price.bottom(500, mask=adv1000)

    momentum = Momentum(mask=adv1000)  # momentum
    high_momentum = momentum.top(500, mask=adv1000)
    low_momentum = momentum.bottom(500, mask=adv1000)

    volatility = Volatility(mask=adv1000)
    highvol = volatility.top(500, mask=adv1000)
    lowvol = volatility.bottom(500, mask=adv1000)

    streversal = RSI(window_length=14, mask=adv1000)
    high_streversal = streversal.top(500, mask=adv1000)
    low_streversal = streversal.bottom(500, mask=adv1000)

    universe = biggest | smallest | highpb | lowpb | low_momentum | high_momentum

    return Pipeline(
        columns={
            'returns': Returns(window_length=2),
            # 'market_cap': market_cap,  # not needed
            # 'book_to_price': book_to_price,  # not needed
            'biggest': biggest,
            'smallest': smallest,
            'highpb': highpb,
            'lowpb': lowpb,
            # 'momentum': momentum,  # not needed
            'low_momentum': low_momentum,
            'high_momentum': high_momentum,
            # 'volatility': volatility, # not needed
            'highvol': highvol,
            'lowvol': lowvol,
            # 'streversal': streversal,  # not needed
            'high_streversal': high_streversal,
            'low_streversal': low_streversal
        },
        screen=universe)
예제 #3
0
def make_universe():
    # Set screen
    dollar_volume = AverageDollarVolume(window_length=90)
    return dollar_volume.top(UNIVERSE)