Oct-01-2017, 05:00 AM
(This post was last modified: Oct-01-2017, 05:00 AM by shivam_hbti.)
I am doing my analysis on time series data using Python. I am also interested in moving averages, to calculate moving averages for my target variable, I used the following function to calculate MA over my target variable.
Now, I want to calculate reduced moving averages. like in the above the averages are being calculated over fixed number, say 90.
But, in case of reduced moving averages, this number will reduce by 1 at each next value. Such as I supplied 90 as the average number, my first MA will average of 90 days, my next calculation will be the average of 89 days and so on.
How can I do this using numpy library in Python?
def movingaverage(values, avg_number): weights = np.repeat(1.0, avg_number)/avg_number smas = np.convolve(values, weights, 'valid') return smasIn this function, I supply my pandas Series and the average number to calc. corresponding averages.
Now, I want to calculate reduced moving averages. like in the above the averages are being calculated over fixed number, say 90.
But, in case of reduced moving averages, this number will reduce by 1 at each next value. Such as I supplied 90 as the average number, my first MA will average of 90 days, my next calculation will be the average of 89 days and so on.
How can I do this using numpy library in Python?