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?

Best Answer

  • Jirapongse
    Answer ✓

    @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


Answers

  • Hi @torben1 ,

    I used the code you provided and can retrieve the data properly, could you please provide RICs you've used for further investigation.

    currency = "EUR"
    bs_fields = ["AVAIL(""TR.CashAndSTInvestments"",""TR.CashandEquivalents""+""TR.Cash""+""TR.STInvestments"")"]
    ric_liste = ["GOOG.O", "AAPL.O"]
    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

    1690173224627.png

  • 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.

  • 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.