Hello. I am modifying the Mean Reversion Algorithm and am having trouble with the pandas iloc function. I am turning the algorithm into a daily mean reversion algorithm.
How could I change this (for 5 days price history):
context.returns_lookback = 5
prices = history(context.returns_lookback, '1d', 'price')
# Calculate the past 5 days' returns for each security.
returns = (prices.iloc[-1] - prices.iloc[0]) / prices.iloc[0]
Into a function just for one day.
I have this
context.returns_lookback = 1
prices = history(context.returns_lookback, '1m', 'price')
# Calculate the past 1 days' returns for each security.
returns = (prices.iloc[-1] - prices.iloc[0]) / prices.iloc[0]
but know the iloc function is still running for 5 days.
Any help is much appreciated.