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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.