Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
easiest way to resample algo into hourly bars?

What would be the easiest way to resample my algo from trading daily into an intraday strategy using hourly data? I'm mainly trying to resample my customfactors that use daily windows and transition it into hourly windows.

Thanks

2 responses

Unfortunately, if you use pipeline and custom or built in factors, then ONLY daily data can be used. It's the way pipeline is set up and optimized. There's no way to simply say 'run now with hourly data'.

However, that's not to say you need to throw out all your pipeline code. There probably will be a chunk of factors that don't change intraday anyway. Any fundamental data and especially any universe selection (ie Q500US) should be kept as is.

If possible, structure your code so to use pipeline data to filter your universe to only a subset of stocks you want to consider during the day. That initial selection would get done once and run in the 'before_trading' method. Use the 'schedule' function to schedule when to execute your trade logic (or if you want to execute it every minute then put it into the 'handle_data' method). Use the '.history' or '.current' methods to get minutely data in your trade logic. Typically manipulate the data with pandas or numpy or use the Talib libraries for more esoteric tech indicators.

The biggest 'gotcha' in intraday trading is how to check for and handle outstanding orders. One needs to be careful not to 'over order'. Definitely consider using the 'order_optimal_portfolio' method for placing orders rather than the other 'order_target_percent' or similar methods. You lose a bit of control (eg you can only place market orders) however it will take care of the outstanding orders for you. Additionally, making use of constraints can be very powerful (once one get's over the learning curve), and, if you ever get an allocation, the 'order_optimal_portfolio' is required anyway.

Perhaps post your algorithm (or a skinnied version) if you would like help with specific areas.

Good luck.

Thanks for the reply Dan,

My algo is designed for a daily or weekly rebalance, and it utilizes a lot of support, resistance and trend indicators. I was thinking of resampling it just to see what the outcome would be. I'm already running into issues with outstanding orders on my current algo, so I imagine it'd be even more of a pain to handle with intraday trades.