quantmod::chartSeries does not plot all components

喜你入骨 提交于 2019-12-11 02:37:08

问题


I have read quite a lot of R docs, but I can't find anything I recognized as the answer to this. My forehead is sore from banging it against the desk. ;)

This is specific to library(quantmod), because that is what I am trying to learn, but I suppose it is a general question too.

R 2.12.2 GUI 1.36 Leopard build 64-bit (5691) Mac OS X 10.6.6

I am trying to replicate the behaviour of a quantmod example at http://www.quantmod.com/examples/intro/

From the GUI, all is well - the below generates a chart like this http://www.quantmod.com/examples/intro/AAPL-full.png:

> require(TTR)
> getSymbols("AAPL")
[1] "AAPL"
> chartSeries(AAPL)
> addMACD()
> addBBands()

But when I source() a .R file from the GUI, I only get the chart for

> chartSeries(AAPL)

That is, only a price chart and a volume chart underneath it. Further, if I try the following from the command line it kind of works as expected.

$ R --no-save `<`quantmod.R

A file called Rplots.pdf is generated, which contains three pages. The third page contains the price + volume + MACD + Bollinger Bands.

What is quantmod doing to make life so difficult? Or what do I not understand that is blindingly obvious and is making life so difficult?

What do I have to do to get the sourced script to be able to use the addMACD() and addBBands() functions to the chart?

As a side question, where are the data generated by addMACD() and addBBands() stored?


回答1:


After reading through the quantmod docs and before banging your head against the desk, try searching the R-SIG-Finance mailing list archives (one way is via the "Support Lists" tab on rseek.org). This question has come up several times on the list.

To answer your main question, see the "Note" section of ?TA:

 Calling any of the above methods from within a function or script
 will generally require them to be wrapped in a ‘plot’ call as they
 rely on the context of the call to initiate the actual charting
 addition.

So you should change the example to:

> require(TTR)
> getSymbols("AAPL")
[1] "AAPL"
> chartSeries(AAPL)
> plot(addMACD())
> plot(addBBands())

To answer your side question, see the "Value" section of ?chartSeries, along with help("chob-class") and help("chobTA-class").



来源:https://stackoverflow.com/questions/5133551/quantmodchartseries-does-not-plot-all-components

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!