Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Minute backtest in reasearch

I get the error: "Requested history at frequency 'm' cannot be created with data at frequency 'daily'." when I try to run this. Any ideas?

import talib as ta  
import numpy as np  
import pandas as pd

import zipline  
from zipline import TradingAlgorithm  
from zipline.api import symbol, history, add_history

data = get_pricing(  
    ['SPY'],  
    start_date='2015-07-06',  
    end_date = '2015-07-07',  
    frequency='minute')

def initialize(context):  
    add_history(200, '1m', 'price')  
    context.i = 0  
def handle_data(context, data):  
    context.i += 1  
    if context.i < 200:  
        return  
    history('200','1m','price')  
algo_obj = TradingAlgorithm(  
    initialize=initialize,  
    handle_data=handle_data  
)

algo_obj._analyze = analyze

perf_manual = algo_obj.run(data.transpose(2,1,0))  
2 responses

I don't know what the official way of doing minutely backtests in research is, but you can do a nasty hack: https://www.quantopian.com/posts/minute-backtest-not-working-with-research-platform

(the situation may have changed since May)

You just have to specify the 'data_frequency' when you initialize the TradingAlgorithm. Your code should work if you use the following initialization.

algo_obj = TradingAlgorithm(  
    initialize=initialize,  
    handle_data=handle_data,  
    data_frequency='minute'  
)