Smoothing and forecasting using the Holt-Winters method
stats package contains functionality for applying the
HoltWinters method for exponential smoothing in the presence of trends and seasonality, and the
forecast package extends this to forecasting. This recipe addresses these topics.
If you have not already downloaded the files for this chapter, do it now and place them in your R working directory. Install and load the
How to do it...
To apply the
HoltWinters method for exponential smoothing and forecasting, follow these steps:
- Read the data. The file has monthly stock prices from Yahoo! Finance for Infosys between March 1999 and January 2015:
> infy <- read.csv("infy-monthly.csv")
- Create the time series object: ...