Rblp / Rblpapi

R package interfacing the Bloomberg API from https://www.bloomberglabs.com/api/
Other
166 stars 75 forks source link

Creating a financial report #344

Closed AntonioFasano closed 2 years ago

AntonioFasano commented 2 years ago

When exporting a financial report in Excel, data cells are typically like follows (newlines added for readability):

=BDH("AAPL US Equity","RETURN_COM_EQY","FQ3 2019","FQ3 2019",
     "Currency=USD","Period=FQ","BEST_FPERIOD_OVERRIDE=FQ","FILING_STATUS=MR","FA_ADJUSTED=GAAP",
     "Sort=A","Dates=H","DateFormat=P","Fill=-","Direction=H","UseDPDF=Y")

Such a formula shows the value 52.69.
I am translating this into R like follows:

bdh("AAPL US Equity","RETURN_COM_EQY", start.date = "FQ3 2019",
    options=c(endDate="FQ3 2019", periodicityAdjustment="FISCAL",
              periodicitySelection = "QUARTERLY", UseDPDF="Y"),
    overrides= c(Currency="USD",BEST_FPERIOD_OVERRIDE="FQ",FILING_STATUS="MR",FA_ADJUSTED="GAAP"))

The arguments from the last line of the Excel formula:

"Sort=A","Dates=H","DateFormat=P","Fill=-","Direction=H","UseDPDF=Y"

appear to be Excel specific, and affecting only the data layout. Period="FQ" seems not effective in R.

The result is:

        date RETURN_COM_EQY
1 2019-06-29        52.6903

While results match, it could be sheer luck. Is this the conversion method that you too are following?

eddelbuettel commented 2 years ago

In general it is best to not assume Rblpapi to be any sort of Excel clone or replacement. The package accesses a published API which permits you to access resources offered by the backend, chiefly data and calculation access.

What you do with the retrieved information is up to you. R offers a multitude of ways to generate reports (there must a be hundreds of RMarkdown extension packages) including just about any format known to man as pandoc can convert.

This division of labor follows standard practice and makes sense for most of us.

johnlaing commented 2 years ago

I'm not sure I understand the question. Is there a case where you get an unexpected result from R? It's very hard to troubleshoot something that seems to be working.

AntonioFasano commented 2 years ago

Perhaps the question title created confusion. The fact that I exported an FA screen to Excel was intended only to identify the relevant arguments for the API call.

Let me try to rephrase my question like follows: What is the correct Rblpapi line to retrieve the Apple ROE in the third quarter 2019?

armstrtw commented 2 years ago

We are not here to provide that level of service.

My suggestion is to duplicate your test over a wide range of stocks, so that you can verify that the method you are using in Rblpapi matches excel.

AntonioFasano commented 2 years ago

OK, and, please, do you have any Rblpapi example retrieving a balance sheet item? (whatever item or quarter)

csrvermaak commented 2 years ago

For FA level data I would recommend looking at EQS screens in Bloomberg, and subsequently the beqs() function in RblpApi

AntonioFasano commented 2 years ago

Thank you, @csrvermaak. While this could be a useful workaround, my objective is to obtain a valid Rblpapi line to retrieve fundamental data, such as a balance sheet item, which I think could be of interest to many. I have shared my bdh version, maybe someone will improve it.