quantmod::chartSeries 不绘制所有组件 [英] quantmod::chartSeries does not plot all components

查看:32
本文介绍了quantmod::chartSeries 不绘制所有组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读了很多 R 文档,但是我找不到任何我认为可以解决这个问题的答案.我的额头因为撞在桌子上而酸痛.;)

这是特定于 library(quantmod) 的,因为这是我想要学习的,但我想这也是一个普遍的问题.

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

我正在尝试在 http 上复制 quantmod 示例的行为://www.quantmod.com/examples/intro/

从 GUI 来看,一切都很好 - 下面生成了一个这样的图表 http://www.quantmod.com/examples/intro/AAPL-full.png:

<代码>>要求(TTR)>getSymbols("AAPL")[1]苹果">图表系列(AAPL)>添加MACD()>添加BBands()

但是当我source()一个来自GUI的.R文件时,我只能得到

的图表

<代码>>图表系列(AAPL)

也就是说,它下面只有一个价格图表和一个交易量图表.此外,如果我从命令行尝试以下操作,它会按预期工作.

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

生成一个名为 Rplots.pdf 的文件,其中包含三页.第三页包含价格 + 交易量 + MACD + 布林带.

quantmod 做了什么让生活变得如此艰难?或者我不明白什么是显而易见的,让生活变得如此艰难?

我需要做什么才能使源脚本能够将 addMACD()addBBands() 函数用于图表?

作为一个附带问题,addMACD()addBBands() 生成的数据存储在哪里?

解决方案

在阅读完 quantmod 文档之后,在将头撞在桌子上之前,尝试搜索 R-SIG-Finance 邮件列表档案(一种方法是通过"rseek.org 上的支持列表"选项卡).这个问题在列表中出现过多次.

要回答您的主要问题,请参阅?TA 的注意"部分:

<块引用>

 从函数或脚本中调用上述任何方法通常会要求将它们包装在情节"调用中,因为它们依靠调用的上下文来启动实际的图表添加.

因此您应该将示例更改为:

<代码>>要求(TTR)>getSymbols("AAPL")[1]苹果">图表系列(AAPL)>情节(添加MACD())>情节(addBBands())

要回答您的附带问题,请参阅 ?chartSeries 的值"部分,以及 help("chob-class")help("chobTA-class").

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?

解决方案

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

这篇关于quantmod::chartSeries 不绘制所有组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆