Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Time stamp and periodicity #245

Open
scfhath opened this issue Oct 9, 2017 · 1 comment
Open

Time stamp and periodicity #245

scfhath opened this issue Oct 9, 2017 · 1 comment

Comments

@scfhath
Copy link

scfhath commented Oct 9, 2017

Hello,

I have been working with your excellent package, Rblpapi.

I have a couple of questions:

• I primarily work with economic data and find that for some series the dates don’t line up with the last calendar day of the month, to enable easy merging with other datasets. I have tried setting include.non.trading.days = TRUE but that does not seem to work. I have managed to fudge around this (see code below) but wondered whether there was something I could include in the bdh function, the equivalent of indexAt = ‘lastof’, that could make this easier?

• If setting a lower frequency of data, eg. Daily or weekly to quarterly, is there a way to pull the average of the quarter rather than automatically pulling the close price? I basically want to do the Excel equivalent of setting Period = CQ and Quote = A but can’t seem to make it work in R.

I essentially want to end up with an xts object, timestamped on the last calendar day of the quarter, with quarterly data (averaged over the quarter rather than the closing value)... Any direction would be greatly appreciated. Thank you!

library(Rblpapi)
blpConnect()

Set time period

start_date <- as.Date("2006/10/01", "%Y/%m/%d")
end_date <- as.Date("2017/06/30", "%Y/%m/%d")
opt <- c("periodicitySelection"="QUARTERLY")
securities <- c("....")

Import data from BBG, convert to xts

bbg <- bdh(securities, "PX_LAST", include.non.trading.days = TRUE, start.date = start_date, end.date = end_date, options = opt)
bbg <- as.data.frame(bbg)
rownames(bbg) <- bbg[,1]
bbg <- bbg[, -grep("date", colnames(bbg))]
colnames(bbg) <- c("tenyr", "baa", "somambs", "spx", "fdtr", "somabond", "tp")
bbg <- as.xts(bbg)
bbg <- to.monthly(bbg, indexAt = 'lastof', OHLC = FALSE)

@joel23888
Copy link
Contributor

@scfhath if you want to explore what options are available you can refer to the BLPAPI developer guide at https://data.bloomberglp.com/professional/sites/10/2017/03/BLPAPI-Core-Developer-Guide.pdf. In this case I think you may find what you are looking for around pp 92-93.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants