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

Overview |  Quickstart |  Documentation |  Downloads |  Tutorials |  Articles

question

Upvotes
Accepted
7 1 0 0

Setting dynamic SDate

Is there way to set a dynamic date for SDate? Rather than the static dates in the code below, I'd like to use the defined week1 and week3 dates.

from datetime import date, timedelta
import eikon as ek
ek.set_app_key('APP KEY')


week1 = (date.today()-timedelta(weeks=1)).strftime("%Y-%m-%d")
week3 = (date.today()-timedelta(weeks=1)).strftime("%Y-%m-%d")


rics = [
    'HOc1','HOc2','HOc3','HOc4','HOc5','HOc6',
    'HOc7','HOc8','HOc9','HOc10','HOc11','HOc12'
    ]


fields = [
    'TR.ClosePrice.date','TR.ClosePrice',
    'TR.ClosePrice(SDate=20200625).date','TR.ClosePrice(SDate=20200625)',
    'TR.ClosePrice(SDate=20190301).date','TR.ClosePrice(SDate=20190301)'
    ]


df, e = ek.get_data(rics,fields)


print(df)
df.plot()


eikoneikon-data-apiworkspaceworkspace-data-apirefinitiv-dataplatform-eikon
icon clock
10 |1500

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

Upvotes
Accepted
18k 21 12 20

Hi @Corey.Stewart

Please try this code:

ahs1.png


ahs1.png (66.3 KiB)
icon clock
10 |1500

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

Upvotes
38.1k 71 35 53

@Corey.Stewart

Sdate can be either relative or absolute dates.


1625198482817.png


Therefore, the code could be:

rics = [
    'HOc1','HOc2','HOc3','HOc4','HOc5','HOc6',
    'HOc7','HOc8','HOc9','HOc10','HOc11','HOc12'
    ]
 
 
fields = [
    'TR.ClosePrice.date','TR.ClosePrice',
    'TR.ClosePrice(SDate=0w).date','TR.ClosePrice(SDate=0w)',
    'TR.ClosePrice(SDate=-2w).date','TR.ClosePrice(SDate=-2w)'
    ]
 
 
df, e = ek.get_data(rics,fields)

The output is:

1625198577795.png




1625198482817.png (57.2 KiB)
1625198577795.png (33.8 KiB)
icon clock
10 |1500

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

Click below to post an Idea Post Idea