Rblp / Rblpapi

R package interfacing the Bloomberg API from https://www.bloomberglabs.com/api/
Other
167 stars 75 forks source link

Problem with bds overrides for FUT_CHAIN ​​field #345

Closed henrique1008 closed 2 years ago

henrique1008 commented 2 years ago

Good Morning

This Excel query returns tickers of futures contracts existing on a given date for iron ore

=@BDS("SCO1 Comdty", "FUT_CHAIN","CHAIN_DATE",B1,"cols=1;rows=38")

Where B1 is a cell in Excel with a date fomat field, as 03/10/2018 or any other date

In this query, CHAIN_DATE is an overrides to choose the reference date

It returns all open contract tickers for that reference date

Trying to reproduce in R, I believe it looks like

library(tidyverse)

conn <- Rblpapi::blpConnect()

date <- '2019-03-12'

overrd <- c(CHAIN_DATE = date)

Rblpapi::bds(security = "SCO1 Comdty", 
                        field = "FUT_CHAIN", 
                        overrides = overrd,
                        con = conn) %>%
  magrittr::extract2(1) %>% 
  dplyr::as_tibble() %>% 
  janitor::clean_names()

This returns results but not the expected results.

Apparently the overrides are not working in R as it works in Excel, and the return from R is equivalent to returning from Excel without the overrides

I would like to extract a long series of past data for a study, and I needed to get the CHAIN_DATE overrides to work, can you help me please?

henrique1008 commented 2 years ago

It was much simpler than I thought, and my question wasn't very smart kkkk

It was enough to change the format that the date is passed in the overrides

library(tidyverse)

conn <- Rblpapi::blpConnect()

date <- '20190312'

overrd <- c(CHAIN_DATE = date)

Rblpapi::bds(security = "SCO1 Comdty", 
                        field = "FUT_CHAIN", 
                        overrides = overrd,
                        con = conn) %>%
  magrittr::extract2(1) %>% 
  dplyr::as_tibble() %>% 
  janitor::clean_names()