Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Using data.history in initialize

Hi everyone,

I am trying to call on yesterday's S&P 500 by using data.history in my initialize function.
However, it seems that the data. does not work in initialize.

def initialize(context):  
    context.spy=sid(8554)  
    data.history(context.spy,'price',2,'1d')  

When I run the code above I get an error saying

  • Undefined name 'data'

Is anyone else having this issue?
Thank you for your help in advance.

3 responses

Hey Luke,

I was trying to do some similar things a while back. These threads are sort of similar to your issue.

https://www.quantopian.com/posts/before-trade-starts-on-first-day-of-algo-deployment
https://www.quantopian.com/posts/history-api-available-in-before-trading-start

Thanks Frank!

I defined a new function with context and data as input and it allows me to use data.history

Luke,

Ok that makes sense. The initialize function does not pass the data argument, so I think it is safe to assume it will work anywhere but def_initialize. (I have been wrong in the past though).

Good luck with your algos!