0% found this document useful (0 votes)
42 views

Fa Assignment

This document analyzes time series data on quarterly Moody's industrial stock prices from 1983 to 1987 using R. It decomposes the data into trend, seasonal and random components. Various ARIMA and Holt-Winters exponential smoothing models are fitted to make forecasts. The document forecasts one period ahead for different models and components, provides confidence intervals, and plots the forecasts against the data.

Uploaded by

Anshuman Ghosh
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views

Fa Assignment

This document analyzes time series data on quarterly Moody's industrial stock prices from 1983 to 1987 using R. It decomposes the data into trend, seasonal and random components. Various ARIMA and Holt-Winters exponential smoothing models are fitted to make forecasts. The document forecasts one period ahead for different models and components, provides confidence intervals, and plots the forecasts against the data.

Uploaded by

Anshuman Ghosh
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 7

mody <- read.csv("C:\\Users\\IBM_ADMIN\\Desktop\\Moody1.

csv")
datawide <- ts(mody, frequency=4, start=c(1983,1))
library("TTR")

plot.ts(datawide)

> datawide
Qtr1 Qtr2 Qtr3 Qtr4
1983 80.20 71.21 48.26 51.25
1984 60.10 67.55 63.54 60.28
1985 54.80 55.41 63.56 74.04
1986 71.16 87.24 111.11 105.90
1987 97.99 110.45 112.61 126.97

It looks like a multiplicative model since the size of the seasonal fluctuations and random fluctuations
seem to increase with the level of the time series. Also, the random fluctuations in the data are not
roughly constant in size over time.
acf(datawide, lag.max=20)
> pacf(datawide, lag.max=20)
So, this is a AR(1) model with negative phi.

2. Build proper ARIMA/seasonal ARIMA model.

> ats <- ts(mody, frequency=4, start=c(1949,1))


> auto.arima(log(ats))
Series: log(ats)
ARIMA(0,1,0)

sigma^2 estimated as 0.02132: log likelihood=9.6


AIC=-17.2 AICc=-16.96 BIC=-16.25

3) Forecast for one point ahead.

> r1<-arima(ats,order=c(1,0,0),method="ML")
> predict(r1,n.ahead=1)
$pred
Qtr1
1954 123.9675

$se
Qtr1
1954 10.70735

4) Give the confidence interval for the forecast value

5) Give forecast based on Holt-winter method.

> atsHWfit <- HoltWinters(ats, alpha=TRUE,beta=TRUE, gamma=TRUE)


> atsHWfit
Holt-Winters exponential smoothing with trend and additive seasonal component.

Call:
HoltWinters(x = ats, alpha = TRUE, beta = TRUE, gamma = TRUE)

Smoothing parameters:
alpha: TRUE
beta : TRUE
gamma: TRUE

Coefficients:
[,1]
a 130.281563
b 8.400000
s1 4.085938
s2 8.497187
s3 -9.271562
s4 -3.311563
> summary(atsHWfit)
Length Class Mode
fitted 64 mts numeric
x 20 ts numeric
alpha 1 -none- logical
beta 1 -none- logical
gamma 1 -none- logical
coefficients 6 -none- numeric
seasonal 1 -none- character
SSE 1 -none- numeric
call 5 -none- call

>
> # For pedicting future value
> predict(atsHWfit,n.ahead=4 )
Qtr1 Qtr2 Qtr3 Qtr4
1954 142.7675 155.5788 146.2100 160.5700
>
> # Confidence intervals
> lhwl <- (forecast(atsHWfit, h=12)$lower)[,2]
> uhwl <- (forecast(atsHWfit, h=12)$upper)[,2]
>
> # Combining the limits and predicted value
> cbind(forecast(atsHWfit, h=12)$mean, lhwl, uhwl)
forecast(atsHWfit, h = 12)$mean lhwl uhwl
1954 Q1 142.7675 99.43546 186.0995
1954 Q2 155.5788 58.68536 252.4721
1954 Q3 146.2100 -15.92364 308.3436
1954 Q4 160.5700 -76.76935 397.9094
1955 Q1 176.3675 -144.99150 497.7265
1955 Q2 189.1788 -224.18256 602.5401
1955 Q3 179.8100 -332.90160 692.5216
1955 Q4 194.1700 -424.73531 813.0753
1956 Q1 209.9675 -521.56152 941.4965
1956 Q2 222.7788 -627.45726 1073.0148
1956 Q3 213.4100 -761.32012 1188.1401
1956 Q4 227.7700 -876.98457 1332.5246
>

> # Code for producing forecast plot


> plot.ts(ats,xlim=c(1949,1961))
> lines((1961+(0:11)/12),forecast(atsHWfit, h=12)$mean,col=4)
> lines((1961+(0:11)/12),lhwl,col=3)
> lines((1961+(0:11)/12),uhwl,col=2)
>
6. For monthly and quarterly data, decompose the data into components.
7. Make forecasts (one point ahead) for each component based on suitable
model.
> decots =decompose(ats)
> decots$seasonal
Qtr1 Qtr2 Qtr3 Qtr4
1949 -3.8723438 0.9004687 1.7520313 1.2198438
1950 -3.8723438 0.9004687 1.7520313 1.2198438
1951 -3.8723438 0.9004687 1.7520313 1.2198438
1952 -3.8723438 0.9004687 1.7520313 1.2198438
1953 -3.8723438 0.9004687 1.7520313 1.2198438

> decots$trend
Qtr1 Qtr2 Qtr3 Qtr4
1949 NA NA 60.21750 57.24750
1950 58.70000 61.73875 62.20500 60.02500
1951 58.51000 60.23250 63.99750 70.02125
1952 79.94375 89.87000 97.20625 103.46125
1953 106.55000 109.37125 NA NA

> decots$random
Qtr1 Qtr2 Qtr3 Qtr4
1949 NA NA -13.7095312 -7.2173437
1950 5.2723438 4.9107812 -0.4170313 -0.9648438
1951 0.1623437 -5.7229687 -2.1895313 2.7989063
1952 -4.9114062 -3.5304688 12.1517188 1.2189062
1953 -4.6876563 0.1782812 NA NA

> plot(decots)

You might also like