0

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

Panup Pong
  • 1,871
  • 2
  • 22
  • 44
user3690243
  • 113
  • 1
  • 11
  • Didn't you just ask us at the GitHub repo in an issue ticket? – Dirk Eddelbuettel May 17 '17 at 12:15
  • Sorry Dirk, I am just trying to get a broader audience... I hope I am not infringing the "etiquette"... – user3690243 May 17 '17 at 12:44
  • Nothing wrong with casting a wider but do at least reference prior attempts as well as _fairly comprehensive answer you were already given_. And in short, your best source of help may be pressing F1 on the Bloomberg terminal. – Dirk Eddelbuettel May 17 '17 at 12:55
  • Thank you Dirk, indeed my first point of contact was Bloomberg and I will definitively make reference going forward. My question was about how to make the code more efficient as opposed on hwo to download the data. It just takes ages when you do a loop as you make many calls on the bdp function...I just wondered if someone had looked into this or if BDS could be used for that purpose.... – user3690243 May 18 '17 at 09:30

1 Answers1

2

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.

mgilbert
  • 3,495
  • 4
  • 22
  • 39
  • Thank you, this is a very,detailled and concise answer. I appreciate the time you took to look into this. This is very helpful to me and hopefully others. – user3690243 May 23 '17 at 11:31
  • Glad you found it helpful @user3690243. Since your new to SO it's worth checking out https://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work – mgilbert May 23 '17 at 20:08