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
17 1 4 5

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-apirefinitiv-dataplatform-eikonworkspaceworkspace-data-api
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
Accepted
18.2k 21 13 21

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 512.0 KiB each and 1.0 MiB total.

Upvotes
79.1k 250 52 74

@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 512.0 KiB each and 1.0 MiB total.

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.