#Illustration of S-Plus functions (Used on Day 5) #getReturns #autoCorTest #Reminder of the "@" extractor and the "$" extractor #for slotnames and names (for two flavors of S objects) module(finmetrics) #We load the finmetrics module which has a data set in it called singleIndex.dat #We looked at it before, but lets look again. class(singleIndex.dat) slotNames(singleIndex.dat) #Lets put the MSFT prices into a vector. msft.p=singleIndex.dat[, "MSFT"] msft.p #Let's look at these prices plot(msft.p) #Tools for getReturns() #See discussion in ZW args(getReturns) msft.ret=getReturns(msft.p,percentage=T) #we looked at the plot before; let's look again. plot(msft.ret) #Now, when we look at this can we tell if this is just noise. help(autocorTest) #Now, lets give it a look. autocorTest(msft.ret) #This is non-significant. Irritating --- disappointing... maybe wrong? #Let's explore. First, let's look at price --- just for fun autocorTest(msft.p) #Wow, insanely significant ... is this COOL .. or is it BOGUS? #What are the assumtions of the autocorTest? At a minimum, correlations have to #make sense. Do correlations in prices make sense? NO! #Why? Well, there is no chance they are stationary! #We have to look at returns ... they have a chance of being stationary. #So, OK, Let's look directly at the autocorrelations.. acf(msft.ret) #There looks like there is something there #Maybe if we don't that the defacult number of lags in our Ljung-Box test. autocorTest(msft.ret, lag.n=2) #Pretty close to significant. I'm not going to disregard the possibility that MSFT #had an eploitable level of month-to-month correlation during this study period. #There are lots of things to worry about, but we have a little nibble --- #an indication of "signal." #Supponse we just look exactly at one month. autocorTest(msft.ret, lag.n=1) #Now, just to cover some ground for HW 2, lets use the $ extractor to understand the #information provided by acf() v=acf(msft.ret, plot=F) v names(v) w=v$acf w[1:5] #You can use acf() and this way of extracting information from the value #the acf returns in order to build the function for LB that you need for HW2. #Note that the first value of w is the lag 0 corrleation, which is 1. #Note also from the definition of the LB statistic that it just contains #terms with lag 1,2,...,k. #Correct code for HW2 will need to take this into consideration.