Discover Refinitiv
MyRefinitiv Refinitiv Perspectives Careers
Created with Sketch.
All APIs Questions & Answers  Register |  Login
Ask a question
  • Questions
  • Tags
  • Badges
  • Unanswered
Search:
  • Home /
  • Eikon Data APIs /

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

Overview |  Quickstart |  Documentation |  Downloads |  Tutorials |  Articles

avatar image
Question by danieluphromes · Jan 28 at 06:00 PM · eikon-data-apihistoricalprice-history

Historical Highs and Lows using EDAPI

I know I can get snapshots of Highs and Lows with code such as the below, but is it possile to get this historically?


df, err = ek.get_data(
    instruments = [
        'VOD.L'
    ],
    fields = [
        'TR.Price52WeekHighDate',
        'TR.Price52WeekHigh',
        'TR.Price52WeekLow',
        'TR.Price52WeekLowDate',
        'YRHIGH',
        'YRLOW',
        'YRHIGHDAT',
        'YRLOWDAT'
    ]
)
display(df)

People who like this

0 Show 0
Comment
10 |1500 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Reply

  • Sort: 
avatar image
REFINITIV
Best Answer
Answer by jonathan.legrand · Jan 28 at 06:08 PM

Please try the following:



def Historical_HL(from_date=(datetime.now() - relativedelta(years=3)).strftime("%Y-%m-%d"),
                  to_date=datetime.now().strftime("%Y-%m-%d"),
                  instrument='VOD.L', field='TR.closeprice', field_name='Close Price', weeks=52, years=1):
    
    mxyw = max(years, weeks/52)
    if [years, weeks].index(mxyw) == 0:
        switch = relativedelta(years=years)
    else:
        switch = relativedelta(weeks=weeks)
    
    fromd = datetime.strptime(from_date, "%Y-%m-%d")
    tod = datetime.strptime(to_date, "%Y-%m-%d")
    
    df0, err = ek.get_data(
        instruments = [instrument],
        fields = [field + '.date', field],
        parameters={
            'SDate': (fromd - switch).strftime("%Y-%m-%d"),  # more here: https://dateutil.readthedocs.io/en/stable/relativedelta.html
            'EDate': to_date,
            'Frq':'d'})
    df0.Date = [df0.Date.iloc[i][:10] for i in range(len(df0))]
    
    df1 = pd.DataFrame()
    df1['date'] = [str(i)[:10] for i in pd.date_range((fromd - switch).strftime("%Y-%m-%d"), to_date, freq='D')]
    
    df2 = df1.merge(df0, left_on=['date'], right_on=['Date'], how='outer')
    
    df3 = df2.replace({float('nan') : np.nan})
    df3 = df3.replace({pd._libs.missing.NA : np.nan})
    
    mx_d, mx_ix_l , mx_val_l, mi_d,  mi_ix_l, mi_val_l = [], [], [], [], [], []
    for j, i in enumerate(range(weeks*7,len(df3))):
        number_list = df3[field_name][j:i].to_list()
        mi_val_l.append(min(number_list))
        mi_ix = len(number_list) - number_list[::-1].index(np.nanmin(number_list)) - 1 + j
        mi_ix_l.append(mi_ix)
        mi_d.append(df3.iloc[mi_ix])
        mx_val_l.append(max(number_list))
        mx_ix = len(number_list) - number_list[::-1].index(np.nanmax(number_list)) - 1 + j
        mx_ix_l.append(mx_ix)
        mx_d.append(df3.iloc[mx_ix])
        
    df4 = df3.copy()
    df4[str(weeks) + "WH"] = [np.nan for i in range(weeks*7)] + [mx_d[i][field_name] for i in range(len(mx_d))]
    df4[str(weeks) + "WHD"] = [np.nan for i in range(weeks*7)] + [mx_d[i].date for i in range(len(mx_d))]
    df4[str(weeks) + "WL"] = [np.nan for i in range(weeks*7)] + [mi_d[i][field_name] for i in range(len(mi_d))]
    df4[str(weeks) + "WLD"] = [np.nan for i in range(weeks*7)] + [mi_d[i].date for i in range(len(mi_d))]
    
    ymx, ymi, ymxd, ymid = [], [], [], []
    for i in range(366*years, len(df4)):
        fm = df4.index[df4.date == (datetime.strptime(df4.iloc[i].date, "%Y-%m-%d") - relativedelta(years=years)).strftime("%Y-%m-%d")].tolist()
        ymx.append(df4[field_name].iloc[fm[0]:i].max())
        ymxd.append(df4.iloc[df4[field_name].iloc[fm[0]:i].idxmax()].date)
        ymi.append(df4[field_name].iloc[fm[0]:i].min())
        ymid.append(df4.iloc[df4[field_name].iloc[fm[0]:i].idxmin()].date)
    
    df5 = df4.copy()
    df5[str(years) + "YH"] = [np.nan for i in range(366*years)] + ymx
    df5[str(years) + "YHD"] = [np.nan for i in range(366*years)] + ymxd
    df5[str(years) + "YL"] = [np.nan for i in range(366*years)] + ymi
    df5[str(years) + "YLD"] = [np.nan for i in range(366*years)] + ymid
    
    return df5


I tried this for e.g.:

Historical_HL(from_date='2018-01-01', to_date='2020-01-01',
              instrument='VOD.L',
              field='TR.closeprice', field_name='Close Price',
              weeks=52, years=2)


capture.png



capture1.png


capture.png (38.1 KiB)
capture1.png (46.2 KiB)
Comment

People who like this

0 Show 0 · Share
10 |1500 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Watch this question

Add to watch list
Add to your watch list to receive emailed updates for this question. Too many emails? Change your settings >
10 People are following this question.

Related Questions

Trying to fetch Close Bid Price for CMO tranche from Python

How to get TR.PE at a historical date?

How to get the 3M USD LIBOR interest rate historical data with Python Eikon API?

How can I get the historical options greeks and implied volatility ?

Get EPS historical data for stocks

  • Copyright
  • Cookie Policy
  • Privacy Statement
  • Terms of Use
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Alpha
  • App Studio
  • Block Chain
  • Bot Platform
  • Connected Risk APIs
  • DSS
  • Data Fusion
  • Data Model Discovery
  • Datastream
  • Eikon COM
  • Eikon Data APIs
  • Electronic Trading
    • Generic FIX
    • Local Bank Node API
    • Trading API
  • Elektron
    • EMA
    • ETA
    • WebSocket API
  • FX Venues
    • FX Trading – RFQ Maker
  • Intelligent Tagging
  • Legal One
  • Messenger Bot
  • Messenger Side by Side
  • ONESOURCE
    • Indirect Tax
  • Open Calais
  • Open PermID
    • Entity Search
  • Org ID
  • PAM
    • PAM - Logging
  • ProView
  • ProView Internal
  • Product Insight
  • Project Tracking
  • RDMS
  • Refinitiv Data Platform
    • Refinitiv Data Platform Libraries
  • Rose's Space
  • Screening
    • Qual-ID API
    • Screening Deployed
    • Screening Online
    • World-Check One
    • World-Check One Zero Footprint
  • Side by Side Integration API
  • TR Knowledge Graph
  • TREP APIs
    • CAT
    • DACS Station
    • Open DACS
    • RFA
    • UPA
  • TREP Infrastructure
  • TRKD
  • TRTH
  • Thomson One Smart
  • Transactions
    • REDI API
  • Velocity Analytics
  • Wealth Management Web Services
  • Workspace SDK
    • Element Framework
    • Grid
  • World-Check Data File
  • Yield Book Analytics
  • 中文论坛
  • Explore
  • Tags
  • Questions
  • Badges