Homework assignment 2


Instruction: Review the class materials, and then go over the detailed step by step example provided on the course website, titled “R_lecture3” and “R_lecture4”. Read carefully the questions, and Submit the assignment on Blackboard.


1. Consider the daily gold xing price 10:30 am (London time) in London Bullion Market in U.S. dollars per Troy ounce from January 3, 1995 to March 30, 2017. The data can be obtained from FRED using the quantmod package. Since there are some missing values, we need to remove them before analysis. Let xt = log(gold price). See instructions below.


require(quantmod)

getSymbols(“GOLDAMGBD228NLBM”, src='FRED')

GOLD <- GOLDAMGBD228NLBM[6982:12784]

idx <- c(1:nrow(GOLD))[is.na(GOLD)]

GOLD <- GOLD[-idx]

xt <- log(as.numeric(GOLD))

rt <- 100*diff(xt)


(a) Obtain the time plots of xt and rt (in one page, using the command par(mfcol=c(2,1)).

(b) Compute the first 12 lags of ACF of xt. Based on the ACF, is there a unit root in xt? Why?

(c) Use the command ar(rt,method=”mle”,order.max=20) to specify the order of an AR model for rt.

(d) Build an AR model for rt, including model checking. Redefine the model by excluding all estimates with t-ratio less than 1.645. Write down the fitted model.

(e) Use the fitted AR model to compute 1-step to 4-step ahead forecasts of rt at the forecast origin March 30, 2017.


2. Consider the CBOE daily volatility index (VIX) from January 2, 1990 to March 31, 2017. The data are available from FRED via quantmod. Again, there are some missing values, which need to be removed. Use the commands below:


getSymbols(“VIXCLS”,src=''FRED'')

VIXCLS <- VIXCLS[1:7109]

idx <- c(1:7109)[is.na(VIXCLS)]

VIXCLS <- VIXCLS[-idx]

vix <- as.numeric(VIXCLS)


(a) Find an AR model for the VIX series. Remove insignificant coefficient estimates (based on t-ratio 1.645). Provide model checking to confirm that the model is adequate. Write down the model.

(b) Use the fitted model to obtain 1-step to 10-step ahead predictions at the forecast origin March 31, 2017.


3. Consider the U.S. quarterly real GDP growth rate from 1947 to 2017. The data are available from FRED. See the command below.


getSymbols(“A191RL1Q225SBEA”,src=''FRED'')

gdp <- as.numeric(A191RL1Q225SBEA)


(a) Obtain time-series plot of the real GDP growth rates.

(b) Find an AR model for the real GDP growth rate, including model checking. Write down the fitted model.

(c) Does the model imply existence of business cycle? Why?

(d) If business cycles are present, compute the average length of the cycles.

(e) Obtain 95% interval forecasts of 1-step to 4-step ahead GDP growth rates at the forecast origin 2017 Q4.


4. Consider the price time series of the five stocks mentioned in “R_lecture2”, and add the following stocks: Amazon (AMZN), AT&T (T), Johnson & Johnson (JNJ), McDonald’s Corporation (MCD), General Electric (GE)


getSymbols(c('AAPL','IBM','INTC','GOOG','MSFT',’AMZN’,’T’,’JNJ’,’MCD’,’GE’))


(a) Calculate the correlation matrix for the stock returns, and plot the heatmap.

(b) Calculate the stock correlation matrix on an annual basis, and calculate the mean and standard deviation of the correlation (you should end up with one number per year for the mean and one for the std).

(c) Plot the time series of the annual mean, the annual std, and the scatter plot of the annual mean versus the annual std.