0

I am trying to replace a column in my data with the output of function: bdp(column + "equity", "GICS_SECTOR NAME")

Require(Rblpapi)
#Create raw data example
ticker <- c(2,3,4,5,6)
sector <- c(NA,NA,NA,NA,NA)
dataraw <- data.frame(ticker, random)

dataraw$sector <- bdp("dataraw$ticker Equity", "GICS_SECTOR_NAME")

This does not work due to "" making it text only and I have to add the word "Equity" e.g. IBM Equity. An example of it working perfectly would be bdp("IBM Equity", "GICS_SECTOR_NAME")

1 Answers1

0

You can add the "Equity" part using paste and use the resulting ticker as an argument to bdp:

#Create raw data example
ticker <- c("IBM", "AAPL", "MSFT", "FB")
sector <- c(NA,NA,NA,NA)
df <- data.frame(ticker, sector)
df$ticker_full <- paste(df$ticker, "US Equity", sep = " ")

conn <- Rblpapi::blpConnect()

sectors <- bdp(securities = df$ticker_full,
               fields = "GICS_SECTOR_NAME")

> print(sectors)
                     GICS_SECTOR_NAME
IBM US Equity  Information Technology
AAPL US Equity Information Technology
MSFT US Equity Information Technology
FB US Equity   Communication Services

df$sector <- sectors$GICS_SECTOR_NAME

> print(df)
  ticker                 sector    ticker_full
1    IBM Information Technology  IBM US Equity
2   AAPL Information Technology AAPL US Equity
3   MSFT Information Technology MSFT US Equity
4     FB Communication Services   FB US Equity
tester
  • 1,662
  • 1
  • 10
  • 16
  • Thank you very much! However when I try to run the bdp function I get "Error: Duplicated securities submitted." – hoppekevin Dec 21 '20 at 13:03
  • Strange. Have you tried running it in a clean environment? I.e. try restarting R and loading `library(Rblpapi)`. Then run the code above, it should work as there are no duplicated securities in the tickers above. It works for me, using the latest R, Rblpapi and Bloomberg software. – tester Dec 21 '20 at 14:30