Mobile Averages in Python

-1

I would like to know if there is a specific function in Python for calculating moving averages. In MATLAB there is one called "tsmovavg" that has an algorithm called "Financial Time Series". Will the same algorithm exist in Python?

    
asked by fcuturrufo 23.05.2018 в 18:10
source

1 answer

0
list = [1, 2, 3, 4, 5, 6, 7]
N = 3
cumsum, moving_averages = [0], []

for i, x in enumerate(list, 1):
    cumsum.append(cumsum[i-1] + x)
    if i>=N:
        moving_ave = (cumsum[i] - cumsum[i-N])/N
        #Puedes hacer cosas con el promedio movil aquí
        moving_averages.append(moving_ave)
    
answered by 23.05.2018 / 18:50
source