library(MASS)

ps.options(horizontal=FALSE,onefile=FALSE)
ps.options(pagecentre=TRUE)
ps.options(paper="letter")
ps.options(width=7.0,height=10.0)

rootname <- "stocks_s"

filename <- paste(rootname,".dat",sep="")

vnames <- c("date","SP500","NASDAQ")

stocks <- read.table(file=filename,col.names=vnames)

n <- nrow(stocks)

time <- seq(1,n)

year  <- floor(stocks[,1] / 10000.0)
month <- floor((stocks[,1] - year*10000.0) / 100.0)
day   <- floor((stocks[,1] - year*10000.0 - month*100))

time <- year + month/12.1 + day/310.1

filename <- "expost.eps"

a0 <-  0.0002549080291702 
a1 <-  0.0310860728593678
a2 <- -0.0446769775372705

sdf = a0 + a1*stocks[,2] + a2*stocks[,3]

postscript(file=filename)
par(mfrow=c(3,1),mar=c(2.5,4,1.5,2)+0.1) # mar=c(b,l,t,r)

fval = 0.001

xlim <- c(time[1],time[length(time)])
ylim <- c(-6,6)

title <- "SP500 vs time"

plot(xlim,ylim,type="n",ylab="",xlab="",main=title)
  lines(lowess(time,stocks[,2],f=fval),lty="solid")
  lines(lowess(time,100*sdf,f=fval),lty="dotted")

title <- "NASDAQ vs time"

plot(xlim,ylim,type="n",ylab="",xlab="",main=title)
  lines(lowess(time,stocks[,3],f=fval),lty="solid")
  lines(lowess(time,100*sdf,f=fval),lty="dotted")

title <- "100*log(SDF) vs time"

plot(xlim,ylim,type="n",ylab="",xlab="",main=title)
  lines(lowess(time,100*sdf,f=fval),lty="solid")

dev.off()
