Q1. (1)Taking the expected value of both sides of the AR(1) equation, we get:
E[x_t] = E[δ + φ_1 x_{t-1} + w_t]
= E[δ] + E[φ_1 x_{t-1}] + E[w_t]
Since w_t has a mean of 0 (w_t ~ N(0, σ_w^2)), we have:E[w_t] = 0
Also, due to the stationarity of x_t, we have: E[x_t] = E[x_{t-1}]
Substituting these conditions, we get: E[x_t] = δ + φ_1 E[x_t]
Rearranging the terms, we get: (1 - φ_1) E[x_t] = δ
Therefore, the expected value of x_t is given by: E[x_t] = δ / (1 - φ_1)
(2)Substituting these values, we get: x_t = 11,000,000,000 + 0.001 × 10,000,000,000 + w_t
Since we are forecasting for the next year, we need to set w_t = 0 (assuming no error term for the forecast).
x_t = 11,000,000,000 + 0.001 × 10,000,000,000 + 0
= 11,000,000,000 + 10,000,000
= 11,010,000,000
Q2.
goo = tq_get("GOOG", get="stock.prices", from="1997-01-01") %>% tq_transmute(mutate_fun=to.period,period="months")
ggplot(goo, aes(date,close)) + geom_line()
adf.test(diff(log(goo$close)), alternative="stationary", k=0)
## Warning in adf.test(diff(log(goo$close)), alternative = "stationary", k = 0):
## p-value smaller than printed p-value
##
## Augmented Dickey-Fuller Test
##
## data: diff(log(goo$close))
## Dickey-Fuller = -14.781, Lag order = 0, p-value = 0.01
## alternative hypothesis: stationary
acf(diff(log(goo$close)))
pacf(diff(log(goo$close)))
(fit <- arima(diff(log(goo$close)), c(3,0,1)))
##
## Call:
## arima(x = diff(log(goo$close)), order = c(3, 0, 1))
##
## Coefficients:
## ar1 ar2 ar3 ma1 intercept
## -0.7440 -0.0149 -0.0676 0.7866 0.0178
## s.e. 0.3758 0.0881 0.0691 0.3716 0.0054
##
## sigma^2 estimated as 0.007079: log likelihood = 249.3, aic = -486.6
fitARIMA <- auto.arima(diff(log(goo$close)), trace=TRUE)
##
## Fitting models using approximations to speed things up...
##
## ARIMA(2,0,2) with non-zero mean : -511.4437
## ARIMA(0,0,0) with non-zero mean : -493.1642
## ARIMA(1,0,0) with non-zero mean : -497.314
## ARIMA(0,0,1) with non-zero mean : -491.5451
## ARIMA(0,0,0) with zero mean : -484.8265
## ARIMA(1,0,2) with non-zero mean : -505.8596
## ARIMA(2,0,1) with non-zero mean : -513.3808
## ARIMA(1,0,1) with non-zero mean : -506.5986
## ARIMA(2,0,0) with non-zero mean : -514.9837
## ARIMA(3,0,0) with non-zero mean : -512.6675
## ARIMA(3,0,1) with non-zero mean : -511.0328
## ARIMA(2,0,0) with zero mean : -508.1801
##
## Now re-fitting the best model(s) without approximations...
##
## ARIMA(2,0,0) with non-zero mean : -489.9322
##
## Best model: ARIMA(2,0,0) with non-zero mean
plot(as.ts(diff(log(goo$close))))
lines(fitted(fitARIMA), col="red")
futurVal <- forecast(fitARIMA,h=25, level=c(99))
plot(forecast(futurVal))
futurVal$mean
## Time Series:
## Start = 237
## End = 261
## Frequency = 1
## [1] 0.01927305 0.01238502 0.01749310 0.01803598 0.01781342 0.01777811
## [7] 0.01778733 0.01778940 0.01778905 0.01778893 0.01778895 0.01778895
## [13] 0.01778895 0.01778895 0.01778895 0.01778895 0.01778895 0.01778895
## [19] 0.01778895 0.01778895 0.01778895 0.01778895 0.01778895 0.01778895
## [25] 0.01778895