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)