1

当我使用 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
4

2 回答 2

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),])

希望有帮助。

于 2018-09-28T11:29:52.257 回答
0

您是否尝试使用 ema 或 wma?您可以通过指定 maType = EMA 来做到这一点

ADX(HLC(间谍),n = 14,maType = EMA)

于 2017-10-22T10:01:46.693 回答