简体   繁体   English

使用Quantmod ChartSeries在R中绘制日内OHLC数据的问题

[英]Problems plotting intraday OHLC data in R with quantmod chartSeries

I have an xts/zoo object ESZ1: 我有一个xts / zoo对象ESZ1:

> class(ESZ1) 
[1] "xts" "zoo"

with

> class(time(ESZ1))
[1] "POSIXt"  "POSIXct"

and

> colnames(ESZ1)
[1] "ESZ1.Open"    "ESZ1.High"    "ESZ1.Low"     "ESZ1.Close"   "ESZ1.Volume"  "ESZ1.WAP"     "ESZ1.hasGaps" "ESZ1.Count"  

and I would like to plot it using the chartSeries function from the package quantmod. 我想使用Quantmod包中的chartSeries函数绘制它。 However, I get the following error: 但是,出现以下错误:

> chartSeries(ESZ1)
Error in if (on == "years") { : missing value where TRUE/FALSE needed

Any ideas of what the problem could be would be greatly appreciated. 对于可能出现问题的任何想法,将不胜感激。

Additional question: Is there any documentation for how to adjust the axes/margins for chartSeries()? 附加问题:是否有任何有关如何调整chartSeries()的轴/边距的文档? Currently my y-axis labels are partially cut off on the right-hand margin of the plot. 目前,我的y轴标签在该图的右边缘已被部分切除。 I've tried using 我试过使用

mar = ...

in the argument list of chartSeries, but this did not change the resulting plot. 在chartSeries的参数列表中,但这不会更改结果图。

The issue is within chartSeries, specifically the axTicksByTime call. 问题出在chartSeries之内,特别是axTicksByTime调用。 I'll add a patch to fix this, but for now you can do: 我将添加一个补丁来解决此问题,但现在您可以执行以下操作:

chartSeries(ESZ1, major.ticks="minutes")

By default major.ticks="auto" and it seems to fail too early in the automagical procedure to get to the right answer. 默认情况下为major.ticks =“ auto” ,它似乎在自动魔术过程中为时过早,无法获得正确的答案。

You have not provided enough information about your ESZ1 object, but I can reproduce the error by trying to plot 2 minutes or less of data. 您没有提供有关ESZ1对象的足够信息,但是我可以通过尝试绘制2分钟或更短的数据来重现该错误。 Your column names look like something from IBrokers,so ... 您的列名称看起来像来自IBrokers的名称,所以...

> library(IBrokers)
> library(quantmod)
> ibg <- ibgConnect()
> fut <- twsFUT('ES', 'GLOBEX', '201112')
> ESZ1 <- reqHistoricalData(ibg, fut, barSize='1 secs', duration='120 S')
TWS Message: 2 -1 2104 Market data farm connection is OK:usfuture 
TWS Message: 2 -1 2106 HMDS data farm connection is OK:ushmds2a 
waiting for TWS reply on ES .... done.
> chartSeries(ESZ1)
Error in if (on == "years") { : missing value where TRUE/FALSE needed

If you use more than 2 minutes of data it works. 如果您使用2分钟以上的数据,它将起作用。

> ESZ1 <- reqHistoricalData(ibg, fut, barSize='1 secs', duration='121 S')
waiting for TWS reply on ES .... done.
> chartSeries(ESZ1)

> indexClass(ESZ1)
[1] "POSIXct" "POSIXt" 
> colnames(ESZ1)
[1] "ESZ1.Open"    "ESZ1.High"    "ESZ1.Low"     "ESZ1.Close"   "ESZ1.Volume" 
[6] "ESZ1.WAP"     "ESZ1.hasGaps" "ESZ1.Count"  

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM