Any ideas on how to improve this algo are welcomed
Any ideas on how to improve this algo are welcomed
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.