/* SAS program to address Exercise 8 in Eco 5375 Fall 2014 */ data dj; input date:monyy5. dji @@; format date monyy5.; datalines; jan84 1258.89 feb84 1164.46 mar84 1161.97 apr84 1152.71 may84 1143.42 jun84 1121.14 jul84 1113.27 aug84 1212.82 sep84 1213.51 oct84 1199.30 nov84 1211.30 dec84 1188.96 jan85 1238.16 feb85 1283.23 mar85 1268.83 apr85 1266.36 may85 1279.40 jun85 1314.00 jul85 1343.17 aug85 1326.18 sep85 1317.95 oct85 1351.58 nov85 1432.88 dec85 1517.02 jan86 1534.86 feb86 1652.73 mar86 1757.35 apr86 1807.05 may86 1801.80 jun86 1867.70 jul86 1809.92 aug86 1843.45 sep86 1813.47 oct86 1817.04 nov86 1883.65 dec86 1924.07 jan87 2065.13 feb87 2202.34 mar87 2292.61 apr87 2302.64 may87 2291.11 jun87 2384.02 jul87 2481.72 aug87 2655.01 sep87 2570.80 oct87 2224.59 nov87 1931.86 dec87 1910.07 jan88 1947.35 feb88 1980.65 mar88 2044.31 apr88 2036.13 may88 1988.91 jun88 2104.94 jul88 2104.22 aug88 2051.29 sep88 2080.06 oct88 2144.31 nov88 2099.04 dec88 2148.58 jan89 2234.68 feb89 2304.30 mar89 2283.11 apr89 2348.91 may89 2439.55 jun89 2494.90 jul89 2554.03 aug89 2691.11 sep89 2693.41 oct89 2692.01 nov89 2642.49 dec89 2728.47 jan90 2679.24 feb90 2614.18 mar90 2700.13 apr90 2708.26 may90 2793.81 jun90 2894.82 jul90 2934.23 aug90 2681.89 sep90 2550.69 oct90 2460.54 nov90 2518.56 dec90 2610.92 jan91 2587.60 feb91 2863.04 mar91 2920.11 apr91 2925.53 may91 2928.42 jun91 2968.13 jul91 2978.18 aug91 3006.08 sep91 3010.35 oct91 3019.73 nov91 2986.12 dec91 2958.64 jan92 3227.06 feb92 3257.27 mar92 3247.41 apr92 3294.08 may92 3376.78 jun92 3337.79 jul92 3329.40 aug92 3307.45 sep92 3293.92 oct92 3198.69 nov92 3238.49 dec92 3303.15 jan93 3277.71 feb93 3367.26 mar93 3440.73 apr93 3423.62 may93 3478.17 jun93 3513.81 jul93 3529.43 aug93 3597.01 sep93 3592.28 oct93 3625.80 nov93 3674.69 dec93 3743.62 jan94 3868.36 feb94 3905.61 ; goptions cback=white colors=(black) border reset=(axis symbol); axis1 offset=(1 cm) label=('Year') minor=none order=('01jan84'd to '01jan95'd by year); axis2 label=(angle=90 'Dow Jones Index') order=(1000 to 4000 by 500); symbol1 i=join; title 'Dow Jones Index Data'; title2 'Monthly Average'; proc gplot data=dj; format date year4.; plot dji*date / haxis=axis1 vaxis=axis2 vminor=1; run; /* Prof. Fomby thinks the series is best modelled in log form and differences of log(Dow Index). */ data dj; set dj; ddji = dji - lag(dji); ldji = log(dji); dldji = ldji - lag(ldji); run; /* Let's look at the plot of the differenced Dow Jones Index. */ axis1 offset=(1 cm) label=('Year') minor=none order=('01jan84'd to '01jan95'd by year); axis2 label=(angle=90 'Differenced Dow Jones Index') order=(-200 to 200 by 50); symbol1 i=join; title 'Differenced Dow Jones Index Data'; title2 'Monthly Average'; proc gplot data=dj; format date year4.; plot ddji*date / haxis=axis1 vaxis=axis2 vminor=1; run; /* Let's look at a plot of the logged Dow Jones Index. */ title1 'Log of Dow Jones Index'; title2 'Monthly Average'; goptions cback=white colors=(black) border reset=(axis symbol); axis1 offset=(1 cm) label=('Year') minor=none order=('01jan84'd to '01jan95'd by year); axis2 label=(angle=90 'Log of Dow Jones Index') order=(6 to 9 by 1); symbol1 i=join; proc gplot data=dj; format date year4.; plot ldji*date / haxis=axis1 vaxis=axis2 vminor=1; run; /* Let's look at the plot of the difference of log Dow Jones Index. */ title1 'Difference of Log of Dow Jones Index'; title2 'Monthly Average'; goptions cback=white colors=(black) border reset=(axis symbol); axis1 offset=(1 cm) label=('Year') minor=none order=('01jan84'd to '01jan95'd by year); axis2 label=(angle=90 'Differenced Log of Dow Jones Index') order=(-.2 to .2 by .05); symbol1 i=join; proc gplot data=dj; format date year4.; plot dldji*date / haxis=axis1 vaxis=axis2 vminor=1; run; /* Let's look at the sample ACF, sample PACF and Augmented Dickey-Fuller Unit Root tests of the logged DJ data. Note that the sample ACF is slowly damping and that the sample PACF has a lag 1 partial autocorrelation near one. This indicates that the logged Dow Jones data needs to be differenced in order to make it stationary and thus amenable to Box-Jenkins identification methods. */ proc arima data=dj; identify var=ldji stationarity = (ADF=12); title1 'ACF, PACF, and Augmented Dickey-Fuller test for Unit Root'; title2 'in the logged Dow Jones data'; run; /* Let's look at the sample ACF, sample PACF and Augmented Dickey-Fuller Unit Root tests of the differenced logged DJ data. Note that both the sample ACF and sample PACF are quickly damping. This indicates that the logged Dow Jones data is stationary after differencing (i.e. the logged Dow Jones data is of stochastic order one (I(1)). */ proc arima data=dj; identify var=ldji(1) stationarity = (ADF=12); title1 'ACF, PACF, and Augmented Dickey-Fuller test for Unit Root'; title2 'of differenced logged Dow Jones data'; run; /* We are using the Logtest Macro to determine whether or not we should be using the differences of the Dow Jones index or the difference of the log of the Dow Jones index. */ title 'Test Results from %logtest macro'; %logtest(dj,dji,ar=1,dif=(1),print=yes); %logtest(dj,dji,ar=2,dif=(1),print=yes); %logtest(dj,dji,ar=3,dif=(1),print=yes); %logtest(dj,dji,ar=4,dif=(1),print=yes); %logtest(dj,dji,ar=5,dif=(1),print=yes); %logtest(dj,dji,ar=6,dif=(1),print=yes); run; /* Now let's form a P-Q box for the differenced logged Dow Jones series. Thereafter we should be able to determine a reasonable Box-Jenkins model for the diferenced logged Dow Jones data. */ proc arima data=dj; identify var=ldji(1) noprint; estimate p = 0 q = 0; estimate p = 1 q = 0; estimate p = 2 q = 0; estimate p = 0 q = 1; estimate p = 0 q = 2; estimate p = 1 q = 1; title 'Getting the info for P-Q Box of Log of Dow Jones Index'; run; /* Now let's forecast the Dow Jones Index 12 steps ahead using the ARIMA(0,1,1) model for the log of the Dow Jones Index. */ proc arima data=dj out=forecast; identify var=ldji(1)noprint; estimate p = 0 q = 1 noprint; forecast lead = 12; title '12 step ahead forecasts of log of Dow Jones Index using the ARIMA(0,1,1) model'; run; /* Here we transformed the log forecasts into the forecasts of the original Dow Jones index. */ data forecast; set forecast; djfore = exp(forecast + 0.5*std**2); if _n_ >= 123 then output; title '12 step ahead forecasts of Dow Jones Index using logged ARIMA(0,1,1) model'; proc print data = forecast; var djfore; run;