library(reshape)
stocklist <- list.files("e:/stock/")
stocklist
stockcodes <- substr(stocklist,1,9)
stockcodes
stockdata <- data.frame()
for(i in 1:length(stocklist))
{
readdata <- read.csv(paste("e:/stock/",stocklist[i],sep = ""),header = FALSE,sep = ",")
if(nrow(readdata)>0)
{
readdata <- rename(readdata,c(V1="DATETIME",V2="OPEN",V3="HIGH",V4="LOW",V5="CLOSE",V6="VOLUME",V7="AMT"))
readdata$CODE <- substr(stocklist[i],1,9)
stockdata <- rbind(stockdata,readdata)
}
print(paste(i,Sys.time(),stocklist[i]))
}
nrow(readdata)
nrow(stockdata)
head(stockdata)
tail(stockdata,20)
library(reshape)
stocklist <- list.files("e:/stock/")
stocklist
## [1] "399001.SZ.csv" "399005.SZ.csv" "399006.SZ.csv" "399300.SZ.csv"
## [5] "600000.SH.csv" "600030.SH.csv" "999999.SH.csv"
stockcodes <- substr(stocklist,1,9)
stockcodes
[1] “399001.SZ” “399005.SZ” “399006.SZ” “399300.SZ” “600000.SH” “600030.SH”
[7] “999999.SH”
stockdata <- data.frame()
for(i in 1:length(stocklist))
{
readdata <- read.csv(paste("e:/stock/",stocklist[i],sep = ""),header = FALSE,sep = ",")
if(nrow(readdata)>0)
{
readdata <- rename(readdata,c(V1="DATETIME",V2="OPEN",V3="HIGH",V4="LOW",V5="CLOSE",V6="VOLUME",V7="AMT"))
readdata$CODE <- substr(stocklist[i],1,9)
stockdata <- rbind(stockdata,readdata)
}
print(paste(i,Sys.time(),stocklist[i]))
}
“1 2016-05-15 17:50:07 399001.SZ.csv”
“2 2016-05-15 17:50:07 399005.SZ.csv”
“3 2016-05-15 17:50:07 399006.SZ.csv”
“4 2016-05-15 17:50:07 399300.SZ.csv”
“5 2016-05-15 17:50:07 600000.SH.csv”
“6 2016-05-15 17:50:07 600030.SH.csv”
“7 2016-05-15 17:50:07 999999.SH.csv”
nrow(readdata)
6213
nrow(stockdata)
26113
head(stockdata)
DATETIME OPEN HIGH LOW CLOSE VOLUME AMT CODE
1 1991-04-03 988.05 988.05 988.05 988.05 1 10000 399001.SZ
2 1991-04-04 983.11 983.11 983.11 983.11 523 761000 399001.SZ
3 1991-04-05 978.27 978.27 978.27 978.27 107 150000 399001.SZ
4 1991-04-06 973.42 973.42 973.42 973.42 102 159000 399001.SZ
5 1991-04-08 968.57 968.57 968.57 968.57 57 84000 399001.SZ
6 1991-04-09 963.73 963.73 963.73 963.73 19 39000 399001.SZ
tail(stockdata,3)
DATETIME OPEN HIGH LOW CLOSE VOLUME AMT
26111 2016-05-11 2843.54 2857.25 2818.70 2837.04 135795466 146022514688
26112 2016-05-12 2812.11 2839.28 2781.24 2835.86 136337655 140838633472
26113 2016-05-13 2828.46 2850.09 2814.11 2827.11 114319710 123692646400
CODE
26111 999999.SH
26112 999999.SH
26113 999999.SH