Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Extracting List Data Into Hashable Type

I am setting up an algorithm that mimics bar data to eventually deploy various technical trading strategies. In order to do this I am using the history function. For instance, I mimic daily bar data as shown in the code below and then store the bar data from the respective time period into their own variables. I am wondering if anyone can help me think of the best way to extract that data into something hashable that I could then use to drive trade logic? My Python capabilities seem to turn off on Friday evenings so any suggestions would be appreciated.

def handle_data(context, data):

# Use history function to get bar level data
high_history = history(bar_count=2, frequency='1d', field='high')
low_history = history(bar_count=2, frequency='1d', field='low')
open_history = history(bar_count=2, frequency='1d', field='open_price')
close_history = history(bar_count=2, frequency='1d', field='close_price')

# Store prior and current data into variables  
prior_high = high_history.iloc[-2]  
current_high = high_history.iloc[-1]  
prior_low = float(low_history.iloc[-2])  
current_low = float(low_history.iloc[-1])  
prior_open = float(open_history.iloc[-2])  
current_open = float(open_history.iloc[-1])  
prior_close = float(close_history.iloc[-2])  
current_close = float(close_history.iloc[-1])  
1 response

Hi Frank,

You'll need to use context. For example, in initialize, create an empty list, context.high=[] and then append to the list, every time handle_data is called.

Note, however, that this would seem unnecessary, since history will provide an up-to-date trailing window. See the help docs for a description of how it works.

Grant