library(MASS)

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

snpname  = "snp.big_down.imp"
npbname  = "npb.big_down.imp"

M <- 2
size <- 30

sidx <- seq(1,size,2)
nidx <- seq(2,size,2)

tmp <- scan(snpname)

snp_sp500 <- tmp[sidx]
snp_nasdaq <- tmp[nidx]

tmp <- scan(npbname)

npb_sp500 <- tmp[sidx]
npb_nasdaq <- tmp[nidx]

snpname  = "snp.big_down.imp.sig"
npbname  = "npb.big_down.imp.sig"

size <- 60

sidx <- seq(1,size,4)
nidx <- seq(3,size,4)

tmp <- scan(snpname)

snp_sp500_sig <-  sqrt(tmp[sidx])
snp_nasdaq_sig <- sqrt(tmp[nidx])

tmp <- scan(npbname)

npb_sp500_sig <-  sqrt(tmp[sidx])
npb_nasdaq_sig <- sqrt(tmp[nidx])


time <- seq(0,14)

top <- max(c(snp_sp500+snp_sp500_sig,npb_sp500+npb_sp500_sig,
             snp_nasdaq+snp_sp500_sig,npb_sp500+npb_sp500_sig))

bot <- min(c(snp_sp500-snp_sp500_sig,npb_sp500-npb_sp500_sig,
             snp_nasdaq-snp_sp500_sig,npb_sp500-npb_sp500_sig))

plotname = "impulse.eps"

#postscript(file=plotname)
#par(mfrow=c(2,2),mar=c(2.5,4,1.5,2)+0.1) # mar=c(b,l,t,r)
#plot(c(0,14),c(bot,top),type='n',xlab="",ylab="")
#  lines(time,snp_sp500+snp_sp500_sig,lty="dashed")
#  lines(time,snp_sp500              ,lty="solid")
#  lines(time,snp_sp500-snp_sp500_sig,lty="dashed")
#plot(c(0,14),c(bot,top),type='n',xlab="",ylab="")
#  lines(time,npb_sp500+npb_sp500_sig,lty="dashed")
#  lines(time,npb_sp500              ,lty="solid")
#  lines(time,npb_sp500-npb_sp500_sig,lty="dashed")
#plot(c(0,14),c(bot,top),type='n',xlab="",ylab="")
#  lines(time,snp_nasdaq+snp_nasdaq_sig,lty="dashed")
#  lines(time,snp_nasdaq              ,lty="solid")
#  lines(time,snp_nasdaq-snp_nasdaq_sig,lty="dashed")
#plot(c(0,14),c(bot,top),type='n',xlab="",ylab="")
#  lines(time,npb_nasdaq+npb_nasdaq_sig,lty="dashed")
#  lines(time,npb_nasdaq              ,lty="solid")
#  lines(time,npb_nasdaq-npb_nasdaq_sig,lty="dashed")

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

plot(c(0,14),c(bot,top),type='n',xlab="",ylab="",main="S&P500")
  #lines(time,snp_sp500+snp_sp500_sig,lty="dotted")
  lines(time,snp_sp500              ,lty="dashed")
  #lines(time,snp_sp500-snp_sp500_sig,lty="dotted")
  lines(time,npb_sp500+npb_sp500_sig,lty="dotted")
  lines(time,npb_sp500              ,lty="solid")
  lines(time,npb_sp500-npb_sp500_sig,lty="dotted")
plot(c(0,14),c(bot,top),type='n',xlab="",ylab="",main="NASDAQ")
  #lines(time,snp_nasdaq+snp_nasdaq_sig,lty="dotted")
  lines(time,snp_nasdaq              ,lty="dashed")
  #lines(time,snp_nasdaq-snp_nasdaq_sig,lty="dotted")
  lines(time,npb_nasdaq+npb_nasdaq_sig,lty="dotted")
  lines(time,npb_nasdaq              ,lty="solid")
  lines(time,npb_nasdaq-npb_nasdaq_sig,lty="dotted")

dev.off()
