I applied a different data set to Joshua Ulrich's answer at previous question (Automatic vlookup and multiply coefficients with R) and it gives an error I haven't been able to solve.
New dataset:Brazil's Bovespa index
(sp<-read.csv("http://www.bolsapt.com/download/historico/%5EBVSP/de-01-01-2000-a-04-02-2013/")
spLag <- lag(sp)
Error in hasTsp(x) : invalid time series parameters specified
Best regards