|
- <DIV class=blockcode>
- <BLOCKQUOTE>
- <BLOCKQUOTE>getZceData <- function(dates){
- require(RCurl)
- zceDatabase <- data.frame()
- for (date in dates) {
- str1 <- "http://www.czce.com.cn/portal/exchange/"
- str2 <- "/datadaily/"
- date <- as.character(date)
- year <- substr(date, 1, 4)
- url <- paste(str1, year, str2, date, ".txt", sep = "")
- if (!url.exists(url)) {
- next
- } else {
- colnames <- c("品种月份", "昨结箿", "今开盘", "最高价", "最低价",
- "今收盘", "今结算", "涨跌1", "涨跌2", "成交量", "空盘量",
- "增减量", "成交额", "交割结算价")
- fileName <- paste("zce", date, ".txt", sep = "")
- if (!file.exists(fileName)) {
- download.file(url, fileName, quiet = T)
- }
- zceData <- read.table(fileName, header = F, skip = 1, sep = ",", col.names = colnames)
- zceData <- zceData[(zceData[, 1] != "小计") & (zceData[, 1] != "总计"), ]
- zceData$$$$date <- date
- zceDatabase <- rbind(zceDatabase, zceData)
- }
- }
- return(zceDatabase)
- }
复制代码 |