question

Upvotes
Accepted
31 1 1 6

How to retrieve a sum of fields with RDP API?

As in Excel I want to get data for the following formula in Excel:

AVAIL(TR.CashAndSTInvestments,TR.CashandEquivalents+TR.Cash+TR.STInvestments)


I tried this jupyter notebook:

currency = "EUR"
bs_fields = ["AVAIL(""TR.CashAndSTInvestments"",""TR.CashandEquivalents""+""TR.Cash""+""TR.STInvestments"")"]

as_of_date = "2023-06-30"
freq = "FY"
period = "FY0, FY-2"
bs_result = fundamental_and_reference.Definition(
universe = ric_liste,
fields = bs_fields,
parameters = {"Scale": 6, "SDate": as_of_date, "Period": period, \
"FRQ": freq, "Curn": currency, "IncludePartial": "No"}
).get_data()

bs_result.data.df


I get the error:

Error code 234 | The 'TR.Cash' is unexpected in formula. A delimiter is probably missing before the lexeme.

I had tried only the "AVAIL"-function with two fields and it works with double ".
But in combination with the addition it doesn't work.
How can I get the result as requested?

#technologyrdp-apifundamental-data
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

The ric_liste is created as follows:

response = fundamental_and_reference.Definition(

["0#.STOXX"],

["TR.CompanyName", "TR.CompanyMarketCap"]

).get_data()

company0 = response.data.df

ric_liste = company0["Instrument"].tolist()

ric_liste = sorted(ric_liste)

@torben1

What is the RD session you are using?

I tested the code and it works fine with the desktop.workspace session.


I use the platform.rdp session.

Upvote
Accepted
77k 240 52 72

@torben1

Thank you for reaching out to us.

As I know, the fundamental_and_reference services on the desktop and RDP sessions are different.

The code that works on the desktop session may not work on the RDP session.

In stead of relying on the AVAIL function, you can do it in Python code.

For example:

currency = "EUR"

bs_fields = ["TR.CashAndSTInvestments","TR.CashandEquivalents","TR.Cash","TR.STInvestments"]


as_of_date = "2023-06-30"
freq = "FY"
period = "FY0, FY-2"
bs_result = fundamental_and_reference.Definition(
universe = ric_liste,
fields = bs_fields,
parameters = {"Scale": 6, "SDate": as_of_date, "Period": period, \
"FRQ": freq, "Curn": currency, "IncludePartial": "No"}
).get_data()


df1 = bs_result.data.df
df1["Cash and Equivalents"] = df1["Cash and Equivalents"].fillna(0)
df1["Cash"] = df1["Cash"].fillna(0)
df1["Short Term Investments"] = df1["Short Term Investments"].fillna(0)
df1["AVAIL_CASH"] = np.where(
    df1['Cash and Short Term Investments'].isnull(), 
    df1['Cash and Equivalents']+df1['Cash']+df1['Short Term Investments'],  
    df1['Cash and Short Term Investments']) 
df1

The output is:

1690260708137.png



1690260708137.png (32.0 KiB)
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Upvotes
31 1 1 6

Thank You for the solution. It works as described.

I understand that one has to retrieve all components of the sum and for the "Avail"-function one should make a separate column.

Thank you also for the python-solution for "ZAV" via "fillna(0)". It is the answer to another question I had put in this forum.


icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.