Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
1 minute history now available

The history() function has been extended and now supports trailing windows of one minute granularity. This was a popular request and we’re excited to expand the feature.

As a reminder, history() is a function that returns price and volume information for a trailing window of data. Before today, we only supported day-level, or ‘1d’ values. Now, we support '1m' values. The remaining syntax is the same.

This feature now enables a number of ideas to be easily implemented. For instance, you can create a vwap, or moving average, or other transform on much shorter time frames using minute bars. You can also inspect the minutes before market close or after the open, if that interests you.

For example the code below returns the last 20 minutes of the stock price as a pandas dataframe:

history(20, 1m’, price’)  

This is one step closer to deprecating batch_transform().  If you're using batch_transform to generate trailing windows in minute mode, you should consider changing the code over to history().

The attached example compares the 90 minute VWAP to the 30 minute VWAP for a stock. Happy coding!

Disclaimer

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances.

12 responses

Thanks! --Grant

Time to throw a party!

Quick question on the TA usage. I can use this to compute on all sids?

import talib

def initialize(context):  
    context.my_sid = [sid(24), sid(1234)]

def handle_data(context, data):  
    price_history = history(bar_count=30, frequency='1d', field='price')  
    ema_result = talib.EMA(price_history)  

Also if I am to use TA Lib functions like ATR (use H, L, C), MFI (Use C, V) how is this expressed in code?

great feature. However, is there a way to backfill NA values (to deal with cases where the first element of the vector happens to be 'NA')?

A runtime error results for bar_count = 1. Is this the expected behavior or a bug? --Grant


def initialize(context):  
    context.stocks = [sid(8554)] # SPY

def handle_data(context, data):  
    prices = history(2,'1m','price')  
    # prices = history(1,'1m','price') # Runtime Error "IndexError: index out of bounds"  

Hi Grant,

I cloned and re-ran your posted algorithm from 2014-06-19 to 2014-06-20 and didn't get the IndexError mentioned in your comment. Are you still seeing this behavior with the code you posted, or is there a more complex setup necessary to repro the error?

Thanks,
-Scott

Disclaimer

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances.

Also, to answer your original question a 1m history of length one should return data for the current minute.

Thanks Scott,

This code crashes for the range of dates in my backtest above:

def initialize(context):  
    context.stocks = [sid(8554)] # SPY

def handle_data(context, data):  
    # prices = history(2,'1m','price')  
    prices = history(1,'1m','price') # Runtime Error "IndexError: index out of bounds"  

Let me know if you need more info.

Grant

Ah, looks like it's only crashing if you only have length-1 history with no length-2 entries (I ran my test with both lines uncommented). I'll take a look at what's happening here.

Yep, there's a bug in the HistoryContainer logic that special-cases a single length-1 1m history for a field. Bugfix has been posted to https://github.com/quantopian/zipline/pull/354 and should make its way to Quantopian relatively soon.

UPDATE: This is fixed on zipline/master as of https://github.com/quantopian/zipline/commit/6a2ee7c417440d59c59bc9430ef4394384cc912e

Thanks for the bug report!

Wow -- that's great!

Looking forward to using a 15 minute indicator.