---
title: "Exercise 2.2"
author: "Garland Durham"
date: "January 23, 2017"
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

```{r}
y = read.csv( "spx.csv" )
x = y$Close
x = ts( rev(x), start=1950, freq=12)
plot(x, main="SPX prices")
logx = log(x)
plot(logx, main="Log SPX prices")

trend = time(logx)
fit = lm( logx ~ trend)
plot( logx, main="Log SPX with time trend" )
abline( fit, col=2)
z = ts(resid(fit), start=1950, freq=12) 
plot( z, type="o", ylab="Residuals", main="Log SPX with time trend, residuals")
acf(z)


r = diff(logx)
plot( r, ylab="Log return", main="Log SPX returns")
(mu = mean(r))
z = r - mu  
plot(z, main="Random walk with drift, residuals")
acf(z)
qqnorm(z)
qqline(z)



```
