Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Grab data history for a computed field

Hi,

I'm looking to build an algorithm based on a specific value of the closed price. Actually I would like to backtest this algorithm based on the : (high + low + 2 * close)/4 price.

How can I past this value in the data.history() method to backtest the algorithm for the last year and a half ?

Thanks

2 responses

This may help you.

# --------------------------------------  
stk, ma_f, ma_s = symbol('SPY'), 10, 100  
# --------------------------------------  
def initialize(context):  
    schedule_function(record_my_prices, date_rules.every_day(), time_rules.market_close())    

def record_my_prices(context, data):  
    prices = data.history(stk, ['high','low', 'close'], ma_s, '1d')  
    H = prices['high']  
    L = prices['low']  
    C = prices['close'] 

    my_prices = (H + L + 2*C) / 4  
    mavg_f = my_prices[-ma_f:].mean()  
    mavg_s = my_prices.mean()  

    record(C = C[-1], my_prices = my_prices[-1], mavg_f = mavg_f, mavg_s = mavg_s)  

Thanks @Vladimir , You Rock !