[英]get multiple chart using chart_Series of quantmod package
I'm tring to use chart_Series function instead chartSereis due to compatibility issue with par(mfrow) function to draw multiple chart. 由于par(mfrow)函数的兼容性问题,我试图使用chart_Series函数而不是chartSereis来绘制多个图表。 When I use chart_Series function, I run into error as below. 当我使用chart_Series函数时,出现以下错误。 It must have stemmed from char_Serires. 它一定源自char_Serires。 Because I run code line by line. 因为我逐行运行代码。
Error in plot.window(c(1, 0), c(NaN, NaN))
whole code is as below 整个代码如下
library(Rbbg)
library(quantmod)
conn<-blpConnect()
currency <- c("NZD Curncy", "AUD Curncy")
fld <- c("PX_OPEN", "PX_HIGH", "PX_LOW","PX_LAST")
par(mfrow=c(2,1))
par(mar = c(3, 3, 1, 0), oma = c(1, 1, 1, 1))
for (i in 1:2){
crcy<-bdh(conn,currency[i],fld,Sys.Date()-365)
Name<-as.character(bdp(conn,currency[i],"NAME"))
crcy_xts <- as.xts(crcy[,-1])
crcy.ohcl<-as.quantmod.OHLC(crcy_xts,col.names = c("Open", "High","Low", "Close"))
chart_Series(crcy.ohcl,name=Name,theme=chartTheme("white"),type='candles',TA=NULL,subset='last 6 months')
please help me. 请帮我。
here is 这是
> head(crcy.ohcl)
crcy_xts.Open crcy_xts.High crcy_xts.Low crcy_xts.Close
2014-10-27 0.7853 0.7903 0.7846 0.7894
2014-10-28 0.7894 0.7959 0.7884 0.7919
2014-10-29 0.7919 0.7978 0.7770 0.7802
2014-10-30 0.7802 0.7827 0.7774 0.7798
minimum data for reproduction. 复制的最小数据。
crcy cy
row.names date PX_OPEN PX_HIGH PX_LOW PX_LAST
1 2014-10-29 2014-10-29 0.7919 0.7978 0.7770 0.7802
2 2014-10-30 2014-10-30 0.7802 0.7827 0.7774 0.7803
crcy_xts crcy_xts
row.names PX_OPEN PX_HIGH PX_LOW PX_LAST
1 2014-10-29 0.7919 0.7978 0.7770 0.7802
2 2014-10-30 0.7802 0.7827 0.7774 0.7803
I don't have access to a Bloomberg terminal, so your example is not reproducible for me. 我无法使用彭博终端机,因此您的示例对我而言是不可复制的。 My guess is that crcy.ohcl
has missing and/or NaN
values. 我的猜测是crcy.ohcl
缺少和/或NaN
值。
You can test with range(crcy.ohcl)
. 您可以使用range(crcy.ohcl)
进行测试。 If the output is [1] NA NA
, then you need to take care of the missing values in your data with something like na.omit(crcy.ohcl)
, na.locf(crcy.ohcl)
, etc. 如果输出为[1] NA NA
,那么您需要使用na.omit(crcy.ohcl)
, na.locf(crcy.ohcl)
等来照顾数据中的缺失值。
EDIT: Thanks to GSee , I can replicate this via: 编辑:感谢GSee ,我可以通过以下方式复制它:
require(quantmod)
data(sample_matrix)
x <- as.xts(sample_matrix)
y <- as.quantmod.OHLC(x, col.names=c("Open", "High", "Low", "Close"))
chart_Series(y) # error
chart_Series(as.xts(y)) # works
So it looks like chart_Series
expects an xts object, but as.quantmod.OHLC
doesn't have an xts
method, so it returns a zoo
object if you pass it a xts
object. 因此,看起来chart_Series
需要一个xts对象,但是as.quantmod.OHLC
没有xts
方法,因此,如果您将其传递给xts
对象,它将返回一个zoo
对象。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.