Smoothing and forecasting using the Holt-Winters method

The 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.

Getting ready

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 forecast package.

How to do it...

To apply the HoltWinters method for exponential smoothing and forecasting, follow these steps:

  1. 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")
  2. Create the time series object: ...

Get R: Recipes for Analysis, Visualization and Machine Learning now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.