Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Before Trade Starts On First Day Of Algo Deployment

Wondering if there is a way to get history function data for the end of the trading day prior to the first day of deploying in an algo? In my code below I set up the algo to get history data in the before_trade_start function, but I noticed that it is not returning the data from the prior day until actual trade data has occurred within the algo. So for all intensive purposes the history function in before_trade_start does not work until the second trading day. I thought I could just fix it by putting a history function in the initialize function, but that caught an error. Any suggestions?

3 responses

Hello Frank,

Why not just call history() in handle_data()? There are a couple downsides:

  1. Instead of 5 minutes of compute time, you are limited to 50 seconds.
  2. The computation of your signal based on the data from history() will delay subsequent orders (e.g. if you are trying to get orders in as close to the open as possible).

It is a bit inelegant, but on the first day of trading, you could call history() in handle_data() but call it in before_trading_start() thereafter.

Also, note the behavior if price is used (see attached).

Grant,

Thanks for the response. Gave me an idea. I will just add a counter to increment for each trading day and only utilize the history function data when the counter is at 0 using an if statement. Appreciate the help!

Also, note that it sounds like history() will be disabled in before_trading_start() (see https://www.quantopian.com/posts/history-api-available-in-before-trading-start). You can still get the data in there, by using context, just in case you ever need more than 50 secs. compute time on minute data.