Search code examples
rjbloomberg

Bloomberg / R / Newbie


I'm at the moment learning R from a fellow student. I have heard that it's possible to download data from Bloomberg and then, for example, calculate the Returns from Prices. Do I have to convert the data into a time series ?

An example would be great.


Solution

  • yes this is possible but you need be able access Bloomberg of course. The code I'm using to download the data into R is:

    start.date=as.Date('2016-01-04')
    end.date= as.Date('2017-02-17')
    opt = c("periodicitySelection"="DAILY")
    blpConnect()
    Bloombergdata=bdh(c("DAX Index", INDU Index"),"PX_LAST",start.date,end.date,options=opt,include.non.trading.days = TRUE)
    

    After getting the data I transform this into time series with a function:

    f.xts=function(dat.l){
      out=as.xts(dat.l[,2],order.by=dat.l[,1])
      return(out)}
    
    out=na.locf(do.call("merge",lapply(data,f.xts)))
    

    I hope this will help...