import numpy as np
import scipy as sp
from statsmodels.tsa.tsatools import lagmat
from matplotlib import pyplot as plt
x=sp.randn(100)
y=lagmat(x,5) # creating lag of 5 (this is a matrix of all lags up to 5)
yy=y[:,4].squeeze()
cc=plt.xcorr(x,yy,maxlags=20)
xcor=cc[1]
lags=cc[0]
plt.subplot(211)
plt.grid() 
plt.plot(x,'o')
plt.plot(x)
plt.plot(yy,'o')
plt.plot(yy)
plt.subplot(212)
plt.stem(lags,xcor)
plt.grid()
plt.show()


