## Pages

### Time Series Forecasting - Part 1 ### Not just ARIMA, but much more

"Time is money and hence time series is equivalent to a treasure!" ... No Einstein or Hawking has said that, it came to my very unpopular mind, while I started writing about time-series.
Ask Analytics is committed to cover the subject in best possible depth and breadth ever, so not just ARIMA, we will explain each and every aspect of time series in a series of articles.
What is time series

Time Series is sequence of value observed of an event on various points of time OR in other words observations in a variable in a time sequence e,g, number of passengers traveled to UAE from India month wise, air quality index measured daily, any stock exchange index at second or minute level. The period interval at which events are measured is called Granularity.

It is assumed about a time series that an observation at a given point of time is not purely independent, it is rather a function or result of its historical value(s). The assumptions serves as a focal point for all the methods used for performing a time series forecasting.

Mathematically:                          V(t) = p V(t-n) + e

The equation says Value(V) at point of time "t" is a function of its n time lagged value i.e value of V at point of time "t-n" with an error (e). Value at time "t" can be dependent on one or various lags of various orders at a time.

Components of time series

There are many components of time series which are needed to me identified in order to decide best suitable method for forecasting. Time series can be decomposed into following components for the analysis purpose:

1. Seasonality : When a series is influenced by a seasonal factor the its fluctuation pattern recurs on a regular basis at equal interval of time. e.g. sales of cold drinks goes up in every summer, sales of cough syrups go up in winters, sales of sweets go up every festive season, sales of candies go up around Halloween etc.

2. Trend: It is any long term continuous increase or decrease in the series, or it could be mix e.g. series first increasing for a while and then decreasing.

3. Lateral Shift: It is a sudden shift from one level to another due to some big change for example any merger or acquisition of a company may lead to lateral shift in sales figures.

4. Cyclicity : significant ups and downs but NOT at a constant time interval.

5. Error: It is the unexplained variation that co-occur with other components in time series. it is totally random without any pattern. It is also called as residual term.

Methods used for time series forecasting

There are N number of methods used for time series forecasting, few of which have recently popped up with new softwares such as Python and R coming in, but historically following are the method being used for forecasting (these methods are the principle behind new methods as well):

1. Moving Average Method

Exponential Smoothing Methods (2nd to 5th)

2. Simple Exponential Smoothing (SES)

5. ARIMA (acronym for Auto Regressive Integrated Moving Average)

You can click on the above links to navigate through other articles in this series

All above listed methods just work on one time series at a time and forecast it; being univariate methods are unable to consider any other factor involved. Hence comes a method that takes multiple time series together into account and forecast the principle time series.

6. VARIMA (Vector ARIMA)

Excited? Well, there seems to be a good enough reason for that.

So let's learn the first and most rudimentary method of time series forecasting as a warm-up, we need to run a long marathon this time.

Moving Average Method

It is average with previous consecutive values in a time series. Moving average can be calculated at various orders. You can simply calculate the moving average in Excel or can use Proc Expand in SAS.

In SAS (do follow the link of Proc Expand for better understanding)

Proc expand data= Demo out= new_demo;
convert sales = sales_movave / transformout=(movave 3);
run;

In Excel, using basic formula:

Let's say we have a series Sales :

We will take average of 3 previous observation to calculate a third order moving average. First observation remains as such, second one would be average of first two observations and third onward it would be average of three terms.

And we get a series like this, we extend the series on one level ahead a get a forecast for next month.

Goodness of forecast:
The goodness of forecast is calculated in form of RMSE.

We calculate errors, square, take average and then calculate square root of the same. We calculate moving average of various orders and take the one with least RMSE.

Download the following file to see the calculations : Moving Average Calculation file

The method is definitely not very evolved and logical and hence is not used by the analytics people, but the method is very important to learn, as it used as input in ARIMA.

Rest of the methods we will be explained in a series of articles, till then ...

Enjoy reading our other articles and stay tuned with ...

Kindly do provide your feedback in the 'Comments' Section and share as much as possible.

The article has been written by Suyash Nigam with Rajat Agarwal as a co-author.