Skip to content

Instantly share code, notes, and snippets.

@yanping
Created November 8, 2012 13:09
Show Gist options
  • Save yanping/4038720 to your computer and use it in GitHub Desktop.
Save yanping/4038720 to your computer and use it in GitHub Desktop.
基金数据的整理
# 数据文件的下载地址 http://dl.vmall.com/c0a13rrt7p
# 基金基本信息数据来自 http://quote.eastmoney.com/center/fund.html
# 历史行情数据来自天相
setwd("C:/etf/data")
etf <- read.csv("etf.csv")
lof <- read.csv("lof.csv")
colnames(etf) <- c("jjdm","jjmc","bdzs","glr","clgm","zcgm","clsj","tgr")
colnames(lof) <- c("jjdm","jjmc","bdzs","glr","clgm","zcgm","clsj","tgr","tgfl","glfl")
#priceDataFile <- dir(pattern="\\.txt")
#dataName <- substr(priceDataFile,1,6)
dataName <- c(etf$jjdm,lof$jjdm)
dataList <- vector("list",length(dataName))
for (i in 1:length(dataName)) {
xlsFileName <- paste(dataName[i], ".xls", sep = "")
CsvFileName <- paste(dataName[i], ".csv", sep = "")
if(file.exists(xlsFileName)) {
if(file.exists(CsvFileName)) shell(paste("del", CsvFileName,sep=" "))
shell(paste("st",xlsFileName,CsvFileName,sep=" ")) #安装了数据格式转换工具StatTransfer后才有st命令
dataList[[i]] <- read.csv(CsvFileName,
col.names = c("date", "zf","zd","qs","open","high","low","close","meanPrice","cjl","cje","hsl","ltsz","zsz"),
na.strings='-')
}
}
dataBase <- list(dataName = dataName, dataList = dataList)
dataBase$meanCJL <- sapply(dataBase$dataList,function(x){mean(x$cjl,na.rm=TRUE)})
dataBase$meanCJE <- sapply(dataBase$dataList,function(x){mean(x$cje,na.rm=TRUE)})
CJEdecOrderName <- dataBase$dataName[order(dataBase$meanCJE,decreasing=T)]
etf1 <- etf[,1:8]
etf1$type <- "ETF"
lof1 <- lof[,1:8]
lof1$type <- "LOF"
fundDF <- rbind(etf1,lof1)
fundDF$meanCJL <- dataBase$meanCJL
fundDF$meanCJE <- dataBase$meanCJE
write.csv(fundDF,"fundDF.csv")
@yanping
Copy link
Author

yanping commented Nov 8, 2012

安装StatTransfer 真是不得已而为之啊 感觉VBA应该能做转换吧 但不知读取之后效果如何

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment