Code Fragments: Most (but not all) Discussed in Class

S1.txt gives the code for the 4-coin game that we used to illustrate the idea of an equilibrium. It also illustrates how one can use the "burn-in" method in simulations when one may not know the equilibrium distribution.

S2.txt illustrates the dependence of the Ljung-Box p-values on the choice that you make for k.

S3.txt computes the Ljung-Box statistic drirectly from the defintion. We use it to check the Finmetrics function autocorTest().

AR1SimpP67.txt modifies the code on page 67 of Z&W. It illustrates the use of arima.sim(), the relation between the theoretical and the empicial autocorrelation functions. It also illustrates S-Plus graphics features such as par(mfrow(2,2)).

WRDStoFinMet.txt tells you how to access WRDS. How to get a CRSP retrun series into the form of a Finmetrics data set. How to take the series for a test drive.

ZWp62p67p71.txt provides the code fragments from Z&W that illustrate subsampling from a time series, the uses of acf(), and graphics tools.

ARIMAsim.txt ARMAfitting.txt: Two fragments that illustrate simulation of a ARIMA data stream and the use of arima.mle for the fitting of an ARIMA model.

ARIMASimSeed.txt gives more on simulation of an ARIMA model, including the use of innov and start.innov. We also see an example of a series for which arima.mle() fails to converge.

DF.txt builds a function DF() to compute the Dickey-Fuller statistic, and it uses punitroot() to look at the p-values for some simulated series. Our homemade DF function eventually breaks, and we are motivated to consider the SPlus function unitroot().

Unitroot.tex further explores the augmented Dickey-Fuller tests and comments on the examples of Z&W pages 114--123. For log-exchange rates and for stock prices we fail to reject the null hypothesis that there is a unit root. For stock prices this is "obvious," but for exchange rates it may hold a modest surprise.

Zivot and Wang Chapter 6: Time Series Regression (unmodified code from the text)

An edited version of the code provided by Zivot and Wang for Chapter7: Univariate GARCH Modeling.

A heavily editied and commented version of the code provided by Zivot and Wang for Chapter 9: Rolling Analysis of Time Series. This is current as of November 14, but the second half of the file will be modified by November 16.

We will not go over all of the code in chapter 11, chapter 12, or chapter 13, but you should familarize yourself with these examples. As they sit, these samples of code from the text are unedited. I suspect that over the next few weeks some edits may creep in. Stil that depend on how our collective conversation progresses.

Here are some fragments illustrating the use of the S-plus zero finder uniroot() for a user specified univariate function. You can use this to build yourself a tool for finding the risk adjusted returns using the leverage-to-market-sd method. [Note: uniroot() is more different from unitroot() than one little "t" can capture.]