Xi = np.array([1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5])
N = np.size(Xi)
k = 5
Xs = np.average(Xi)

def autocovariance(Xi, N, k, Xs):
    autoCov = 0
for i in np.arange(0, N - k):
    autoCov += (Xi[i + k] - Xs) * (Xi[i] - Xs)
return 1 / (N - 1) * autoCov

def autocorrelation():
    return autocovariance(Xi, N, k, Xs) / autocovariance(Xi, N, 0, Xs)
print(('Autocovariance:', autocovariance(Xi, N, k, Xs)))
print(('Autocorrelation:', autocorrelation()))
How to calculate auto-covariance in Python