Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Access historical data outside handler_data

Hi,

I have some problem to access my data outside handler_data. In this example I make a schedule to check for new high at the end of each month but the function newHigh cannot access prices_hist. It says xiv doesn't has attribute .max. How can I do that ? I understand history() must be in data_handler and nowhere else.

Thank's
Florent

def initialize(context):  
...
    schedule_function(  
                      func=newHigh,  
                      date_rule=date_rules.month_end(days_offset=2),  
                      time_rules.market_open(minutes=15)  
                      )  
def handle_data(context, data):  
    #Store historical data  
    prices_hist = history(21, '1d', 'price')  
    spy = prices[context.spy]  
    xiv = prices[context.xiv]

...

def newHigh(context, data):  
    if xiv.max > context.old_max:  
        print('new high')  
        return            
1 response

Perhaps you could use context.prices_list instead of local variable...