1

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
Jae Hoon
  • 59
  • 8

1 Answers1

2

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.

Community
  • 1
  • 1
Joshua Ulrich
  • 173,410
  • 32
  • 338
  • 418
  • thanks Jochua. I have tried and redult is as below. It looks doesn't have missing value. > range(crcy.ohcl) [1] 0.7709 0.8836 – Jae Hoon Oct 30 '14 at 07:39
  • 1
    @JaeHoon: I can't help you if I can't reproduce the error. Please provide the minimum amount of data required to create a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). – Joshua Ulrich Oct 30 '14 at 16:06
  • I just updated my question to show minimum data so you can reproduce. I hope that is good for you to reproduce. Appreciate Joshua. – Jae Hoon Oct 30 '14 at 23:35
  • @JaeHoon: Please read some of the answers in the question I linked to. What you've provided is not a reproducible example. – Joshua Ulrich Oct 31 '14 at 01:37
  • now I can produce multi panel chart thanks to you. It is pretty strong tool for reviewing financial market. Thanks again. – Jae Hoon Nov 03 '14 at 08:20