*** This file contains some Splus commands useful for Financial *** Time Series Analysis. *** **** Commands associated with FinMetrics module [That is, commands for Splus 6.0 or higher for Windows] Part A) For Chapter 2 of the textbook. Click Start > Programs > Splus 6.0 (or 6.1 to start the Splus program) Click File > Load Module to select and download the finmetrics module Click File > Import Data > From Files (then (a) select Browse in the pop-up window to find the data file (b) specify Data Set name (of your choice, I shall use DAA as an example)) then click OK to complete the data input. A data window will appear with the data in columns. The columns are named as Col1, Col2, etc. If you like to change the name of a particular column, move the Cursor to that column, click with the "Right Button" of the mouse to produce a pop-up window, select "Properties" to produce a pop-up window. You can change the column name in that small window, then click OK. (If "Command Window" already appears, skip.) Click Window > Commands window to produce a command window You can now issue commands in the Commands Window For simplicity, you can define a variable for the time series you like to analyze. Fr instance, suppose that we like to analyze Col1 of the data set "DAA" and name the series "rtn". rtn = DAA$Col1 For descriptive statistics of the time series "rtn". summaryStats(rtn) To compute the ACF of "rtn": acf(rtn, lag.max = 20) [The lag.max is optional, an ACF plot will appear.] To compute Ljung-Box Statistics of the first 10 lags autocorTest(rtn, lag.n = 10) To compute the first 12 lags of PACF of "rtn" acf(rtn, lag.max=12, type='partial') To quit q() [Or Click File > Exit] To obtain an Ordinary Least Squares estimation of the linear regression y = b0 + b1*x1 + b2*x2 + b3*b3 + error: fit = OLS(y ~ 1 + x1 + x2 + x3) summary(fit) [To obtain output] Then, use names(fit) to see the variables from the object ``fit''. To fit the above regression model WITHOUT the constant term: fit= OLS(y ~ -1 + x1 + x2 + x3) sumamry(fit) To fit an AR(3) model using OLS command for a time series ``rtn'': fit = OLS(rtn ~ ar(3)) summary(fit) To fit an AR(3) model using maximum likelihood method to ``rtn'': m.fit = arima.mle(rt.rm, model=list(order=c(3,0,0)),xreg=1) [Note: the command "xreg=1" is used to fit a constant term in the model. Otherwise, the command assume the mean of the time series is zero.] m.fit To fit an airline model to a monthly time series ``rtn'': (a) first, specify the model air.md = list(list(order=c(0,1,1)),list(order=c(0,1,1),period=12)) (b) next, perform estimation m.fit = arima.mle(rtn, model=air.md) m.fit To perform model checking using various plots.: chk = arima.diag(m.fit) To use the fitted model m.fit to produce 12 forecasts: m.fore = arima.forecast(rtn, n = 12, model=m.fit$model) m.fore To fit the following regression model with time series error: y(t) = b0 + b1*x(t) + b2*y(t-1) + b3*x(t-1) + error fit = OLS(y~x + tslag(y,1) + tslag(x,1), na.rm=T) [The command "na.rm=T" is to remove any missing values due to the time-series lag operator "tslag".] summary(fit) =================================================================== Part B). For volatility models: Chapter 3 of the textbook Again, I use "rtn" as the name of the time series to be analyzed. (1) To test for serial correlations in "rtn" autocorTest(rtn, lag.n=10) (2) To test for ARCH effects using 10 lags: archTest(rtn, lag.n=10) (3) To obtain PACF of squared return series: acf(rtn^2, lag.max=12, type='partial') (4) To fit an ARCH(2) model to "rtn": arch2 = garch(rtn~1, ~garch(2,0)) summary(arch2) (5) To see various plots concerning the fit: plot(arch2) (6) To fit a GARCH(1,1) model to "rtn": fit = garch(rtn~1, ~garch(1,1)) sumamry(fit) (7) To fit a GARCH(1,1) model with Student-t innovations: fit=garch(rtn~1, ~garch(1,1), cond.dist="t") sumamry(fit) (8) To fit a GARCH(1,1) model with generalized error distributions: fit = garch(rtn~1m ~garch(1,1), cond.dist="ged") summary(fit) (9) To fit an EGARCH(1,1) model with leverage effect and generalized error distribution: fit=garch(rtn~1, ~egarch(1,1), leverage=T, cond.dist="ged") summary(fit) (10) To fit a GARCH(1,1)-M model using volatility: fit=garch(rtn~var.in.mean, ~garch(1,1)) summary(fit) (11) To fit a GARCH(1,1)-M model using standard deviation: fit=garch(rtn~sd.in.mean, ~garch(1,1)) summary(fit) (12) To produce 1-step to 10-step ahead forecasts: fore=predict(fit,10) fore (13) To fit a threshold GARCH(1,1) model: fit=garch(rtn~1, ~tgarch(1,1), trace=F) summary(fit)