使用Rbbg的R烛光图

使用Rbbg的R烛光图,r,R,我正在尝试使用Rbbg包在R中绘制蜡烛图,如下所示 library(Rbbg) library(quantmod) currency <- c("NZD Curncy") fld <- c("PX_OPEN", "PX_HIGH", "PX_LOW","PX_LAST") crcy<-as.xts(bdh(conn,currency, fld,Sys.Date()-365)) candleChart(crcy) 这是我们的调查结果 head(bdh(conn, curre

我正在尝试使用Rbbg包在R中绘制蜡烛图,如下所示

library(Rbbg)
library(quantmod)
currency <- c("NZD Curncy") 
fld <- c("PX_OPEN", "PX_HIGH", "PX_LOW","PX_LAST") 
crcy<-as.xts(bdh(conn,currency, fld,Sys.Date()-365))
candleChart(crcy)
这是我们的调查结果

head(bdh(conn, currency, fld, Sys.Date()-365)) 

ticker       date PX_OPEN PX_HIGH PX_LOW PX_LAST
1 NZD Curncy 2013-10-28  0.8283  0.8333 0.8272  0.8302
2 NZD Curncy 2013-10-29  0.8302  0.8305 0.8234  0.8258
3 NZD Curncy 2013-10-30  0.8258  0.8287 0.8193  0.8266
4 NZD Curncy 2013-10-31  0.8266  0.8311 0.8231  0.8263
5 NZD Curncy 2013-11-01  0.8263  0.8286 0.8210  0.8268
6 NZD Curncy 2013-11-02      NA      NA     NA      NA
请帮助我更改要导入的数据类型

谢谢你帮我解决上述问题

我遇到了另一个问题

> head(crcy_xts) 
`         `PX_OPEN PX_HIGH PX_LOW PX_LAST
2014-05-01  0.8617  0.8640 0.8601  0.8633
2014-05-02  0.8633  0.8670 0.8594  0.8662
2014-05-05  0.8651  0.8687 0.8648  0.8678
2014-05-06  0.8678  0.8780 0.8677  0.8741
2014-05-07  0.8741  0.8744 0.8657  0.8661
2014-05-08  0.8661  0.8672 0.8626  0.8647

chartSeries(crcy_xts,theme='white',type='candles',TA=NULL)

这只让我看到了折线图而不是蜡烛图。OHCL数据中是否存在任何问题?

我们的包装RBBG扩展使这项工作变得简单,只是您仍然需要手动将列名更改为quantmod包所接受的正确列名

> require(RbbgExtension)
> require(quantmod)
> 
> ticker <- "NZD"
> 
> fields <- c("PX_OPEN", "PX_HIGH", "PX_LOW", "PX_LAST")
> 
> prices <- HistData(tickers = ticker,
+                    type = "Curncy",
+                    fields = fields,
+                    startdate = "20140101")
R version 3.1.2 (2014-10-31) 
rJava Version 0.9-6 
Rbbg Version 0.5.3 
Java environment initialized successfully.
Looking for most recent blpapi3.jar file...
Adding C:\blp\API\APIv3\JavaAPI\v3.7.1.1\lib\blpapi3.jar to Java classpath
Bloomberg API Version 3.7.1.1 
> candleChart(prices)
> ?candleChart
> head(prices)
           PX_OPEN PX_HIGH PX_LOW PX_LAST
2014-01-01  0.8214  0.8239 0.8191  0.8194
2014-01-02  0.8194  0.8235 0.8139  0.8185
2014-01-03  0.8185  0.8317 0.8179  0.8273
2014-01-06  0.8279  0.8306 0.8252  0.8292
2014-01-07  0.8292  0.8303 0.8255  0.8283
2014-01-08  0.8283  0.8319 0.8251  0.8264
> colnames(prices) <- c("open", "high", "low", "close")
> candleChart(prices)
下面是没有适当标题的烛光图等,工作由你决定


你从哪里得到坎德哈特的?这不是基本数据,你应该显示dputheadbdhconn、currency、fld、Sys.Date-365的输出,因为这里的大多数人都没有彭博社。您的问题是,第一列包含字符日期,这导致as.xts将整个矩阵强制为字符。尝试使用.xtsx[,-1],其中x是bdh调用的输出。谢谢。我想坎德克哈特是从quantmod软件包来的。当我申请as.xtsx[,-1].as.quantmod.OHLC帮助我时,它非常有效。谢谢
> require(RbbgExtension)
> require(quantmod)
> 
> ticker <- "NZD"
> 
> fields <- c("PX_OPEN", "PX_HIGH", "PX_LOW", "PX_LAST")
> 
> prices <- HistData(tickers = ticker,
+                    type = "Curncy",
+                    fields = fields,
+                    startdate = "20140101")
R version 3.1.2 (2014-10-31) 
rJava Version 0.9-6 
Rbbg Version 0.5.3 
Java environment initialized successfully.
Looking for most recent blpapi3.jar file...
Adding C:\blp\API\APIv3\JavaAPI\v3.7.1.1\lib\blpapi3.jar to Java classpath
Bloomberg API Version 3.7.1.1 
> candleChart(prices)
> ?candleChart
> head(prices)
           PX_OPEN PX_HIGH PX_LOW PX_LAST
2014-01-01  0.8214  0.8239 0.8191  0.8194
2014-01-02  0.8194  0.8235 0.8139  0.8185
2014-01-03  0.8185  0.8317 0.8179  0.8273
2014-01-06  0.8279  0.8306 0.8252  0.8292
2014-01-07  0.8292  0.8303 0.8255  0.8283
2014-01-08  0.8283  0.8319 0.8251  0.8264
> colnames(prices) <- c("open", "high", "low", "close")
> candleChart(prices)