Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 59

Lecture-28-32

An overview of forecasting tools and techniques


ACC 501 (Unit 3)

Financial Reporting, Statements


and Analysis

Dr. ARPIT SIDHU


(Ph.D, UGC-NET, HP-SET, MBA,
MCOM, BCOM)
Learning Outcomes:

• Application of Moving average model for


forecasting
Lecture outline

• Introduction of Auto Regressive Moving Average Model (ARIMA),


• Regression & Moving average models
What Is a Time Series?

• A time series is a data set that tracks a sample over time.


• In particular, a time series allows one to see what factors influence certain
variables from period to period.
• Time series analysis can be useful to see how a given asset, security, or
economic variable changes over time.
Examples of time series data include:

Quarterly Annual
Daily IBM Monthly
sales results Google
stock prices rainfall
for Amazon profits
Time series patterns
One more
Uses of Time Series

• The most important use of studying time series is that it helps us to


predict the future behaviour of the variable based on past experience

• It is helpful for business planning as it helps in comparing the actual


current performance with the expected one
Measurements of Trends

Following are the methods by which we can measure the


trend.

(i) Freehand or Graphic Method.

(ii) Method of Semi-Averages.

(iii) Method of Moving Averages.

(iv) Method of Least Squares.


Freehand or Graphic Method.

It is the simplest and most flexible method for estimating


a trend. We will see the working procedure of this
method.

Procedure:

(a) Plot the time series data on a graph.

(b) Draw a freehand smooth curve joining the plotted


points.
Freehand or Graphic Method.

Procedure:

(c) Examine the direction of the trend based on the


plotted points.

(d) Draw a straight line which will pass through the


maximum number of plotted points.
Example

Fit a trend line by the method of freehand method for


the given data.
Solution
Method of Semi-Averages

In this method, the semi-averages are calculated to find out the trend values. Now, we will
see the working procedure of this method.

Procedure:

(i) The data is divided into two equal parts. In case of odd number of data, two equal parts
can be made simply by omitting the middle year.

(ii) The average of each part is calculated, thus we get two points.
Method of Semi-Averages

Procedure:

(iii) Each point is plotted at the mid-point (year) of each half.

(iv) Join the two points by a straight line.

(v) The straight line can be extended on either side.

(vi) This line is the trend line by the methods of semi-averages.


Example

Fit a trend line by the method of semi-averages for the given data.
Solution

Since the number of years is odd(seven), we will leave the middle year’s production value
and obtain the averages of first three years and last three years.
Method of Moving Averages

Moving Averages Method gives a trend with a fair degree of accuracy. In this
method, we take arithmetic mean of the values for a certain time span. The
time span can be three-years, four -years, five- years and so on depending on the
data set and our interest. We will see the working procedure of this method.
Method of Moving Averages

Procedure:

(i) Decide the period of moving averages (three- years, four -years).

(ii) In case of odd years, averages can be obtained by calculating,

(iii) If the moving average is an odd number, there is no problem of centering it, the average
value will be centered besides the second year for every three years.
Method of Moving Averages

(iv) In case of even years, averages can be obtained by


calculating,
Method of Moving Averages

(v) If the moving average is an even number, the average of first four
values will  be placed between 2 nd and 3rd year, similarly the average of the
second four values will be placed between 3rd and 4th year. These two
averages will be again averaged and placed in the 3rd year. This continues
for rest of the values in the problem. This process is called as centering of
the averages
Method of Least Squares

The line of best fit is a line from which the sum of the deviations of various
points is zero. This is the best method for obtaining the trend values. It
gives a convenient basis for calculating the line of best fit for the time
series. It is a mathematical method for measuring trend. Further the sum of
the squares of these deviations would be least when compared with other
fitting methods
Defining the Moving Average Model for Time
Series Forecasting
• One of the foundational models for time series forecasting is the moving
average model, denoted as MA(q).
• This is one of the basic statistical models that is a building block of more
complex models such as the ARMA, ARIMA, SARIMA and SARIMAX
models.
• A deep understanding of the MA(q) is thus a key step prior to using more
complex models to forecast intricate time series.
Time series regression models
For example, we might wish to forecast monthly sales Y using total advertising spend X as a
predictor. Or we might forecast daily electricity demand Y using temperature X1 and the day of
week X2 as predictors.
The forecast variable Y is sometimes also called the regress and, dependent or explained
variable. The predictor variables X are sometimes also called the regressors, independent or
explanatory variables.
Simple linear regression
In the simplest case, the regression model allows for a linear relationship between
the forecast variable y and a single predictor variable x :
yt=β0+β1xt+εt
An artificial example of data from such a model is shown in Figure 5.1. The
coefficients β0 and β1 denote the intercept and the slope of the line respectively. The
intercept β0 represents the predicted value of y when x=0. The slope β1 represents the average
predicted change in y resulting from a one unit increase in x
Ploting
Univariate Forecasting ARIMA
35,000
Forecast for Nifty 50
monthly data 30,000

25,000

Refer Excel
20,000

15,000

10,000

5,000

0
08 10 12 14 16 18 20 22 24 26 28 30

ARIMA CURVEF EXPONENTIALF


NIFTY TRENDF
Lecture content
Trend forecasting

Curvilinear trend forecasting

Exponential trend Forecasting

ARIMA Forecasting

AR, MA & I time series

Static vs Dynamic forecasting

Diagnostic
1) Trend forecasting
If yt is a time series variable, the 24,000

presence of a long-term trend in the 20,000


series can be analyzed with the help
of following eq 16,000

12,000
Where, ‘Time’ is the time variable and
its slope coefficient (beta) represents 8,000

the long term trend in the series. If the 4,000

p value of t stats is less than 5% level


0
of significance, it indicates the 08 10 12 14 16 18 20 22 24 26 28 30

presence of a statistically significant TRENDF NIFTY

long term trend in the time series.


E-views

• Open eviews- Open nifty monthly data- Select nifty and time-
open as equation- Change period to june2022-coefficient
shows trend (means nifty change –per month)-Click forecast-
name new series as trend- change forecast period to July 2022
to December 2030-run-got forecast series-open nifty and trend
series as group-view graph-
2. Curvilinear Trend Forecasting
35,000
Curvilinear trend in the behaviour of a
time series can be analyzed with the help 30,000
of following eq
25,000

20,000

15,000
The slope coefficient (beta) of the time2
term represents the curvilinear trend in 10,000
the series. If the p value of t statistic is less
than 5% level of significance, it indicates 5,000
the presence of a statistically significant
0
long term trend in the time series. 08 10 12 14 16 18 20 22 24 26 28 30

CURVEF NIFTY
E-views

• Open eviews- Open nifty monthly data- Select nifty and time-open as
equation-ADD one more variable time2 - Change period to june2022-
coefficient shows trend (means nifty change –per month)-Click
forecast-name new series as trend- change forecast period to July
2022 to December 2030-run-got forecast series-open nifty and trend
series as group-view graph-
3. Exponential (Growth) Forecasting
35,000

Similarly, the exponential growth rate (EGR) of a 30,000


series can be estimated with the help of
following model: 25,000

20,000

15,000
The slope coefficient (beta) of the regression
model represents the value of the growth rate of 10,000

the time-series variable. If the p value of t


5,000
statistic is less than 5% level of significance, it
indicates that the growth rate of the time series 0
variable is statistically significant. This model is 08 10 12 14 16 18 20 22 24 26 28 30

also known as semi-log model. NIFTY EXPONENTIALF


Eview

• Open eviews- Open nifty monthly data- Select nifty and time-open as
equation-ADD log to nifty only- Change period to june2022-coefficient
shows trend (means nifty change –per month)-Click forecast-name
new series as trend- change forecast period to July 2022 to December
2030-run-got forecast series-open nifty and trend series as group-
view graph-
Time Series Forecasting can also be done on the basis of

• Past momentum/inertia
(Auto Regressive
Behaviour)

• Impact of the Market


Sentiments or mood of
the market (Moving
Average Behaviour)
Information asymmetry
Autoregressive processes (girlfriend mood-stable)

An AR model is one where the current value of a variable y, depends upon only the
values that the variable took in previous periods plus an error term. An AR model of
order p, denoted as AR(p), can be expressed as

Yt = u + Φ1 yt-1 + Φ2 yt-2 + …….. + Φp yt-p + ut  

• This work with stable series (gold, interest rate, gdp,)


• where ut is a white noise disturbance term. The expression of AR(p) model can be
written more compactly using sigma notation
Moving average processes (girlfriend mood-
unstable)

Let ut be a white noise process with zero mean & constant variance σ2. Then

yt = µ + ut + θ1ut-1 + θ 2 ut-2 + . . . + θq ut-q


 
is a MA(q) model.
Simulations of AR & MA Time Series

• White Noise = Norminv(rand(), 0,1) (0 mean Constant variance random behavioir)


• Random Walk = lag 1 + white noise
• Random walk with drift = lag1 + WN + 0.05
• AR1 = lag1 *0.8 + white noise
• AR2 = lag1*0.4 + lag2 *0.3 + white noise
• AR3 = lag1*0.3 + lag2 *0.25 + lag 3*0.15 + white noise
• MA1 = WN + 0.8 *WN(lag1)
• MA2 = WN + 0.4*WN(lag1) + 0.3*WN(lag2)
• MA3 = WN + 0.3*WN(lag1) + 0.25*WN(lag2) + 0.15 *WN(lag3)
Open eviews

• Click ar1- view-graph-view-correlogram-understand Autocorrelation and partial


correlation(remove intermediate effect) (yt-yt-1-yt-2)-test AR2-test AR3-test
MA her Auto correlation is imp-test MA2-test MA3

• Autocorrelation- Autocorrelation refers to the degree of correlation of the


same variables between two successive time intervals.Corr of Yt-Yt-1, Yt-1-Yt-2
• Partial Autocorrelation-a summary of the relationship between an observation
in a time series with observations at prior time steps with the relationships of
intervening observations removed Corr of Yt-Yt-2 (Yt-1 removed)
How many AR and ma

• AR term depend upon Partial correlation



• MA term depend upon Autocorrelation
ARMA (p,q) processes
 obtained by combining the AR(p) & MA(q) models.

 States that the current value of some series y depends linearly on its own
previous values plus a combination of current and previous values of a white noise
error term.

 The model could be written

Yt = u + Φ1 yt-1 + Φ2 yt-2 + ……..+ Φp yt-p +


θ1 ut-1 + θ2 ut-2 + …..+ θq ut-q + ut
Is a ARMA (p, q)m model
ARIMA models
• ARIMA models provide another approach to time series forecasting.
• Exponential smoothing and ARIMA models are the two most widely used
approaches to time series forecasting, and provide complementary approaches to
the problem.
• While exponential smoothing models are based on a description of the trend and
seasonality in the data, ARIMA models aim to describe the autocorrelations in the
data.
ARIMA
If we combine differencing with autoregression and a moving average model, we
obtain a non-seasonal ARIMA model. ARIMA is an acronym for AutoRegressive
Integrated Moving Average (in this context, “integration” is the reverse of differencing).
The full model can be written as

where y′t is the differenced series (it may have been differenced more than once). The
“predictors” on the right hand side include both lagged values of yt and lagged errors.
We call this an ARIMA(p,d,q) model, where

p=p= order of the autoregressive part;


d=d= degree of first differencing involved;
q=q= order of the moving average part.
ARIMA in E-views
• Open Nifty in Eviews- Check NIFTY has unit root or not-view-unit root-
Series is non-stationary- Generate series at first difference-click
generate –nifty_ret = dlog(nifty)-go to corrlelogram- Check patial and
auto correlation- Select quick- estimate equation- dlog(nifty) c ar(1)
ma(1) – test up to minimum AIC- then click forecast- change date- run
–then check it with nifty series
ARIMA forecasting in R
1) Open R-Studio
Change Rconsole to right- click view-then panes-select option
Install package-check red button

# Upload packages i.e.


library(forecast)
library(tseries)
library(xts)
library(zoo)
ARIMA forecasting in R
# Set the default Folder
Go to your folder-select anyfile-check property-copy-paste in r source-invert slash
(/) to this side
setwd("E:/lpu/lpu/2022/ACC501/lecture 28-32 R ARIMA")
getwd() – to understand software understand my path or not

CTRL+l for clear screen


CTRL+enter
Script
# Set the default Folder

arima<- read.csv ("nifty arima.csv", header=TRUE)


head(arima)
tail(arima)
names(arima)
arima
attach(arima)
plot(nifty)
# Define the Nifty as a time series

Y = ts(arima$nifty, start=c(2007, 09),


end=c(2022, 06), frequency=12)
plot(Y)

# Apply the unit root of the Nifty

adf.test(nifty, alternative="stationary", k=0)


• # Transform the series as it is found random walk

• rnifty=diff(log(nifty))
• adf.test(rnifty)

• # Find out p and q


• # Identification Process

• acf(rnifty) # Tell about possible MA terms


• pacf(rnifty) # Tells about AR terms
Check RMSE (Level of Accuracy in
forecasting)
Then AIC
• # Run the ARIMA Model AIC
• arima1 = arima(rnifty,order=c(1,0,1))
RMSE
• summary(arima1)
Note it some where in
• arima2<-arima(rnifty,order=c(2,0,2))
word file or notes
• summary(arima2)
• arima3<-arima(rnifty,order=c(3,0,3))
• summary(arima3)
• arima4<-arima(rnifty,order=c(4,0,4))
• summary(arima4)
Check RMSE (Level of Accuracy in
forecasting)
Then AIC
• # Run the ARIMA Model AIC
• arima5<-arima(rnifty, order=c(12,0,12))
RMSE
• summary(arima5)
Note it some where in
• arima6 <- arima(rnifty,order=c(12,0,1))
word file or notes
• summary(arima6)
• arima6<-auto.arima(rnifty)
• summary(arima6)
Test residual series (check info is still random
or not)
• # Examining the residuals
• res<-residuals(arima5)
• res
• acf(res)
• pacf(res)
• adf.test(res)
• shapiro.test(res)
• Box.test(res)
• summary(res)
• fitted(arima5)
• # Predict the series
• mypredict <- predict(arima5,n.ahead=50)
• mypredict
• plot(forecast(arima5))
• # To forecast the original Series
• nifty
• arimafinal = arima(nifty,order=c(12,1,12))
• plot(forecast(arimafinal))
• mypredict<-predict(arimafinal,n.ahead=10)
• mypredict
• # Predict the series
• mypredict <- predict(arima5,n.ahead=50)
• mypredict
• plot(forecast(arima5))
• # To forecast the original Series
• nifty
• arimafinal = arima(nifty,order=c(12,1,12))
• plot(forecast(arimafinal))
• mypredict<-predict(arimafinal,n.ahead=10)
• mypredict

You might also like