Reputation: 33
I need to get the settlement date of forward contracts in R.
I can do it in excel as below:
BDP("CAD1M CURNCY","SETTLE_DT","REFERENCE_DATE",TEXT(C2,"YYYYMMDD"))
(assume my specific date for which I am trying to find the settlement date on a 1 month forward contract is at cell C2)
this gives me the settlement date for the forward contract above. So I want to do the same thing in R (I am connected to bloomberg and can get data)
I tried the followings (and many other versions):
bdp("CAD1M Curncy",c("SETTLE_DT","REFERENCE_DATE",as.Date("2018-11-15")))
but does not work.
Seems like SETTLE_DT
is not recognized but I do not know how to make it recognized for bdp in R.
Here are the error messages I get
bdh("CAD1M Curncy","SETTLE_DT",REFERENCE_DATE = as.Date("20181115"),options=NULL)
Error in bdh("CAD1M Curncy", "SETTLE_DT", REFERENCE_DATE = as.Date("20181115"), : unused argument (REFERENCE_DATE = as.Date("20181115"))
bdh("CAD1M Curncy","SETTLE_DT","REFERENCE_DATE" = as.Date("20181115"),options=NULL)
Error in bdh("CAD1M Curncy", "SETTLE_DT", REFERENCE_DATE = as.Date("20181115"), : unused argument (REFERENCE_DATE = as.Date("20181115"))
bdh("CAD1M Curncy","SETTLE_DT","REFERENCE_DATE = as.Date("20181115")",options=NULL)
Error: unexpected numeric constant in "bdh("CAD1M Curncy","SETTLE_DT","REFERENCE_DATE = as.Date("20181115"
bdp("CAD1M Curncy","SETTLE_DT","REFERENCE_DATE = as.Date("20181115")",options=NULL)
Error: unexpected numeric constant in "bdp("CAD1M Curncy","SETTLE_DT","REFERENCE_DATE = as.Date("20181115"
bdp("CAD1M Curncy","SETTLE_DT",as.Date("20181115"),options=NULL)
Error in charToDate(x) : character string is not in a standard unambiguous format
bdp("CAD1M Curncy","SETTLE_DT",as.Date("2018-11-15"),options=NULL)
Error in bdp_Impl(con, securities, fields, options, overrides, verbose, : Request overrides must be named.
bdp("CAD1M Curncy","SETTLE_DT","REFERENCE_DATe",as.Date("2018-11-15"),options=NULL)
Error in bdp_Impl(con, securities, fields, options, overrides, verbose, : Request overrides must be named.
bdp("CAD1M Curncy","SETTLE_DT",c("REFERENCE_DATe"=as.Date("2018-11-15")),options=NULL) SETTLE_DT CAD1M Curncy 2018-12-31
also if I change the date above to "20181115" instead, it will give me
Error in charToDate(x) : character string is not in a standard unambiguous format
also with so the last one is the only one which gives me some answer but it is basically only giving me the settlement date of the last forward contract (for today) and does not take into account my reference date. In excel the following command works and gives me the right output: =BDP("CAD1M Curncy","SETTLE_DT","REFERENCE_DATE","20181115") output: 2018/12/17
Also tried:
bdp("CAD1M Curncy","SETTLE_DT",c("REFERENCE_DATe",as.Date("2018-11-15")),options=NULL)
Error in bdp_Impl(con, securities, fields, options, overrides, verbose, : Request overrides must be named.
Any ideas? Thank you guys really appreciate it
Upvotes: 1
Views: 1068
Reputation: 33
bdp("CAD1M Curncy", "SETTLE_DT", overrides = c("REFERENCE_DATE"="20181115"))
solved the problem.
Thanks Assylias.
Upvotes: 1
Reputation: 671
You are using different date format between Excel and R, which is a possible cause. I'd suggest to use ...as.Date("20181115") in R, as well. Also, it would be helpful to share the entire error message.
Upvotes: 0