R : Copyright 2003, The R Development Core Team Version 1.6.2 (2003-01-10) R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type `license()' or `licence()' for distribution details. R is a collaborative project with many contributors. Type `contributors()' for more information. Type `demo()' for some demos, `help()' for on-line help, or `help.start()' for a HTML browser interface to help. Type `q()' to quit R. > invisible(options(echo = TRUE)) > library(survival) > > source("index.r") > source("stock.r") > source("bonds.r") > source("fx.r") > source("famfr.r") > > assets <- merge(x=index, y=stock, by.x="caldt", by.y="caldt", all=TRUE) > assets <- merge(x=assets, y=bonds, by.x="caldt", by.y="caldt", all=TRUE) > assets <- merge(x=assets, y=fx, by.x="caldt", by.y="caldt", all=TRUE) > > caldt <- assets$caldt > assets <- 100.0*assets; > assets$caldt <- caldt > > assets <- merge(x=assets, y=famfr, by.x="caldt", by.y="caldt", all=TRUE) > > rm(index,stock,bonds,fx,famfr) > > assets <- assets[assets$caldt > 19710000,] > > crashXLM.idx <- (assets$sp500 < -4.5) & (!is.na(assets$sp500)) > > tmp <- assets[crashXLM.idx,] > dat <- paste("Day",tmp$caldt,sep="") > tmp <- tmp[,-1] > lab <- names(tmp) > tmp <- t(tmp) > tmp <- cbind(lab,tmp) > tmp <- data.frame(tmp) > names(tmp) <- c("PORTFOLIO",dat) > crashXLM <- tmp > > write.table(crashXLM,file="crashXLM.csv",quote=F,sep=",",na="",row.names=F) > > rallyXLM.idx <- (assets$sp500 > 4.5) & (!is.na(assets$sp500)) > > tmp <- assets[rallyXLM.idx,] > dat <- paste("Day",tmp$caldt,sep="") > tmp <- tmp[,-1] > lab <- names(tmp) > tmp <- t(tmp) > tmp <- cbind(lab,tmp) > tmp <- data.frame(tmp) > names(tmp) <- c("PORTFOLIO",dat) > rallyXLM <- tmp > > write.table(rallyXLM,file="rallyXLM.csv",quote=F,sep=",",na="",row.names=F) > > crash80.idx <- (assets$sp500 < -3.5) & (!is.na(assets$sp500)) & + (assets$caldt > 19800000) & (assets$caldt < 19900000) > > tmp <- assets[crash80.idx,] > dat <- paste("Day",tmp$caldt,sep="") > tmp <- tmp[,-1] > lab <- names(tmp) > tmp <- t(tmp) > tmp <- cbind(lab,tmp) > tmp <- data.frame(tmp) > names(tmp) <- c("PORTFOLIO",dat) > crash80 <- tmp > > write.table(crash80,file="crash80.csv",quote=F,sep=",",na="",row.names=F) > > rally80.idx <- (assets$sp500 > 3.5) & (!is.na(assets$sp500)) & + (assets$caldt > 19800000) & (assets$caldt < 19900000) > > tmp <- assets[rally80.idx,] > dat <- paste("Day",tmp$caldt,sep="") > tmp <- tmp[,-1] > lab <- names(tmp) > tmp <- t(tmp) > tmp <- cbind(lab,tmp) > tmp <- data.frame(tmp) > names(tmp) <- c("PORTFOLIO",dat) > rally80 <- tmp > > write.table(rally80,file="rally80.csv",quote=F,sep=",",na="",row.names=F) > > crash90.idx <- (assets$sp500 < -3.5) & (!is.na(assets$sp500)) & + (assets$caldt > 19900000) & (assets$caldt < 20000000) > > tmp <- assets[crash90.idx,] > dat <- paste("Day",tmp$caldt,sep="") > tmp <- tmp[,-1] > lab <- names(tmp) > tmp <- t(tmp) > tmp <- cbind(lab,tmp) > tmp <- data.frame(tmp) > names(tmp) <- c("PORTFOLIO",dat) > crash90 <- tmp > > write.table(crash90,file="crash90.csv",quote=F,sep=",",na="",row.names=F) > > rally90.idx <- (assets$sp500 > 3.5) & (!is.na(assets$sp500)) & + (assets$caldt > 19900000) & (assets$caldt < 20000000) > > tmp <- assets[rally90.idx,] > dat <- paste("Day",tmp$caldt,sep="") > tmp <- tmp[,-1] > lab <- names(tmp) > tmp <- t(tmp) > tmp <- cbind(lab,tmp) > tmp <- data.frame(tmp) > names(tmp) <- c("PORTFOLIO",dat) > rally90 <- tmp > > write.table(rally90,file="rally90.csv",quote=F,sep=",",na="",row.names=F) > > proc.time() [1] 14.28 0.20 14.56 0.00 0.00 >