Anyone ever have trouble getting custom intraday bars (e.g. 15-minute or 30-minute bars)? Q gives you access to one-minute bars via the data.history() function that you can easily turn into any bar length that you want. Thank you pandas! This tripped me up when I got started, so hopefully it can help some of you out there.
The attached algo is setup to get variable minute bars for Apple. It logs the one-minute bars and logs the custom bars so that you can easily check to see if the bars are calculated correctly. A couple of key points:
- How to call a function every x minutes of the trading day (lines 24-27).
- How to use the pandas DataFrame resample function (lines 51-60).
For those that want a detailed description for how this works, you can see my write up on this.
Thanks,
Aaron