forked from hoenie-ams/eikon-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTime Series example: Index + Constituents
More file actions
48 lines (37 loc) · 1.54 KB
/
Time Series example: Index + Constituents
File metadata and controls
48 lines (37 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import eikon
import datetime
'''
Example code to retrieve an index + constituents time series.
Please define the following three variables
'''
application_id = 'XXXXXXXXXXXXXXXXXXXX' # From the "Application ID Generator" in Eikon
index = 'OBX' # Name of the index
number_of_days = 10 # Number of days of history you would like to receive
#################################################################################################
# Define the index RIC and the index chain codes
index_RIC = '.' + index
index_chain = '0#.' + index
# Set your App ID
eikon.set_app_id(application_id)
end = datetime.datetime.now()
start = end - datetime.timedelta(days=number_of_days)
# Read the index into empty dataframe
df_index = eikon.get_timeseries([index_RIC],
start_date=start,
end_date=end,
fields='CLOSE')
# Rename "CLOSE" column to the index name to prevent clash
df_index = df_index.rename(columns={'CLOSE': index_RIC})
# Read in more stocks
symbols = eikon.get_data(index_chain, 'TR.RIC')[0]['RIC']
for symbol in symbols:
df_temp = eikon.get_timeseries([symbol],
start_date=start,
end_date=end,
fields='CLOSE')
# Rename to prevent clash
df_temp = df_temp.rename(columns={'CLOSE': symbol})
# Join the two dataframes
df_index = df_index.join(df_temp[symbol])
# Show the output
print(df_index)