Here's another test case that results in:
There was a runtime error.
MemoryError
Algorithm used too much memory. Need to optimize your code for better performance. Learn More
Note that I am pulling 20 days of minutely data across ~8000 stocks: 62.4 million price values. How many can Q2 support? If it is 8 bytes per point (see Scott's comment, Oct 12, 2015, https://www.quantopian.com/posts/introducing-the-pipeline-api), then it would only take 0.5 GB of RAM, so I don't understand the memory overflow problem.
from quantopian.algorithm import attach_pipeline, pipeline_output
from quantopian.pipeline import Pipeline
from quantopian.pipeline.data.builtin import USEquityPricing
from quantopian.pipeline.factors import CustomFactor
class OvernightGap(CustomFactor):
inputs = [USEquityPricing.open,USEquityPricing.close]
window_length = 2
def compute(self, today, assets, out, open, close):
out[:] = 100*(open[-1,:] - close[0,:])/close[0,:]
def make_pipeline():
pipe = Pipeline()
gap = OvernightGap()
pipe.add(gap, "gap")
return pipe
def initialize(context):
attach_pipeline(make_pipeline(), 'example')
schedule_function(place_orders,
date_rules.every_day(),
time_rules.market_open(hours=1))
def before_trading_start(context,data):
context.output = pipeline_output('example')
context.security_list = context.output.index
prices = data.history(context.security_list, 'close', 20*390, '1m')
def handle_data(context,data):
pass
def place_orders(context,data):
for stock in context.security_list[0:10]:
order(stock,1)
# prices = data.history(context.security_list, 'close', 20*390, '1m')