What would be the best way to shift the periods used to calculate the moving average back by x periods? I'm trying to get what the moving average for the previous say essentially to find out which direction its moving in.
Thanks!
What would be the best way to shift the periods used to calculate the moving average back by x periods? I'm trying to get what the moving average for the previous say essentially to find out which direction its moving in.
Thanks!
All right, my quick hack will be like this:
1, use the @batch_transform function to return the current pointwise value of the mavg.
Say today, the batch_transform looks back for 10 days and average the close prices, returning a value of 455 for the apple.
2, store it in a list
something.append(this value)
3, retrieve a few periods back if you want, for today's evaluation.
myValue = something[ - 3 ]
Did I get your point correctly?
Jiaming Kong,
I have tried taking a stab at it and attached is a backtest for my solution. The the problem I am trying to solve is retrieving what yestersday's value for the call data[sid(X)].mavg(5) yeilds so I can compare it to the value that that same call yeilds when I make it today. That way I can say to some degree which way the mavg is trending. Does that make sense?
I was looking at the information that the API reference provides on the @batch_transform decorator and could not tell if it is what wanted.
To use some code to hopefully describe what I ultimately want to achieve would be:
if mavg_tMinus11_to_tMinus1 < data[sid(X)].mavg(10):
# the 10 mavg is trending up
else:
# the 10 mavg is trending down
Thanks!