使用wind下载中国国航股票数据
library(WindR) #加载万得包
w.start() #显示导航界面
data_wind <- w.wsd("601111.SH", "open,high,low,close", "20100101", Sys.Date()-1) #提取600111的每日四价,开始日期为20180327,结束日期为昨天
stock <- data_wind$Data #将获取的价格数据赋值给stock
library(zoo)
library(xts)
stock_use <- xts(stock$CLOSE,order.by = as.Date(stock$DATETIME)) #将收盘价赋给stock_use
使用TTR包计算MACD
library(TTR)
macd_data <- MACD(stock_use, percent= F)
DIFF <- macd_data$macd
DEA <- macd_data$signal
MACD <- 2 * (DIFF - DEA)
MACD['20180327']