-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathNN6.R
31 lines (24 loc) · 1.1 KB
/
NN6.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
library(doMC)
registerDoMC(6)
optionData = read.csv("allData.csv", header=F,
col.names=c("symbol", "quotedate", "meaniv", "calliv", "putiv", "callvol",
"putvol", "calloi", "putoi", "close", "volume"))
optionData = optionData[order(optionData$symbol, optionData$quotedate),]
colNames = c("meaniv", "calliv", "putiv", "callvol", "putvol", "calloi", "putoi", "close", "volume")
meanDuration = 20
rowCount = nrow(optionData)
subData = as.matrix(optionData[,colNames])
newData = matrix(NA, nrow(subData), ncol(subData))
sysTime = Sys.time()
for (rowNum in meanDuration:rowCount){
firstRow = rowNum - meanDuration
lastRow = rowNum - 1
curRow = subData[rowNum,]
meanCols = colMeans(subData[firstRow:lastRow,])
meanCols[meanCols == 0] <- 1
newData[rowNum,] = curRow / meanCols
}
newData[is.na(newData)] <- 0
print(Sys.time() - sysTime)
optionDataNormalized = transform(newData, symbol = optionData$symbol, quotedate = optionData$quotedate)
write.csv(optionDataNormalized, file=paste("allData", meanDuration, "dayMA.csv", sep=""), row.names=F, quote=F)