0

I'm doing a project on Bloomberg and in order to calculate the volatility i can't have NA on my data. Only including trading day doesn't work since have stocks on different market. So I would like, Instead of the NA, to display the price from the last trading day.

#Install pack
install.packages("Rblpapi")
install.packages("dplyr")
install.packages("tidyr")

# Load package
library(Rblpapi)
library("dplyr")
library(tidyr)
# Connect to Bloomberg
blpConnect()

# Assign tickers and fields
tickers <- c("SPX INDEX","BXIIE3MC Index","LD12TRUU Index","LBUSTRUU Index","ESM1 Index","LEU1TREU Index","USGG10YR Index","GBB0VMH7 Index","LBUTTRUU Index","IBOXIG Index","LP01TREU Index","LF98TRUU Index","BDCCTREU Index","BDCCTRUU Index","JPEIGLSP Index","GDDUWI Index","MXEU Index","MXJPHEUR Index","NDDUJN Index","STEMWUUN Index","MXEF Index","M7WD Index","BCT5TRUU Index","GOLDLNPM Index","BCOM Index","HFRXGL Index")
myField <- "PX_LAST"

# Pull Bloomberg data and create data frame
Benchmark <- as.data.frame(
  bdh(tickers,
      myField,
      start.date = as.Date("2019-12-31"),
      include.non.trading.days = TRUE)
  
)

#Data cleaning


Benchmark <- select_if(Index, is.numeric)
Benchmark$Date <- seq(as.Date("2019-12-31"), Sys.Date(), by=1)

Benchmark <- Benchmark %>% relocate (Date, .before = SPX.INDEX.PX_LAST)
  • Have a look at `tidyr::fill` – Andrew Gustar Jul 14 '21 at 15:26
  • ... or `zoo::na.locf` or `data.table::nafill` – r2evans Jul 14 '21 at 15:34
  • Your question is about `NA`s in data, so ideally we shouldn't need to care about `bloomberg` or other such code. If you can post please just a sample of your `Benchmark` data that contains the problem values, we can help with that. (You may want to consider *why* the data is `NA`, though: if it shouldn't be there, then it may be a bug in `bloomberg`; if it should be there, then be sure your analysis is taking into account the fact that you are imputing data where it is not known to exist.) – r2evans Jul 14 '21 at 15:36

0 Answers0