...Date'?
I use the following code to download a csv of the previous 1 year's data for the instruments in my list and for the fields specified. My understanding is that using this method I am retrieving all of the data (unconstrained by dates) and then modifying that data so that a subset, constrained by 'TR.RNSAnnouncedDate', is downloaded as a csv. Is there a way I can only download the data for the previous year to make the request more efficient? In other words, can I apply a date parameter for 'TR.RNSAnnouncedDate' in my initial retreival?
The code:
#import packages
import eikon as ek # the Eikon Python wrapper package
import pandas as pd
import numpy as np
import datetime
from datetime import timedelta, date, datetime
from pandas.tseries.offsets import BDay
#connects to Bill's Eikon terminal
ek.set_app_key('72d2821f21064a0b8890860db39e375eacd87e24')
#retreive the RICs from Eikon
df_rics,e = ek.get_data("lists('Inv Trust List')","TR.RIC")
#convert that into a list and set as an object
ric_list = df_rics['Instrument'].tolist()
#Slice, loop and concatonate the retreival request - must be done in order to avoid a backend request timeout which
#happens when we use too many RICs. n can be toggled below.
n = 50
df = pd.DataFrame()
for ric_chunk in [ric_list[i:i + n]
for i in range(0, len(ric_list), n)]:
tmp_df, e = ek.get_data(ric_chunk,
['TR.RNSFilerName',
'TR.RNSAnnouncedDate',
'TR.RNSTransactionType',
'TR.RNSARNumShrsTransacted',
'TR.RNSARPctOSTransacted',
'TR.RNSARTransactionPrice',
'TR.RNSARMktValTransaction',
'TR.RNSARTotShrsPostTrans',
'TR.RNSARPctOSPostTrans'])
df = tmp_df.append(df)
#set the dates for the csv file we wish to download
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.rename(columns={'RNS AR Price (at Transaction) - £': 'RNS AR Price (at Transaction) GBP',
'RNS AR Market Value of Transaction - £': 'RNS AR Market Value of Transaction - GBP'},
inplace=True)
#create file name and export as CSV
todays_date = date.today()
todays_date_str = datetime.strftime(todays_date, "%Y%m%d")
df.to_csv('Daily API Download_' + todays_date_str + '.csv')