Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Bar spread average

I'm trying to calculate the moving average for the past y (let's say y=50) bars spreads.
I've tried two different ways, but to no avail:

Method 1:

    last_i_highs = history(50, '1d', 'high')  
    last_i_lows = history(50, '1d', 'low')  
    average_spread = last_i_highs.values - last_i_lows.values  
    average_spread = average_spread.mavg(30)  

Method 2:

last_i_highs = history(50, '1d', 'high')
last_i_lows = history(50, '1d', 'low')
average_spread = []
for i in range(50):
average_spread.append(last_i_highs - last_i_lows)
average_spread.mavg(50)

What would be the best way to do so?
Thank you

1 response

Solved it.
Instead of using .mavg I used .mean() . I guess I just needed more coffee (: