Please convert in Python API: =@spotcalc (today,2)
It is just a function that pulls the spot date and you can input a "days to spot" parameter. That's what I need to do in python.
@Eugene Torres
Thank you for reaching out to us.
I tested this function in Workspace Excel and it returns nothing.
I'm not certain that this functionality belongs to Workspace Excel. You should confirm with the Workspace Excel team how the function operates and which service or endpoint it uses to retrieve data.
Next, we can check if the API can access that service or endpoint.
Hi @Jirapongse. Further information below. Is there an equivalent code as to what the purpose of the custom formula can be?
You can see part of the file in the screenshot.
You can see that we have a formula in G9, that uses a cell containing today’s date and the number 2 and it generates the spot date +2 days (skipping weekends and holidays) I was wondering if there is a way to replicate this using the python API
LSEG Data Library for Python provides the dates_and_calendars module, as shown in this example.
Can you run this function in your Excel for the web workspace? I’d like to confirm which product this Excel function belongs to.
Hi @Jirapongse. This works!
But I don’t get this fields:
calculated_date = ld.dates_and_calendars.add_periods(
start_date=datetime.date.today(), period="3D", calendars=["USD", "KOR"], date_moving_convention="NextBusinessDay", end_of_month_convention="Last28"
)
What does calendars mean? What options can I choose there?
What does the end of month convention mean? What options can I choose there?
The parameters' descriptions are:
Parameters ---------- start_date: str or datetime or timedelta, optional Start date of calculation. period: str, optional Calculation time period. calendars: list of str, optional Calendars to determine the working days and national holidays for particular countries. Optional if currencies is provided. currencies: list of str, optional Currencies to use for calculation of the date for the working day or weekend. Optional if calendars is provided. date_moving_convention : DateMovingConvention or str, optional Convention for adjusting the dates. end_of_month_convention : EndOfMonthConvention or str, optional Possible values for the end of month.
The client can use the following code to retrieve the possible values of the calendars parameter.
request_definition = ld.delivery.endpoint_request.Definition( url = '/data/quantitative-analytics-dates-and-calendars/v1/calendars', method = ld.delivery.endpoint_request.RequestMethod.GET ) response = request_definition.get_data() response.data.raw
The possible values of the end_of_month_convention are:
| The possible values are: | - Last, | - Same, | - Last28, | - Same28
For the meaning of the end_of_month_convention, please contact the product support team directly.
Hello @Jirapongse Good day, I am assisting Eugene on this matter, We were advised that there is an issue with the library:
spot_date_2 = ld.dates_and_calendars.add_periods(
start_date=date.today().strftime("%Y-%m-%d"),
period="2D",
calendars=["USD", "KOR"],
date_moving_convention="NextBusinessDay",
end_of_month_convention="Last28"
This is meant to return the next business date +2 , by running it today, I would assume it would return 27 JAN, but its returning the 26st
Is there any reason why Sundays are taken as business days? Can we exclude this?
@Christian_Ada
The library retrieves data from this /data/quantitative-analytics-dates-and-calendars/v1/add-periods service.
Please contact the product support team directly to verify the content.
Hi @Jirapongse thank you for this, may I ask where can we able to see and review this specific service? Thank you for the help!
Please check this Dates and Calendars: Add Periods document.
Otherwise, please contact the product support team directly regarding this service.