So lag1 should correspond to your y value in t-1. so compare. I think expanding starts at the beginning of your series and computes a metric for all time steps. Let’s say expanding max() should look at each step and find the max value it has seen so far. So if you have y[2,4,1,3], your expanding max should be: [2,4,4,4]. Does this help a bit?