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
32 8 6 7

Dynamic trailing one year request

For the following code, how to I set the end date as today and the start date as one year previous? I would like the formula to be dynamic so that I can run this daily and it always generates the request for the trailing previous year.

df, e = ek.get_data(['AEFS.L'], 
    ['TR.RNSFilerName',                                                        
    'TR.RNSAnnouncedDate',                     
    'TR.RNSTransactionType',                     
    'TR.RNSARNumShrsTransacted',                     
    'TR.RNSARPctOSTransacted',                     
    'TR.RNSARTransactionPrice',                     
    'TR.RNSARMktValTransaction',                     
    'TR.RNSARTotShrsPostTrans',                     
    'TR.RNSARPctOSPostTrans'])

start_date = '2019-01-31'
end_date = '2020-01-31'

df['RNS Announced Date'] = pd.to_datetime(df['RNS Announced Date'])mask = (df['RNS Announced Date'] > start_date) & (df['RNS Announced Date'] <= end_date)

df = df.loc[mask]

df
eikoneikon-data-apipythonrefinitiv-dataplatform-eikonworkspaceworkspace-data-apidate
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.

@bill39

Thank you for your participation in the forum. Are any of the replies below satisfactory in resolving your query? If yes please click the 'Accept' text next to the reply that best answers your question. This will guide all community members who have a similar question. Otherwise please post again offering further insight into your question.

Thanks,

-AHS

1 Answer

· Write an Answer
Upvotes
Accepted
18.2k 21 13 21

Hi @bill39

from datetime import timedelta, date, datetime
import pandas as pd

df, e = ek.get_data(['AEFS.L'],
                    ['TR.RNSFilerName',
                     'TR.RNSAnnouncedDate',
                     'TR.RNSTransactionType',
                     'TR.RNSARNumShrsTransacted',
                     'TR.RNSARPctOSTransacted',
                     'TR.RNSARTransactionPrice',
                     'TR.RNSARMktValTransaction',
                     'TR.RNSARTotShrsPostTrans',
                     'TR.RNSARPctOSPostTrans'])
end_date = date.today()
start_date = end_date - timedelta(days=365)

end_date_str = datetime.strftime(end_date, "%Y-%m-%d")
start_date_str = datetime.strftime(start_date, "%Y-%m-%d")

df['RNS Announced Date'] = pd.to_datetime(df['RNS Announced Date'])
mask = (df['RNS Announced Date'] > start_date_str) & (df['RNS Announced Date'] <= end_date_str)
df = df.loc[mask]
df
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.