RAnalyticFlow是一个由日本人基于R开发的通过绘制流程图分析数据的软件,界面非常简洁, 企图实现类似于SAS EMiner 或RapidMiner的流程图分析模式。RAnalyticFlow的设置是放置R代码,只有在写出函数时,会自动显示参数设置,实际上使用R,代码才是王道。
本文简单介绍如何使用RAnalyticFlow实现ARIMA预测。 ARIMA (Autoregressive Integrated Moving Average Model)在R中的arima函数参数很多,主要是Order(p,d,q):p为自回归AR参数,d为差分阶数,q为MA移动平均周期,其他详见帮助文档。
使用数据为万科A开盘价(2009/08/03----2010/09/17),参数为order(5,2,10),如果使用此方法买股票的脑子不是有问题就是被驴踢了,为什么,你懂的!!!!!!!!
RAnalyticFlow界面和R控制台
实现ARIMA预测的RAnalyticFlow节点:7个简单节点和2个复杂节点(两个方块)
复杂节点(Complex Node)代码设置:可设置多行代码
1. wanke <- read.table("D:/data/wanke.csv", header = TRUE, sep = ",", na.strings = "NA", dec = ".", strip.white = TRUE)
2. library(TSA)
3. open <- arima(wanke[, 2], order = c(5, 2, 10), xreg = data.frame(constant = seq(length(wanke[, 2]))))
4. open.pre <- predict(open, n.ahead = 10, newxreg = data.frame(constant = (length(wanke[, 2]) + 1): (length(wanke[, 2]) + 10)))
5. openLog <- arima(log(wanke[, 2]), order = c(5, 2, 10), xreg = data.frame(constant = seq(length(wanke[, 2]))))
6. plot(open, n.ahead = 10, newxreg = data.frame(constant = (length(wanke[, 2]) + 1):(length(wanke[, 2]) + 10)), main = "万科A", xlab = "时间( 2009/08/03----2010/09/17)", ylab = "开盘价", pch = 19, lty = 1, type = "o", col = "red")
7. n<-length(wanke[,2])
open<-c(wanke[,2],open.pre$pred)
m<-length(open.pre$pred)
class<-c(rep(1,n),rep(2,m))
wanData<-data.frame(open,class)
8. plot(openLog, n.ahead = 5, newxreg = data.frame(constant = (length(wanke[, 2]) + 1):(length(wanke[, 2]) + 5)), transform = exp, main = "万科A", xlab = "时间( 2009/08/03----2010/09/17)", ylab = "开盘价", pch = 10, lty = 5, col = "red")
9. par(bg="white") plot(wanData[, 1], type = "p",main="万科A",xlab="时间( 2009/08/03----2010/09/17)",ylab="开盘价", col = (wanDat a$class)+1) lines(wanData[, 1],col =2:3) legend(230,13.5,c("实际","预测"),text.col=4,pch=10, lty=4, col = 2:3)