Jae Hoon
Jae Hoon

Reputation: 59

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. When I use chart_Series function, I run into error as below. It must have stemmed from 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

    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

    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

Upvotes: 1

Views: 1129

Answers (1)

Joshua Ulrich
Joshua Ulrich

Reputation: 176638

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.

You can test with 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.


EDIT: Thanks to GSee, I can replicate this via:

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.

Upvotes: 2

Related Questions