Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
How to Do a 1 Time Purchase?

Newb here.

I have 10 pre-selected stocks that I want to go Long at the beginning of my backtest.
Is there a way I can use the "schedule_function" for a 1 time purchase using the "date_rules" or something similar?
If there is another way beside that I am open to any method, "schedule_function" is just the only way I know to trade when the market is actually open.

2 responses

Brent ,
Try this:

# ------------------------------------------------------------------------------------  
ASSETS = symbols('XLV', 'XLK', 'XLI', 'XLP', 'XLE', 'XLU', 'XLB', 'XLY', 'XLF', 'TLT')  
LEV, WT =  1.0,  [0.06,  0.06,  0.06,  0.06,  0.06,  0.06,  0.06,  0.06,  0.06,  0.46]  
# ------------------------------------------------------------------------------------  
def initialize(context):  
    context.invested = False  
    schedule_function(trade, date_rules.every_day(), time_rules.market_open(minutes = 65))

def trade(context, data):  
    if context.invested: return  
    for asset in ASSETS:  
        order_target_percent(asset, LEV*WT[ASSETS.index(asset)])  
        context.invested = True  

So far so good. Thank you very much. I tried something similar but couldn't get it to work. Guess I still need to work on my python skills =D