Create a new column with bloomberg data

rstudio

#1

Hi, I want to create a new column on a data set based on values pulled out from bloomberg using the package called Rblpapi,

library("Rblpapi")
blpConnect(host = getOption("blpHost", "localhost"),
port = getOption("blpPort", 8194L), default = TRUE)
Date=as.Date("2018-08-14", origin = "1899-12-30")
library(xts)
test2$ISInstr<-c("US912828XU94 govt","US912828XU94 govt","US9128283Y48 govt")
opt <-c("periodicitySelection"="DAILY","nonTradingDayFillOption"="NON_TRADING_WEEKDAYS","nonTradingDayFillMethod"="PREVIOUS_VALUE") 
precios = bdh(test2$ISInstr,"PX_BID",start.date=Date,options = opt)
datxts <- lapply(precios, function(d) xts(d[,-1], order.by=as.Date(d[,1])))
res <- do.call(merge, datxts)
colnames(res) <-test2$ISInstr  
res2<-t(res)

The problem is that based on the original file, my column ISInstr have the data in format:
"US912828XU94 govt" and the result is in format: "US912828XU94.govt" and is a list

To pull out the data from a list to a dataframe, i tried with:

res2<-data.frame(date=index(res2),coredata(res2))

And to deal with the format problem,

test2$ISIN.Instr<-paste(test2$ISIN,test2$Instr.,sep=".")

And then:

test3<-merge(res2,test2,by.y=res2$ISIN.Instr)

But I'm getting a file with 894.000 values.

Can someone help me to deal with this issue? Thank you in advance