def make_pipeline():
    have_market_cap = IEXKeyStats.marketcap.latest >= 1

    avg_volume = SimpleMovingAverage(inputs=[USEquityPricing.volume], window_length=50)
    filter_volume = avg_volume > 500000

    last_price = Latest(inputs=[USEquityPricing.close], window_length=1)
    filter_price = last_price > 1

    dollar_volume = AverageDollarVolume(window_length=50)
    filter_dollar_volume = dollar_volume > 2500000

    sma_150 = SimpleMovingAverage(inputs=[USEquityPricing.close], window_length=150)
    filter_sma_150 = USEquityPricing.close.latest > sma_150

    atr_10_percent = atr_10days_percent()
    filter_atr_10 = atr_10_percent > 4

    rsi = RSI(inputs=[USEquityPricing.close], window_length=3)
    filter_overbought = rsi < 30

    atr_10 = atr_10days()

    stocks_to_trade = have_market_cap & filter_volume & filter_price & filter_dollar_volume & filter_sma_150 & filter_atr_10 & filter_overbought

    return Pipeline(
        columns={
            'stocks': stocks_to_trade,
            'rsi': rsi,
            'atr': atr_10
        },
        screen=(stocks_to_trade)
    )
def make_pipeline():
    # Filter for primary share equities. IsPrimaryShare is a built-in filter.
    primary_share = IsPrimaryShare()

    # Not when-issued equities.
    not_wi = ~IEXCompany.symbol.latest.endswith('.WI')

    # Equities without LP in their name, .matches does a match using a regular
    # expression
    not_lp_name = ~IEXCompany.companyName.latest.matches('.* L[. ]?P.?$')

    # Equities whose most recent Morningstar market cap is not null have
    # fundamental data and therefore are not ETFs.
    have_market_cap = IEXKeyStats.marketcap.latest >= 1
       
    tradeable_stocks = (
        primary_share
        & not_wi
        & not_lp_name
        & have_market_cap)
    longs = USEquityPricing.close.latest.top(50,mask=tradeable_stocks)
    shorts = SimpleMovingAverage(inputs=[USEquityPricing.close], window_length=10, mask=tradeable_stocks).percentile_between(20,22)    

    return Pipeline(
        columns={
            'longs':  longs,
            'shorts': shorts,
        },
        screen=tradeable_stocks& (shorts | longs)
    
    )
Exemplo n.º 3
0
def make_pipeline(context):
    advFilter = curVsAvgVolFilter(context.params.get('lookback'))
    # midToLargeFilter = isMidToLargeCap(context.params.get('lookback'))
    smaSlow = SimpleMovingAverage(
        inputs=[USEquityPricing.close],
        window_length=context.params.get('smaSlowLookback'))
    smaFast = SimpleMovingAverage(
        inputs=[USEquityPricing.close],
        window_length=context.params.get('smaFastLookback'))
    top50 = AverageDollarVolume(window_length=20).top(50)

    pipe = Pipeline(screen=top50)
    pipe.add(advFilter, 'advFilter')
    pipe.add(smaSlow, 'smaSlow')
    pipe.add(smaFast, 'smaFast')
    # pipe.add(midToLargeFilter, 'midToLargeFilter')

    return pipe
Exemplo n.º 4
0
def make_pipeline():
    # My list of ETFS
    base_universe = StaticSymbols(symbols = ("DGAZ", "UGAZ", "JDST", "JNUG", "UWT", "DWT", "GUSH", "DRIP", "TQQQ", "SQQQ", "SPXS", "SPXL"))

    dollar_volume = AverageDollarVolume(
        window_length=14
    )
    high_dollar_volume = (dollar_volume > 10000000)

    mean_close_10 = SimpleMovingAverage(
        inputs=[USEquityPricing.close],
        window_length=10
    )
    mean_close_30 = SimpleMovingAverage(
        inputs=[USEquityPricing.close],
        window_length=30
    )
    rsi = RSI()

    percent_difference = (mean_close_10 - mean_close_30) / mean_close_30
    rsi_low = (rsi <= 40)
    rsi_high = (rsi >= 65)
    shorts = percent_difference.percentile_between(90, 100) & rsi_high
    longs = percent_difference.percentile_between(0, 15) & rsi_low

    securities_to_trade = high_dollar_volume

    return Pipeline(
        columns={
            'longs': longs,
            'shorts': shorts,
            'rsi': rsi,
            'percent_difference': percent_difference
        },
        screen=base_universe
    )
Exemplo n.º 5
0
def make_pipeline(context):
    """
    Create our pipeline.
    """

    # Filter for primary share equities. IsPrimaryShare is a built-in filter.
    primary_share = IsPrimaryShare()

    # Not when-issued equities.
    not_wi = ~IEXCompany.symbol.latest.endswith('.WI')

    # Equities without LP in their name, .matches does a match using a regular
    # expression
    not_lp_name = ~IEXCompany.companyName.latest.matches('.* L[. ]?P.?$')

    # Equities whose most recent Morningstar market cap is not null have
    # fundamental data and therefore are not ETFs.
    have_market_cap = IEXKeyStats.marketcap.latest >= 1

    # At least a certain price
    price = USEquityPricing.close.latest
    AtLeastPrice = (price >= context.MyLeastPrice)
    AtMostPrice = (price <= context.MyMostPrice)

    # Filter for stocks that pass all of our previous filters.
    tradeable_stocks = (primary_share
                        & not_wi
                        & not_lp_name
                        & have_market_cap
                        & AtLeastPrice
                        & AtMostPrice)

    LowVar = 6
    HighVar = 40

    log.info('''
Algorithm initialized variables:
 context.MaxCandidates %s
 LowVar %s
 HighVar %s''' % (context.MaxCandidates, LowVar, HighVar))

    # High dollar volume filter.
    base_universe = AverageDollarVolume(
        window_length=20,
        mask=tradeable_stocks).percentile_between(LowVar, HighVar)

    # Short close price average.
    ShortAvg = SimpleMovingAverage(inputs=[USEquityPricing.close],
                                   window_length=3,
                                   mask=base_universe)

    # Long close price average.
    LongAvg = SimpleMovingAverage(inputs=[USEquityPricing.close],
                                  window_length=45,
                                  mask=base_universe)

    percent_difference = (ShortAvg - LongAvg) / LongAvg

    # Filter to select securities to long.
    stocks_worst = percent_difference.bottom(context.MaxCandidates)
    securities_to_trade = (stocks_worst)

    return Pipeline(
        columns={'stocks_worst': stocks_worst},
        screen=(securities_to_trade),
    )