How can one query historical minute bar data going back many months for a symbol?

superquantsuperquant Posts: 28
edited March 2017 in Under The Hood

I am implementing a statistical arbitrage model and I would like to utilize 1 minute bar data from several months ago in my computation for the current day. How can I access the corporate action adjusted one minute bars from several months ago?

Comments

  • superquantsuperquant Posts: 28
    edited March 2017

    You can use the following to query historical minute bars.

    md.bar.load_minute_bars(days=217, apply_corporate_actions=True)

    Keep in mind this is a relatively expensive query so you will want to do it in on_start() or on_strategy_start()

  • jsmchangjsmchang Posts: 6

    Thanks. I have given it a try. I ran something like this:

    min_data = md['EEM'].bar.load_minute_bars(days=3), and also
    min_data = md['EEM'].bar.load_minute_bars(days=3, apply_corporate_actions=True)

    I thought the api would return an object similar to that from md.bar.minute_by_index, which returns the minute bar close in min_data.close. But it looks like that attribute does not exist, and thus I got an error:

    AttributeError: 'NoneType' object has no attribute 'close'

    It would be helpful if I can get some guidance on how to access the minute bar data from the returned object.

    Thanks.

  • In order to load minute bars you should first define how many days back you would like to query and if you would like corporate actions applied or not as shown below.

    def on_start(self, md, order, service, account):
            md.bar.load_minute_bars(days=5, apply_corporate_actions=True)
            bars = md.bar.minute(-1561, today_only=False)
            print len(bars.open)
    
Sign In or Register to comment.