Rblpapi
Rblpapi copied to clipboard
include.non.trading.days = TRUE not returning non-trading days.
I am trying to get daily price information from Bloomberg for a time series which includes weekends. Within Bloomberg's spreadsheet builder, the optional parameter is Alignment Calendar: 7D-7 BUS DAY NO HOLIDAY.
My assumption is that the following should work, where each of fields correctly pulls the data.
bdh(
con = con,
securities = bloomberg_file$Ticker[i],
fields = bloomberg_file$Data_Type[i],
start.date = sdate,
end.date = edate,
include.non.trading.days = TRUE,
options = c("periodicitySelection" = "DAILY")
)
The above code does not include non-trading days. When digging through older Q's I found some conversation on this dating back to 2016 with no resolution. What can I do to resolve this issue?
Johnny
Have you tried passing 7D-7 BUS DAY NO HOLIDAY in the options?
any example ids?
If a security has prices on weekends, it should be returned by bdh by default? see example below.
Rblpapi::bdh('XBTUSD Curncy', 'px_last', as.Date('2022-06-01'), as.Date('2022-06-15'))
date px_last
1 2022-06-01 31536.68
2 2022-06-02 30008.35
3 2022-06-03 29793.14
4 2022-06-04 29703.51
5 2022-06-05 29626.05
6 2022-06-06 31462.05
7 2022-06-07 29578.62
8 2022-06-08 30368.18
9 2022-06-09 30408.67
10 2022-06-10 29973.15
11 2022-06-11 28886.39
12 2022-06-12 27406.19
13 2022-06-13 23936.07
14 2022-06-14 22348.38
15 2022-06-15 20538.67
If a security has no data on weekends or holidays (or just missing data), you can fill it like this for all calendar days.
Rblpapi::bdh('BBSW3M Index', 'px_last', as.Date('2022-01-01'), as.Date('2022-01-15'))
date px_last
1 2022-01-04 0.0649
2 2022-01-05 0.0650
3 2022-01-06 0.0693
4 2022-01-07 0.0673
5 2022-01-10 0.0683
6 2022-01-11 0.0663
7 2022-01-12 0.0662
8 2022-01-13 0.0650
9 2022-01-14 0.0728
Rblpapi::bdh('BBSW3M Index', 'px_last', as.Date('2022-01-01'), as.Date('2022-01-15'), options = c('nonTradingDayFillOption' = 'ALL_CALENDAR_DAYS'))
date px_last
1 2022-01-01 0.0677
2 2022-01-02 0.0677
3 2022-01-03 0.0677
4 2022-01-04 0.0649
5 2022-01-05 0.0650
6 2022-01-06 0.0693
7 2022-01-07 0.0673
8 2022-01-08 0.0673
9 2022-01-09 0.0673
10 2022-01-10 0.0683
11 2022-01-11 0.0663
12 2022-01-12 0.0662
13 2022-01-13 0.0650
14 2022-01-14 0.0728
15 2022-01-15 0.0728
Other ways of filling data
bdh_fill_opt <- function(fill_opt, fill_with_prev = TRUE) {
# see bloomberg developer guide pdf
fill_opt <- match.arg(fill_opt, c(
'NON_TRADING_WEEKDAYS', # if date is non trading date but is mon-fri, it will be returned
'ALL_CALENDAR_DAYS',
'ACTIVE_DAYS_ONLY'
))
opt <- c('nonTradingDayFillOption' = fill_opt)
if (!fill_with_prev) {
opt <- c(opt, 'nonTradingDayFillMethod' = 'NIL_VALUE')
}
opt
}
If you just want to show the calendar days without actually filling them with previous day's data
Rblpapi::bdh('BBSW3M Index', 'px_last', as.Date('2022-01-01'), as.Date('2022-01-15'), options = bdh_fill_opt('ALL_CALENDAR_DAYS', fill_with_prev = F))
date px_last
1 2022-01-01 NA
2 2022-01-02 NA
3 2022-01-03 NA
4 2022-01-04 0.0649
5 2022-01-05 0.0650
6 2022-01-06 0.0693
7 2022-01-07 0.0673
8 2022-01-08 NA
9 2022-01-09 NA
10 2022-01-10 0.0683
11 2022-01-11 0.0663
12 2022-01-12 0.0662
13 2022-01-13 0.0650
14 2022-01-14 0.0728
15 2022-01-15 NA