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

Overview |  Quickstart |  Documentation |  Downloads |  Tutorials |  Articles

question

Upvotes
Accepted
32 5 4 2

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-apiworkspaceworkspace-data-apirefinitiv-dataplatform-eikonpythondate
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.

1 Answer

Upvotes
Accepted
18k 21 12 20

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 5.0 MiB each and 10.0 MiB total.

Click below to post an Idea Post Idea