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
39 2 4 6

Create a Closing Price column based on date from another column

Hi,

I have a dataframe generated from ek.get_data, and it includes the columns "Instrument" and "TR.FirstTradeDate".

I would like to create a new column showing "TR.PriceClose" with the date parameter coming from "TR.FirstTradeDate". That is, for each row, the date parameter for "TR.PriceClose" is going to be different.

Can you please tell me the easiest way to accomplish this?

Many thanks

eikoneikon-data-apipythonrefinitiv-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
39.4k 77 11 27

Since the date is going to be different for each stock in your list, you'll need to loop through the list of stocks and retrieve the close price separately for each stock.
Assuming your dataframe is returned by

rics = ['FB.O','TWTR.K']
df, err = ek.get_data(rics, ['TR.FirstTradeDate'])

Try

for i in df.index:
    tmp_df, err = ek.get_data(df.loc[i,'Instrument'], 'TR.PriceClose', 
                              {'SDate':df.loc[i,'First Trade Date']})
    df.loc[i,'First Close Price'] = tmp_df.iloc[0,-1]
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.

Upvotes
39 2 4 6

Thank you very much, @Alex Putkov.!

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.