Rblpapi R Bloomberg data download

1.8k views Asked by At

I am trying to dowload some FX Forward points data from Bloomberg to calculate some yield differentials. For doing so I need to downlowd the number of days betwen the value date and the settlement date for which the foward points are being priced (i.e the tenor) . I have trying as in the below but this dows not work and return NAs. Though the poinst are showing:

require(Rblpapi)
blpConnect()
bdh("AUD1M Curncy",field=c("PX_MID","DAYS_TO_MTY"),start.date=as.Date("2017-05-01"))


         date             PX_MID DAYS_TO_MTY
1  2017-05-01 -4.505000000000000          NA
2  2017-05-02 -4.350000000000000          NA
3  2017-05-03 -4.150000000000000          NA
4  2017-05-04 -4.210000000000000          NA
5  2017-05-05 -4.257000000000000          NA
6  2017-05-08 -4.710000000000000          NA
7  2017-05-09 -4.930000000000000          NA
8  2017-05-10 -4.800000000000000          NA
9  2017-05-11 -4.505000000000000          NA
10 2017-05-12 -4.500000000000000          NA
11 2017-05-15 -4.855000000000000          NA
12 2017-05-16 -4.525000000000000          NA
13 2017-05-17 -4.403000000000000          NA

Now I have been told by the chaps as Bloomberg that you can't download the tenors using bdh but that it is however possible to do so by using the excel bdp formulae. Accordingly I have coded a loop as follows:

mydates <-  c("20170510,"20170511,"20170512,."20170515","20170516
for(i in 1:length(mydates)){print(as.numeric(bdp("AUD1M Curncy",c("PX_BID","DAYS_TO_MTY"),overrides=c("Reference Date"=mydates[i]))))}

ansd here is the print

[1] -4.49 32.00
[1] -4.49 31.00
[1] -4.49 31.00
[1] -4.49 33.00
[1] -4.49 32.00

my problem is that the PX_MID values doe note change when I override the reference date Thgough the days do (as they should). My other problem is that is the most inneficent line of code ever...it takes ages as I have to to as many queries as I have in [mydate].

Is there any way to download the above query in one shot and/or to code this more efficiently ?

Any help appreciated.

Kind regards

Pierre

1

There are 1 answers

2
mgilbert On BEST ANSWER

My guess is that the field PX_BID does not support REFERENCE_DATE overrides whereas the field DAYS_TO_MTY does. If you look at the FLDS command in a Bloomberg terminal you can see the REFERENCE_DATE appearing in conjunction with DAYS_TO_MTY but not with PX_BID. As Dirk indicated in the comments though the best way to confirm this would be through help on the terminal.

In relation to your performance issues, the way that this type of query is working is it is sending multiple requests and receiving multiple responses. If you look at the responses you can see this.

mydates <- c("20170510","20170511","20170512")
for(i in 1:length(mydates)){
    print(as.numeric(bdp("AUD1M Curncy",c("PX_BID","DAYS_TO_MTY"),
                         overrides=c("REFERENCE_DATE"=mydates[i]),
                         verbose=TRUE)))
}

ReferenceDataResponse = {
    securityData[] = {
        securityData = {
            security = "AUD1M Curncy"
            eidData[] = {
            }
            fieldExceptions[] = {
            }
            sequenceNumber = 0
            fieldData = {
                PX_BID = -4.180000
                DAYS_TO_MTY = 32
            }
        }
    }
}
[1] -4.18 32.00
ReferenceDataResponse = {
    securityData[] = {
        securityData = {
            security = "AUD1M Curncy"
            eidData[] = {
            }
            fieldExceptions[] = {
            }
            sequenceNumber = 0
            fieldData = {
                PX_BID = -4.180000
                DAYS_TO_MTY = 31
            }
        }
    }
}
[1] -4.18 31.00
ReferenceDataResponse = {
    securityData[] = {
        securityData = {
            security = "AUD1M Curncy"
            eidData[] = {
            }
            fieldExceptions[] = {
            }
            sequenceNumber = 0
            fieldData = {
                PX_BID = -4.180000
                DAYS_TO_MTY = 31
            }
        }
    }
}
[1] -4.18 31.00

I believe all Bloomberg is doing here is using a domestic (e.g. Australia) and foreign (e.g. United States) holiday calendars to construct the DAYS_TO_MTY. These fluctuate because of holidays and weekends. So one way to do this would be to replicate that logic internally and not use Bloomberg at all. This also will have a benefit of not throttling your data limits, which I seem to recall being an unfortunate side effect of these type of queries.