# How to decide moving window size for time series prediction?

I have a model to predict +1 day ahead of this time series.

Looking at the chart you can notice some seasonality every 5 days. I suspect using a moving window as training set could help me making a better prediction.

However I want to programmatically find the best Moving Window Size for my model. Are these approaches below valid? Should I do something different?

Approach 1. I run the model on the historical data, with any possible Window Size, I pick the window size that minimises the prediction error. This approach is simple and fast, but I am afraid it overfits the Window Size to historical that. Right?

Approach 2. I use cross-validation (LOOCV) to get a more realistic prediction error. Is this better/worse than Approach 1?

• Window size for what model? What role does window size play in your model? What are you trying to achieve with your analysis? Give us more information about the context.
– Tim
Sep 11, 2018 at 12:44
• I am dealing with a similar problem at the moment, that is how best to pick a window size. Which approach did you go with and what were your results?Did you encounter any problems using cross validation to tune your models for time series data at all? Nov 22, 2018 at 6:47
• @Aesir at the end I chose Approach 3 (not-listed above 😛) I simply do a walkforward analysis. At time t, I find the window size that works best on the past data points $x_0$ to $x_{t-1}$, then I use that window size to predict $x_t$. This approach resembles best what happens in reality, where I run my algorithm every day, to predict the following day. In my case, with this approach, it turned out that no window size worked. So I reverted to using no window at all, rather just using all the past data from 0 to t-1. Nov 22, 2018 at 11:14
• Thanks. So to be clear you took iterated through every window size possible on your data and for each window size performed a walkforward analysis. Then you computed an average accuracy for each window size and then used that to pick a final window size that worked for your case? Nov 22, 2018 at 12:15
• Exactly- everyday I iterated all possible windowsizes and picked the one that worked best that day. The next day all over again Nov 22, 2018 at 13:26