我试图预测股票市场的价格,并使用R" Neuralnet"包。如何对数据进行非规范化并最终找到实际价格。这是算法:
library("quantmod")
library("neuralnet")
startDate <- as.Date('2009-01-01')
endDate <- as.Date('2014-01-01')
getSymbols("^AAPL",src="yahoo",from=startDate,to=endDate)
# DataSet
RSI3 <- RSI(Op(AAPL),n=3)
EMA5 <- EMA(Op(AAPL),n=5)
EMAcross <- Op(AAPL)-EMA5
MACD <- MACD(Op(AAPL),fast = 12, slow = 26, signal = 9)
MACDsignal <- MACD[,2]
BB <- BBands(Op(AAPL),n=20,sd=2)
BBp <- BB[,4]
Price <- Cl(AAPL)-Op(AAPL)
DataSet <- data.frame(RSI3,EMAcross,MACDsignal,BBp,Price)
DataSet <- DataSet[-c(1:33),]
colnames(DataSet) <- c("RSI3","EMAcross","MACDsignal","BollingerB","Price")
# Normalize function
Normalized <- function(x) {(x-min(x))/(max(x)-min(x))}
NormalizedData <- as.data.frame(lapply(DataSet,Normalized))
# Training and test sets
TrainingSet <- NormalizedData[1:816,]
TestSet <- NormalizedData[817:1225 ,]
# ANN
nn1 <- neuralnet(Price~RSI3+EMAcross+MACDsignal+BollingerB,data=TrainingSet, hidden=3, learningrate=.001,algorithm="backprop")
predictedPrice=compute(nn1,TestSet[,1:4])