* * CHAPTER 2 * Page 42 * * The data are read as "irregular" rather than daily because there are missing * dates on the file due to holidays, and the percentage change (in the analysis) * is taken to mean the change since the previous trading day. If read as daily, * missing values would be inserted for the holidays, and the percentage change * would also be a missing value for that data point and the next. * cal(irregular) open data ch02_badday.xls data(format=xls,org=columns) 1 2528 decimaldate djia set pchange = 100.0*log(djia/djia{1}) * * The STATS (short for statistics) instruction computes sample statistics on a * single series. In addition to the output, it also saves the calculated values * in various pre-defined variables. In this case, we use %MEAN and %VARIANCE to * compute the "z" scores for the data, that, is the number of standard errors * from the sample mean. * stats pchange set zscores = (pchange-%mean)/sqrt(%variance) * * The EXT instruction (short for extremum) locates the maximum and minimum values. * ext zscores * * This displays the probability of a standardized normal being less than the * observed minimum. * disp "Probability of October drop using Normal" %cdf(%minimum) * * The graph is done as a SCATTER (x vs y) rather than a time series GRAPH in * order to get the labeling on the horizontal axis correct. * scatter(footer="Figure 2.7 Daily Percentage Changes in the DJIA in the 1980s",$ style=lines,vlabel="Percent Change",hlabel="Year") # decimaldate pchange * * This is a bit more advanced use of the RATS graphics to add the labeling to the * extreme data point. The SPGRAPH...SPGRAPH(DONE) is used to surround more * complex graph constructions with multiple graphs on a page or (as in this case) * extra text added to a graph. The SCATTER is the same as before. * spgraph scatter(footer="Figure 2.7 Daily Percentage Changes in the DJIA in the 1980s",$ style=lines,vlabel="Percent Change",hlabel="Year") # decimaldate pchange * * The GRTEXT adds text to a graph at locations that you specify by giving the "x" * and "y" positions (after a scatter). Here, we want the text to be right * aligned, just left of the x position for the spike. (The -.1 is to nudge the * text a bit left). %MINENT is the entry found for the minimum value by extremum. * It's centered vertically at the minimum value for PCHANGE. * grtext(x=decimaldate(%minent)-.1,y=pchange(%minent),align=right,valign=center) "October 19, 1987" spgraph(done)