Here are the list of things you need to do during the lab.
EuStockMarkets in the R package datasets. The data set contains the daily closing prices of major European stock indices: Germany DAX (Ibis), Switzerland SMI, France CAC, and UK FTSE. The data are sampled in business time, i.e., weekends and holidays are omitted.For this lab, we are going to forecast the daily closing price of FTSE (UK).
head(EuStockMarkets)
## Time Series:
## Start = c(1991, 130)
## End = c(1991, 135)
## Frequency = 260
## DAX SMI CAC FTSE
## 1991.496 1628.75 1678.1 1772.8 2443.6
## 1991.500 1613.63 1688.5 1750.5 2460.2
## 1991.504 1606.51 1678.6 1718.0 2448.2
## 1991.508 1621.04 1684.1 1708.1 2470.4
## 1991.512 1618.16 1686.6 1723.1 2484.7
## 1991.515 1610.61 1671.6 1714.3 2466.8
DAX, SMI, and CAC. Make sure you add those values to a new time series data set.Dax.lag= stats::lag(EuStockMarkets[,"DAX"],-1)
Smi.lag= stats::lag(EuStockMarkets[,"SMI"],-1)
Cac.lag= stats::lag(EuStockMarkets[,"CAC"],-1)
df=cbind(FTSE=EuStockMarkets[,4], Dax.lag, Smi.lag, Cac.lag)
c(1991, 131)) to the last day of 1997 (c(1997, 260))train= window(df, start=c(1991,131), end=c(1997,260))
test=window(df, start=c(1998,1))
autoplot)autoplot(df, facets=TRUE) +
xlab("Year") + ylab("") +
ggtitle("FTSE")
FTSE using laddeg values of DAX and training data set.tsreg=tslm(FTSE~Dax.lag, data=train)
summary(tsreg)
##
## Call:
## tslm(formula = FTSE ~ Dax.lag, data = train)
##
## Residuals:
## Min 1Q Median 3Q Max
## -599.51 -131.34 20.01 142.24 356.31
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 1.115e+03 1.474e+01 75.63 <2e-16 ***
## Dax.lag 9.851e-01 6.207e-03 158.72 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 180.2 on 1688 degrees of freedom
## Multiple R-squared: 0.9372, Adjusted R-squared: 0.9372
## F-statistic: 2.519e+04 on 1 and 1688 DF, p-value: < 2.2e-16
FTSE. Plot the actual values against the predicted values.pred=predict(tsreg, data.frame(test), interval="prediction")
actual=test[,1]
FTSE using laddeg values of DAX, SMI, CAC, and training data set.mlr=tslm(FTSE~Dax.lag+Smi.lag+Cac.lag, data=train)
summary(mlr)
##
## Call:
## tslm(formula = FTSE ~ Dax.lag + Smi.lag + Cac.lag, data = train)
##
## Residuals:
## Min 1Q Median 3Q Max
## -468.49 -74.19 14.21 79.18 334.52
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 1791.36069 26.57555 67.406 <2e-16 ***
## Dax.lag 0.01195 0.02642 0.452 0.651
## Smi.lag 0.68122 0.01441 47.258 <2e-16 ***
## Cac.lag -0.24047 0.02231 -10.776 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 112.9 on 1686 degrees of freedom
## Multiple R-squared: 0.9754, Adjusted R-squared: 0.9753
## F-statistic: 2.226e+04 on 3 and 1686 DF, p-value: < 2.2e-16
FTSE. Plot the actual values against the predicted values.pred.mlr=predict(mlr, data.frame(test), interval="prediction")
actual.mlr=test[,1]
dt.mlr=cbind(actual, pred)
autoplot(dt.mlr)
#