In the second problem weekly price changes of the Brent Crude Oil (bco) is given.
library(Quandl)
## Loading required package: xts
## Loading required package: zoo
##
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
##
## as.Date, as.Date.numeric
bco <- Quandl("FRED/WCOILBRENTEU", type="ts")
## Warning in Quandl("FRED/WCOILBRENTEU", type = "ts"): Type 'ts' does not
## support frequency 52. Returning zoo.
plot(bco, xlab="", ylab="US Dollars", main="Crude Oil Prices: Brent - Europe")
Now we define lagged log difference in prices of the given series
log_bco <- log(bco)
lag_diff <- diff(log_bco,1)
plot(lag_diff,xlab="",ylab="",main="Lagged log difference of Crude Oil Prices: Brent - Europe")
Now we derive the ACF and PACF of the series. Since it is a weekly series a lag in terms of multiples of 5 should be optimal for analysis. Lag of 25 is chosen for this analysis.
acf(as.data.frame(lag_diff),type='correlation',lag=25)
acf(as.data.frame(lag_diff),type='partial',lag=25)
By looking at the graphs of ACF and PACF, let’s analyze following models AR(1), AR(2), AR(3) and MA(1), MA(2), MA(3) and check their corresponding AIC and BIC values.
Let’s start with AR(1)
AR1 <- arima(lag_diff, order = c(1,0,0))
AR1
##
## Call:
## arima(x = lag_diff, order = c(1, 0, 0))
##
## Coefficients:
## ar1 intercept
## 0.1836 0.0004
## s.e. 0.0254 0.0013
##
## sigma^2 estimated as 0.00173: log likelihood = 2643.13, aic = -5280.25
AR(2)
AR2 <- arima(lag_diff, order = c(2,0,0))
AR2
##
## Call:
## arima(x = lag_diff, order = c(2, 0, 0))
##
## Coefficients:
## ar1 ar2 intercept
## 0.1848 -0.0066 0.0004
## s.e. 0.0258 0.0258 0.0013
##
## sigma^2 estimated as 0.00173: log likelihood = 2643.16, aic = -5278.32
AR(3)
AR3 <- arima(lag_diff, order = c(3,0,0))
AR3
##
## Call:
## arima(x = lag_diff, order = c(3, 0, 0))
##
## Coefficients:
## ar1 ar2 ar3 intercept
## 0.1855 -0.0244 0.0951 0.0004
## s.e. 0.0257 0.0262 0.0257 0.0014
##
## sigma^2 estimated as 0.001714: log likelihood = 2649.97, aic = -5289.93
MA(1)
MA1 <- arima(lag_diff, order=c(0,0,1))
MA1
##
## Call:
## arima(x = lag_diff, order = c(0, 0, 1))
##
## Coefficients:
## ma1 intercept
## 0.1902 0.0004
## s.e. 0.0261 0.0013
##
## sigma^2 estimated as 0.001729: log likelihood = 2643.54, aic = -5281.08
MA(2)
MA2 <- arima(lag_diff, order=c(0,0,2))
MA2
##
## Call:
## arima(x = lag_diff, order = c(0, 0, 2))
##
## Coefficients:
## ma1 ma2 intercept
## 0.1903 -0.0094 0.0004
## s.e. 0.0259 0.0259 0.0013
##
## sigma^2 estimated as 0.001729: log likelihood = 2643.61, aic = -5279.21
MA(3)
MA3 <- arima(lag_diff, order=c(0,0,3))
MA3
##
## Call:
## arima(x = lag_diff, order = c(0, 0, 3))
##
## Coefficients:
## ma1 ma2 ma3 intercept
## 0.1893 0.0088 0.1044 0.0004
## s.e. 0.0257 0.0261 0.0261 0.0014
##
## sigma^2 estimated as 0.001711: log likelihood = 2651.44, aic = -5292.87
Based AIC we can see that it has smallest value with MA(3) (-5292.87). Now let’s conduct the Box test for this model.
MA3$coef/sqrt(diag(MA3$var.coef))
## ma1 ma2 ma3 intercept
## 7.3713856 0.3358209 4.0004219 0.2657674
tsdiag(MA3,gof.lag=12)
Box.test(MA3$residuals, lag=12, type="Ljung")
##
## Box-Ljung test
##
## data: MA3$residuals
## X-squared = 7.0032, df = 12, p-value = 0.8574
We can see that with the MA(3) model the coefficients are significant. And ffrom the P value of the Ljung Box test we fail to reject the null hypothesis that indicates serial auto correlation.