I'm trying to create an indicator which is a function of the asset's past N days of returns. How do I obtain this?
Given that I have:
def initialize(context): context.spy = sid(8554) spy_price = context.spy
I'd like to get the daily returns of SPY, and then create a function which is the average daily return over the past N days. For example, something like this:
spy_returns = (The daily returns of SPY....) spy_returns_ave = spy_returns.rolling(60).mean()
In the end, I want to create an indicator that behaves like this: If spy_returns_ave < x, Buy SPY... etc.