Back to Community
Help with Getting Started

Hi all! I would love to be a quant trader when I start working (I haven't even finished highschool yet), so I decided to get ahead of myself, now that I have time with the quarantine and all. I have developed a small conglomerate of factors to filtrate stocks, and I would love if you could help me with it. Please, don't refer me to the to tutorials, as I am not looking for how to do something but what to do, and I am trying to learn that.

  1. Are this bad factors, and if so, how should I change them in your opinion?
  2. What would be a good buying - selling strategy for the algo? Maybe longing every remaining stock in a short period of time with high leverage and selling fast?
  3. And last but not least, any risk models that I should be taking into account?

Thanks in advance, here is the code!

# Import Algorithm API  
import quantopian.algorithm as algo

# Pipeline imports  
from quantopian.pipeline import Pipeline  
from quantopian.pipeline.data.psychsignal import stocktwits  
import quantopian.pipeline.factors as Factors  
from quantopian.pipeline.filters import QTradableStocksUS  
from quantopian.pipeline.data.builtin import USEquityPricing

def initialize(context):  
    # Constraint parameters  
    context.max_leverage = 1.0  
    context.max_pos_size = 0.2

    # Attach data pipelines  
    algo.attach_pipeline(  
        make_pipeline(),  
        'data_pipe'  
    )


def before_trading_start(context, data):  
    # Get pipeline outputs and  
    # store them in context  
    context.pipeline_data = algo.pipeline_output('data_pipe')

# Pipeline definition  
def make_pipeline():  
    baseUniverse = QTradableStocksUS()  
    last_close = USEquityPricing.close.latest  
    sma_2 = Factors.SimpleMovingAverage([inputs = USEquityPricing.close],  
                                        window_length = 2,  
                                        mask = QTradableStocksUS(),  
                                       )  
    sma_5 = Factors.SimpleMovingAverage([inputs = USEquityPricing.close],  
                                        window_length = 5,  
                                        mask = QTradableStocksUS(),  
                                       )  
    sma = sma_2 > sma_5

    sentiment_score = SimpleMovingAverage(inputs=[stocktwits.bull_minus_bear],  
                                          window_length=3,  
                                          mask=QTradableStocksUS(),  
                                         )  
    mean_volume = Factors.SimpleMovingAverage(inputs=[USEquityPricing.volume],  
                                              window_length=90,  
                                              mask = baseUniverse,  
                                             )  
    mean_price_10 = Factors.SimpleMovingAverage(inputs=[USEquityPricing.close],  
                                                window_length=10,  
                                               )  
    mean_price_50 = Factors.SimpleMovingAverage(inputs=[USEquityPricing.close],  
                                                window_length=50,  
                                               )  
    rising_price = mean_price_10 > mean_price_50  
    viable_stocks = baseUniverse & (mean_volume > 500000) & (sma == True) & (sentiment_score > 0) & (rising_price == True) & (last_close > 5) & (last_close < 25)

    return Pipeline(  
        columns={  
            "last close":last_close,  
        },  
        screen=viable_stocks()  
    )