R语言神经网络量化交易模型
上篇是逻辑回归模型,这次我们用神经网络模型。再算一遍,试试看 # 载入示例股票 library(quantmod) getSymbols("^DJI", src = "yahoo") dji <- DJI[, "DJI.Close"] # 生成技术指标 avg10 <- rollapply(dji, 10, mean) avg20 <- rollapply(dji, 20, mean) std10 <- rollapply(dji, 10, sd) std20 <- rollapply(dji, 20, sd) rsi5 <- RSI(dji, 5, "SMA") rsi14 <- RSI(dji, 14, "SMA") macd12269 <- MACD(dji, 12, 26, 9, "SMA") macd7205 <- MACD(dji, 7, 20, 5, "SMA") bbands <- BBands(dji, 20, "SMA", 2) # 生成市场方向,收盘价与之后20天价格比较,上涨、下跌、横盘 direction <- data.frame(matrix(NA, dim(dji)[1], 1)) lagret <- (dji - Lag(dji, 20)) / Lag(dji, 20) direction[lagret > 0.02] <- "Up"