Upgrade from Eikon -> Workspace. Learn about programming differences.

For a deeper look into our Eikon Data API, look into:

Overview |  Quickstart |  Documentation |  Downloads |  Tutorials |  Articles

question

Upvotes
Accepted
1 1 1 2

Function FxCalcPeriod() in Eikon API (Codebook)

Please may you advise how I can use the same code from another question "https://community.developers.refinitiv.com/questions/83964/function-fxcalcperiod-in-eikon-api-codebook.html?" or similar to also clone the FX Calc period for a future valuation date?

=FxCalcPeriod("21MAR2022","USDKRW","1M") formula that works correctly in excel with future valuation dates "21MAR2022" (Assume todays actual date is 18th Mar 2022)


top dataframe returned is for todays date 18th Mar 22,

Bottom df is for future date since that works in Excel but seemingly not in python.


Formula works with future valuation_date that works (44641=21st March 2022)

13828-capture.png

13848-capture.png

import refinitiv.dataplatform as rdp

import refinitiv.dataplatform.eikon as rdp_ek
from refinitiv.dataplatform.content.ipa.contracts import cross
from refinitiv.dataplatform.content.ipa import FinancialContracts as fc

#%%
#%%

rdp.open_desktop_session(appkey)


fwd_contract = cross.Definition(fx_cross_code='USDKRW', 
                                fx_cross_type='FxForward',
                                legs = [cross.LegDefinition(tenor='1M')])
response = fc.get_cross_analytics(fwd_contract, 
                                  fields = ['StartDate',
                                            'EndDate',
                                            'FxSwapsCcy1Ccy2', 
                                            'FxOutrightCcy1Ccy2'],
                                 calculation_params = cross.CalculationParams(valuation_date='2022-03-21'))

response.data.df
eikoneikon-data-apipythonrefinitiv-dataplatform-eikonworkspaceforwards
13828-capture.png (3.8 KiB)
13848-capture.png (24.9 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.

Upvote
Accepted
24.4k 53 17 14

Hello @william.smith01

Please be informed that you can reopen cases 11059746 and 11059661 by sending an email to the support team with the intact subject. Then, the case will be reopened and the support team will take care of any further questions.

According to the Eikon support team, a solution for the original question is as follows:

Adfin function DfAddPeriod calculates start and maturity date based on valuation date and chosen currency rules that is why eg in case of USD when the valuation date is 23/03, start date will be 25/03 end date will be 25/04.
Do you need to calculate only the maturity date or swap points and outrights as well?

The FWD rates can be valuated as of today (tomorrow works as well) or any historical date.
So, for example if on Friday (25/03) you want to valuate contract as of Monday (28/03) it won't work because the valuation date in this case is today + 3D.
My suggestion is to keep current (today's) valuation date and just add StartDate parameter to force contract starting as of any future date you wish. EndDate will be calculated from StartDate automatically.

If you and to have Python equivalent of DfAddPeriod, we have API endpoint for this (script attached)
https://apidocs.refinitiv.com/Apps/ApiDocs#/details/L2RhdGEvcXVhbnRpdGF0aXZlLWFuYWx5dGljcy1kYXRlcy1hbmQtY2FsZW5kYXJzL3Yx/L2FkZC1wZXJpb2Rz/POST/PLAYGROUND 
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
1 1 1 2

- Top dataframe returned is for todays date 18th Mar 22,

Bottom df is for future date since that works in Excel but seemingly not in python. Especially when todays date is before a weekend.

13848-capture-1.png


13848-capture-1.png (24.9 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
17k 80 39 63

Hi @william.smith01

Yes, it appears the above code does not work for future valuation dates. You can actually confirm issues by introducing the field 'ErrorMessage' within the output. For example:

fwd_contract = cross.Definition(fx_cross_code='USDKRW', 
                                fx_cross_type='FxForward',
                                legs = [cross.LegDefinition(tenor='1M')])
response = fc.get_cross_analytics(fwd_contract, 
                                  fields = ['StartDate',
                                            'EndDate',
                                            'FxSwapsCcy1Ccy2', 
                                            'FxOutrightCcy1Ccy2',
                                            'ErrorMessage'],
                                 calculation_params = cross.CalculationParams(valuation_date='2022-03-23'))
 
response.data.df
response.data.df['ErrorMessage'][0]
"Invalid Date. Valuation date should be less or equal to '2022-03-21'"

I would suggest you reach out to Refinitiv support to confirm the service provides a way to compute based on a future date.

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.

Hi @william.smith01 ,

ticket number 11059746 was raised for this case, the support team will contact you soon to assist on this.

thank you @nick.zincone for your help checking out the cause /error. much appreciated

I have tried like this, I am however still trying to get the below working:

=FxCalcPeriod(A55,"CNY IGNHOL:NO","1M","FROM:FXTRADE RET:2")

I am unable to get this to work in python, please may you assist?

a55 = 30/Mar/22 "2022-03-30"

it should return:

05/May/22 
 eti_request_body_1m = [
  {
    "tag": "my request",
    "startDate": start_date_1m,
    "period": "1M",
    "calendars": [
      f"{ccy},USA"
    ],
    "dateMovingConvention": "NextBusinessDay",
    "endOfMonthConvention": "Same"
  }
]

eti_response_1m = vs_endpoint.send_request(method = rdp.Endpoint.RequestMethod.POST,
                                        body_parameters = eti_request_body_1m)

eti_response_1m.data.raw[0]['date']



Upvotes
24.4k 53 17 14

Hello @william.smith01

I have checked cases 11059746 and 11059661, the support team has provided a solution for you. Does it resolve the issue?

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.

Hi there,

I will please require assistance on the remaining matter of deriving an equivalent of

=FxCalcPeriod(A55,"CNY IGNHOL:NO","1M","FROM:FXTRADE RET:2")

I am unable to get this to work in python, please may you assist?

a55 = 30/Mar/22 "2022-03-30"

it should return:

05/May/22


 
                 

I will please require assistance on the remaining matter of deriving an equivalent of


=FxCalcPeriod(A55,"CNY IGNHOL:NO","1M","FROM:FXTRADE RET:2")


I am unable to get this to work in python, please may you assist?


a55 = 30/Mar/22 "2022-03-30"


should output as per excel:

05/May/22

@william.smith01

You can reopen case 11059661 by sending an email to the support team with the intact subject. Then, the case will be reopened and the support team will take care of any further questions.

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.