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))
## [1] 0.00608453
z = r - mu  
plot(z, main="Random walk with drift, residuals")

acf(z)

qqnorm(z)
qqline(z)