Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
beginner's luck

Any ideas on how to improve this algo are welcomed

4 responses

Literally anything would be better.
Take your $1 million and light it on fire, still better than this algo.

Just joking, take a look at the "Learn" section.

add a pipeline so you're not choosing from a static base of stocks.

def initialize(context):  
    schedule_function(my_rebalance, date_rules.every_day(), time.rules.open_market(hours=1)) #runs def my_rebalance every day one hour after market opens, can be changed  
    attach_pipeline(make_pipeline, 'my_pipeline')

def make_pipeline():  
    base_universe = Q1500  
    #(add factors)  
    #(do factor_variable.rank(mask=base_universe, ascending=False)  
   # (add all factor_ranks)  
    longs = factor_ranks.percentile_between(80,100) #Top 20%  
    pipe = Pipeline(  
        screen = base_universe,  
        columns={  
            'longs': longs  
    }  
)
    return pipe

def before_trading_start(context, data):  
    context.output = pipeline_output('my_pipeline')  
    context.security_list = context.output.index

def my_rebalance(context, data):  
    #(do rebalance stuff)  

The learn section will help you a lot to get the basics down and poking around the API documentation will also help.

Pipelines provide stocks that match what you want and do are well according to indicators. That way if stocks aren't doing well, then they don't pass into your pipeline based on your screen and/or ranking.

Dustin your came back with an error message