chartSeries:指标的对数标度

时间:2018-01-30 19:40:26

标签: r quantmod dynamic-chart-series

我是R和quantmod的新手。我创建了一个我想添加的新指标 到addTA的情节。但指标的规模应该是对数的。 首先我尝试过(以RSI为例)

> chartSeries ...
> rsi <- RSI(Cl(...))
> addTA(rsi,log.scale=T)
Warning message:
In plot.xy(xy.coords(x, y), type = type, ...) :
  "log.scale" is not a graphical parameter

然后我从源代码复制了addTA(packageVersion(&#39; quantmod&#39;)0.4.12)并尝试了一些肮脏的修改:

--- addTA       
+++ addTA.test  
@@ -1 +1,2 @@
+addTA.test <-
 function (ta, order = NULL, on = NA, legend = "auto", yrange = NULL, 
@@ -11,3 +12,3 @@
     else {
-        lchob <- get.current.chob()
+        lchob <- quantmod:::get.current.chob()
         chobTA <- new("chobTA")
@@ -41,3 +42,4 @@
             order = order, legend = legend, pars = list(list(...)), 
-            time.scale = lchob@time.scale)
+            time.scale = lchob@time.scale, log.scale = T)
+       chobTA@log.scale <- T
         return(chobTA)

这也会导致错误

> source ...
> addTA.test(rsi)
Error in (function (cl, name, valueClass)  : 
  'log.scale' is not a slot in class "chobTA"

如何绘制具有对数刻度的指标?

1 个答案:

答案 0 :(得分:2)

您可以在传递到log

之前使用addTA功能
library(quantmod)
x <- getSymbols("AAPL", auto.assign=FALSE)
rsi <- RSI(Cl(x))

chartSeries(x, subset = "2017")
addTA(log(rsi))

# Newer, cleaner charts alternative:
chart_Series(x, subset = "2017")
add_TA(log(rsi))
add_TA(rsi)