r中的ADX功能结果不正确

时间:2017-10-05 16:57:52

标签: r adx

当我使用ADX功能时,我没有得到正确的答案。例如,2017年10月4日的ADX(14)值为12.87。下面的代码给了我9.53。有什么想法,为什么这是关闭?

require(quantmod)
tickers<-c('SPY')
getSymbols(tickers, from="2017-08-24")
ADX(HLC(SPY))
                DIp      DIn         DX      ADX
2017-08-24       NA       NA         NA       NA
...
2017-09-14 21.60949 13.54557 22.9381443       NA
2017-09-15 20.47286 20.68483  0.5150181       NA
2017-09-18 22.77659 19.99196  6.5109140       NA
2017-09-19 22.36879 19.63402  6.5109140       NA
2017-09-20 21.26106 21.31324  0.1225536       NA
2017-09-21 20.51171 20.56204  0.1225536       NA
2017-09-22 19.97997 20.75146  1.8940939       NA
2017-09-25 18.72051 23.47425 11.2661824       NA
2017-09-26 18.64682 22.54754  9.4690476       NA
2017-09-27 20.81017 20.92800  0.2822906       NA
2017-09-28 20.03528 20.14872  0.2822906       NA
2017-09-29 23.03483 19.02773  9.5265361       NA
2017-10-02 26.60939 18.03780 19.1984916       NA
2017-10-03 28.57002 17.44596 24.1743580 8.058099
2017-10-04 30.09667 16.66099 28.7347243 9.535001

2 个答案:

答案 0 :(得分:0)

您尝试过使用ema或wma吗?您可以通过指定maType = EMA

来实现

ADX(HLC(SPY),n = 14,maType = EMA)

答案 1 :(得分:0)

我遇到了同样的问题。 就我而言,这就是所使用的定价来源。 使用quantmod / src =“ yahoo”时,没有问题:

library(xts)
library(quantmod)
library(TTR)

days_prior <- 100
n <- 0 # n-day prior closing

symbol <- c("SPY") # input ticker
Asset <- getSymbols (symbol, src="yahoo", from = Sys.Date()-days_prior, auto.assign = FALSE) # src : "google", "yahoo", "oanda"
Asset <- Asset[,2:4]
ADX_index <- ADX(Asset, n = 14)
ADX_quantmod <- cbind(Asset, ADX_index)
View(ADX_quantmod[nrow(ADX_quantmod),])

但是,在将Quandl用作定价来源时,TTR:ADX使用调整后的价格并导致较大的偏差。解决方案是强制HLC功能改用未调整价格:

library(xts)
library(TTR)
library(Quandl)

source <- "EOD/"
ticker <- "SPY"
symbol <- paste(source, ticker, sep = "")

Asset <- Quandl(symbol, type = "xts", start_date = Sys.Date() - days_prior, end_date = Sys.Date()-n)
Asset <- HLC(Asset)[,c(1,3,5)] # use the unadjusted prices!
ADX_index <- ADX(Asset, n = 14)
ADX_quandl <- cbind(Asset, ADX_index)
View(ADX_quandl[nrow(ADX_quandl),])

希望有帮助。