开发者

quantmod::chartSeries does not plot all components

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 wo开发者_运维知识库rks 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?


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").

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜