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

Hi,

I'm new to Quantopian.
I want to create a strategy which I want it to do massive calculation after market close (rather than running it real time due to computing time issue I guess). The calculation will generate a number of parameters for each of the stocks in my pool, which it will use in real time monitoring. So it needs to save the parameters to be used in the next trading day, and keeps updating each day (after market close).

My understanding is that I need to do this in the make_pipeline function? Can someone confirm?
I checked some sample algos but seems people only use make_pipeline to select candidate stocks to trade but not generating and saving parameters?

If I use make_pipeline, how to let it run after market close on a daily basis? There is a scheduled function on market close but not really after market close...

I can see there is a before_trading_start function that will run before market open? Should I use this function instead?

These questions maybe dumb, but thanks for your help!

Wei

3 responses

Anyone? Thanks!!

@ Wei Jiang

First of all welcome.

So in no particular order..

Yes, after market close is identical to 'before_trading_start'. Any code placed in that method will run after all data has been updated from the previous day. The data is also adjusted for any splits that may have occurred. Also, the 'before_trading_start' method gets allotted a bit more compute time than any scheduled or 'handle_data" methods. Part of the reason for this is that the later tasks all need to happen within one bar, or minute, to be valid. The 'before_trading_start' method doesn't need to process within a 1 minute bar (it's before trading).

Anything you want to run after market close should be in 'before_trading_start'. You can use the pipeline structures (eg built in methods and filters) to get any of the data you need to feed your buy/sell logic. You aren't required to use pipeline. You could use the 'get_fundamentals" or 'get_history' methods. However, the pipeline approach optimizes the data fetches (runs faster) and gives you a lot of built methods to easily manipulate the results. Stick with pipeline unless there is some compelling reason not to.

The one comment you made "use make_pipeline to select candidate stocks to trade but not generating and saving parameters?" isn't entirely true. You can filter stocks within the pipeline paradigm but that is not required. The real beauty of using the pipeline approach is that it returns a simple powerful Pandas Dataframe of all the data or calculated data you want returned. The rows are indexed by security. The columns are whatever you specify when creating your pipe. This dataframe also has access to all the convenient Dataframe methods.

One caution. You wrote *'So it needs to save the parameters to be used in the next trading day, and keeps updating each day (after market close) * . Don't EVER save price or volume related data across trading days. Data is good for the day only. Any stock splits (which happen more than you would expect) won't be accounted for in saved data. The pipeline output, however, always accounts for stock splits.

Dan, Thank you very much! Very helpful!
This is exactly what I wanted to know and even more on the pipeline structure and the caution in before_trading_start...
Thanks again!