def make_pipeline():

    sentiment_score = SimpleMovingAverage(inputs=[stocktwits.bull_minus_bear],
                                          window_length=3,
                                          mask=QTradableStocksUS())

    return Pipeline(columns={
        'sentiment_score': sentiment_score,
    },
                    screen=sentiment_score.notnull())
Ejemplo n.º 2
0
def make_pipeline():

    sentiment_score = SimpleMovingAverage(inputs=[stocktwits.bull_minus_bear],
                                          window_length=5,
                                          mask=QTradableStocksUS())
    close_price = USEquityPricing.close.latest
    return Pipeline(columns={
        'close_price': close_price,
        'sentiment_score': sentiment_score,
    },
                    screen=sentiment_score.notnull())
Ejemplo n.º 3
0
def make_pipeline():

    sentiment_score = SimpleMovingAverage(
        inputs=[stocktwits.bull_minus_bear],
        window_length=3,
        # filtering
        mask=QTradableStocksUS())

    return Pipeline(
        columns={
            'sentiment_score': sentiment_score,
        },
        # つまり、sentiment_scoreが null ではない銘柄は全部投資対象に入れる
        screen=sentiment_score.notnull())
Ejemplo n.º 4
0
def make_pipeline():

    not_near_earnings = ~((BusinessDaysUntilNextEarnings() <= 2) |
                          (BusinessDaysSincePreviousEarnings() <= 2))

    not_acq_tar = ~IsAnnouncedAcqTarget()

    universe = (QTradableStocksUS() & not_near_earnings & not_acq_tar)

    sentiment_score = SimpleMovingAverage(inputs=[stocktwits.bull_minus_bear],
                                          window_length=5,
                                          mask=universe)

    return Pipeline(columns={
        'sentiment_score': sentiment_score,
    },
                    screen=sentiment_score.notnull())
Ejemplo n.º 5
0
def make_pipeline():
    """
    A function to create our dynamic stock selector (pipeline). Documentation
    on pipeline can be found here:
    https://www.quantopian.com/help#pipeline-title
    """

    # Base universe set to QTradableStocksUS()
    base_universe = QTradableStocksUS()

    # Sentiment score, based on a moving average of the bull minus bear factor
    sentiment_score = SimpleMovingAverage(
        inputs=[stocktwits.bull_minus_bear],
        window_length=3,
    )

    pipe = Pipeline(
        columns={'sentiment_score': sentiment_score},
        screen=(base_universe & sentiment_score.notnull()),
    )
    return pipe
Ejemplo n.º 6
0
def make_pipeline():

    # 5-day sentiment moving average factor.
    sentiment_factor = SimpleMovingAverage(inputs=[sentiment.sentiment_signal],
                                           window_length=5)

    # Filter for stocks that are not within 2 days of an earnings announcement.
    not_near_earnings_announcement = ~(
        (BusinessDaysUntilNextEarnings() <= 2)
        | (BusinessDaysSincePreviousEarnings() <= 2))

    # Filter for stocks that are announced acquisition target.
    not_announced_acq_target = ~IsAnnouncedAcqTarget()

    # Filter for stocks that had their sentiment signal updated in the last day.
    new_info = (BusinessDaysSincePreviousEvent(
        inputs=[sentiment.asof_date.latest]) <= 1)

    # Our universe is made up of stocks that have a non-null sentiment signal that was updated in
    # the last day, are not within 2 days of an earnings announcement, are not announced acquisition
    # targets, and are in the Q1500US.
    universe = (Q1500US()
                & sentiment_factor.notnull()
                & not_near_earnings_announcement
                & not_announced_acq_target
                & new_info)

    # A classifier to separate the stocks into quantiles based on sentiment rank.
    sentiment_quantiles = sentiment_factor.rank(mask=universe,
                                                method='average').quantiles(3)

    # Go short the stocks in the 0th quantile, and long the stocks in the 2nd quantile.
    pipe = Pipeline(columns={
        'sentiment': sentiment_quantiles,
        'shorts': sentiment_quantiles.eq(0),
        'longs': sentiment_quantiles.eq(2),
    },
                    screen=universe)

    return pipe
Ejemplo n.º 7
0
def make_pipeline():
    """
    A function that creates and returns our pipeline.

    We break this piece of logic out into its own function to make it easier to
    test and modify in isolation. In particular, this function can be
    copy/pasted into research and run by itself.

    Returns
    -------
    pipe : Pipeline
        Represents computation we would like to perform on the assets that make
        it through the pipeline screen.
    """
    
    sentiment_score = SimpleMovingAverage(
        inputs=[stocktwits.bull_minus_bear],
        window_length=7,
    )
    
    Asset_Growth_7d = Returns(window_length=8);
    
    eveb = morningstar.valuation_ratios.ev_to_ebitda.latest
    
    cash_return = morningstar.valuation_ratios.cash_return.latest
    
    total_yield = morningstar.valuation_ratios.total_yield.latest

    #universe = Q1500US()
    universe = QTradableStocksUS()
    
    # We winsorize our factor values in order to lessen the impact of outliers
    # For more information on winsorization, please see
    # https://en.wikipedia.org/wiki/Winsorizing
    
    sentiment_score_winsorized = sentiment_score.winsorize(min_percentile=0.05,                                                                             max_percentile=0.95)
    
    Asset_Growth_7d_winsorized = Asset_Growth_7d.winsorize(min_percentile=0.05, max_percentile=0.95)
    
    eveb_winsorized = eveb.winsorize(min_percentile=0.05, max_percentile=0.95)
    cash_return_winsorized = cash_return.winsorize(min_percentile=0.05, max_percentile=0.95)
    total_yield_winsorized = total_yield.winsorize(min_percentile=0.05, max_percentile=0.95)

    # Here we combine our winsorized factors, z-scoring them to equalize their influence
    """
    combined_factor = -0.3*Asset_Growth_7d_winsorized.zscore() -0.25*sentiment_score_winsorized.zscore() +0.05*eveb_winsorized.zscore() +0.05*cash_return_winsorized.zscore() +0.35*total_yield_winsorized.zscore();
    """
   
    combined_factor = -0.3*Asset_Growth_7d_winsorized.zscore() -0.2*sentiment_score_winsorized.zscore() +0.1*eveb_winsorized.zscore() +0.1*cash_return_winsorized.zscore() +0.3*total_yield_winsorized.zscore();
    

    # Build Filters representing the top and bottom baskets of stocks by our
    # combined ranking system. We'll use these as our tradeable universe each
    # day.
    longs = combined_factor.top(TOTAL_POSITIONS//2, mask=universe)
    shorts = combined_factor.bottom(TOTAL_POSITIONS//2, mask=universe)

    # The final output of our pipeline should only include
    # the top/bottom 300 stocks by our criteria
    long_short_screen = (longs | shorts)

    # Create pipeline
    pipe = Pipeline(
        columns={
            'longs': longs,
            'shorts': shorts,
            'combined_factor': combined_factor
        },
        screen=long_short_screen & sentiment_score.notnull() & Asset_Growth_7d.notnull(),
    )
    return pipe