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 5 6

Trouble using server-side functions in API

Hi,

I’m having trouble correctly using server-side functions AVG and SUM.

I would like to iterate through dates and get the average price for a preceding number of trading days. The API returns results to me that are not what they should be. Removing the AVG function and just requesting the preceding three days of prices for each date, I i can see it's giving inconsistent results.

My ultimate goal is a dataframe showing a RIC's average price and closing price over several dates, with the average reflecting a set number of preceding trading days, not calendar days.

Can you please tell me what I’m doing wrong?

test_dates = ['2023-06-05', '2023-06-06', '2023-06-07', '2023-06-08']

for d in test_dates:
    date = d
    print(date)

    result, err =  ek.get_data('AAPL.O',
                   [ 
                    # f"AVG(TR.PriceClose(SDate={str(date)}, EDate=-2, Frq=D))",
                     f"TR.PriceClose(SDate={date}, EDate=-4, Frq=D)"
                    ])
        
    print(result)
    print('')


2023-06-05
  Instrument  Price Close
0     AAPL.O      +179.58
1     AAPL.O      +179.21
2     AAPL.O      +177.82

2023-06-06
  Instrument  Price Close
0     AAPL.O      +179.21
1     AAPL.O      +177.82

2023-06-07
  Instrument  Price Close
0     AAPL.O      +177.82

2023-06-08
  Instrument  Price Close
0     AAPL.O      +180.57
1     AAPL.O      +177.82
python#technology#contenteikon-desktop-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.

Hi @noel.randewich01

Thank you for your participation in the forum. Is the reply below satisfactory in resolving your query?


If so please can you click the 'Accept' text next to the appropriate reply? This will guide all community members who have a similar question.

Thanks,


AHS


Upvote
Accepted
1.4k 5 3 6

Hi @noel.randewich01,

Please try:

f"TR.PriceClose(SDate={date}, EDate={date}-2D)"
#you can add date to check:
f"TR.PriceClose(SDate={date}, EDate={date}-2D), TR.PriceClose(SDate={date}, EDate={date}-2D).date"
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 5 6

This works. Thank you @marcin.bunkowski01!

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.