Python Eikon Integration - Function "FxCalcPeriod()"

Good afternoon,


At the organization I work at, we have been using python to integrate with Eikon to retrieve FX rates, Libor, Euribors and so on sucessfully.

Now we face a new challenge, which is: how to call the “=FxCalcPeriod()” function from a Python code and get the results from Eikon. This is the sample code we got in the Eikon Adfin Forex Calculation Guide: “=FxCalcPeriod("24FEB03";"EUR";"3M";"FROM:FXTRADE")”. We would like to know how to invoke it from Python x Eikon integration.

Thank you.

Regards,

Daniel Barroso


Best Answer

  • FxCalcPeriod function is currently only available through a COM library known as AdfinX Analytics. It's possible to use this library in Python, although the use is not very straightforward and it's only possible in 32-bit Python. Here's an article that talks about using AdfinX Analytics COM library in Python.

    https://developers.refinitiv.com/article/using-adfinx-analytics-python

    Going forward we will be replacing Adfin Analytics client side libraries with Instrument Pricing Analytics (IPA) service on Refinitiv Data Platform that will provide equivalent calculations. The documentation for FX Cross contracts pricing is already published and there's a tutorial on using IPA service in Python. However currently this service is only available with credentials for Refinitiv Data Platform. We expect to make it available to Eikon users later this year.

Answers

  • Hi, Could you send more information about instrument Pricing Analytics (IPA) for Eikon user?


    What technology will you be able to connect to use and download data? when do you plan to implement? will it be possible to download data via websocket?
  • @przemyslaw.kowalec

    IPA is now available to Eikon and Refinitiv Workspace users. You need to use Refinitiv Data Platform Library to access it. There are some examples available in recently launched Codebook service. Specifically, after launching Codebook, have a look at the following Jupyter notebooks under Examples/02 - Refinitiv Data Platform Library/

    1.7.0 - Function - IPA - Bond Pricing
    1.7.1 - Function - IPA - Option Pricing
    2.7.0 - Content - FinancialContracts - Synchronous
    2.7.1 - Content - FinancialContracts - Asynchronous
    2.7.2 - Content - FinancialContracts - EventDriven

    All of the above mentioned examples use IPA service with Eikon or Refinitiv Workspace account.

  • @danielbarroso

    This is how to do it (I used the argument of FxCalcPeriod for my needs, but one can change that). Note that you have to be running this on Python 32 and follow the steps in

    https://developers.refinitiv.com/en/article-catalog/article/using-adfinx-analytics-in-python

    to install what you need.

    ####

    import pythoncom

    import win32com.client

    import datetime

    import time

    from enum import Enum

    import sys



    class ConnectionToEikonEnum(Enum):

    Error_InitializeFail =2 # from enum EEikonDataAPIInitializeResult

    Error_Reinitialize =1 # from enum EEikonDataAPIInitializeResult

    Succeed =0 # from enum EEikonDataAPIInitializeResult

    Connected =1 # from enum EEikonStatus

    Disconnected =0 # from enum EEikonStatus

    Disconnected_No_license_agreement_sign_off=8 # from enum EEikonStatus

    LocalMode =2 # from enum EEikonStatus

    Offline =4 # from enum EEikonStatus


    #Calls to methods in AdfinX Analytics library can only be made while our application is connected to Eikon

    #This variable is used to tell whether our Python application is connected to Eikon and therefore can make calls to AdfinX Analytics

    connectedToEikon = False


    class EikonDesktopDataAPI_EventHandler:

    def OnStatusChanged(self, EStatus):

    if EStatus == ConnectionToEikonEnum.Connected.value or EStatus == ConnectionToEikonEnum.LocalMode.value:

    print("EikonDesktopDataAPI is connected in regular or local mode")

    global connectedToEikon

    connectedToEikon = True

    elif EStatus == ConnectionToEikonEnum.Disconnected.value:

    print("EikonDesktopDataAPI is disconnected or not initialized")

    elif EStatus == ConnectionToEikonEnum.Disconnected_No_license_agreement_sign_off.value:

    print("EikonDesktopDataAPI is disconnected because the user did not accept license agreement")

    elif EStatus == ConnectionToEikonEnum.Offline.value:

    print("EikonDesktopDataAPI has lost connection to the platform due to network or platform issue")


    #This creates an instance of EikonDesktopDataAPI object used to manage the connection between our Python application and Eikon

    connectionToEikon = win32com.client.DispatchWithEvents("EikonDesktopDataAPILib.EikonDesktopDataAPI", EikonDesktopDataAPI_EventHandler)

    print("Connecting to Eikon...")


    if not connectedToEikon:

    retval = connectionToEikon.Initialize()

    if retval != ConnectionToEikonEnum.Succeed.value:

    print("Failed to initialize Eikon Desktop Data API")

    sys.exit()

    else:

    print("Already connected to Eikon")


    while True:


    try:

    time.sleep(1)

    except KeyboardInterrupt:

    print("KeyboardInterrupt")

    break


    #Windows message pump is required for COM objects to be able to raise events

    pythoncom.PumpWaitingMessages()


    if connectedToEikon:

    #This creates an instance of CreateAdxForexModule object from AdfinX Analytics library

    FXModule = connectionToEikon.CreateAdxForexModule()

    fx_calc_date = pythoncom.MakeTime(datetime.date(2022,4,26))


    try:

    solve_fx = FXModule.FxCalcPeriod(fx_calc_date,"EUR","1Y","FROM:MMTRADE")

    print ("Solve fx:")

    print (solve_fx)

    except pythoncom.com_error as e:

    print (str(e))


    break



  • Note the output is in the form of numbers such as 44679. These are the number of days counted from 1899-12-30 (not 31).