I have 2 graphs that follow a similar trend (commodity prices) - with one lagging in time from the other. Shapes are not congruent but similar. I would like to calculate the average lag in time. Any superb ideas? Thanks very much!

Do you mean the lag such that the sum of squared differences in corresponding y values is minimized? (or some other reasonable distance metric) define a cell “lag” that can take on values of your time dimension, define the distance metric as a function of lag, use a data table to calculate distance metric for all lags, find the minimum value. Given that distance is probably neither monotonic nor differentiable in lag, I don’t see a quicker solution here. (and the solution above takes around 2 minutes to code up)

A=array{a1,a2,a3,…} B_lagged=array{b1,b2,b3,…} define B(i)=array{bi,bi+1,bi+2,…} for i=1,2,… define D(i)=|A-B(i)|=(a1-bi)^2+(a2-bi+1)^2+(a3-bi+2)^2+… find the i such that D(i) is minimum