How to get the same CSV data as the sample file of the book?

Please tell me the contents of the following csv file introduced in this book and the EIKON API Code to get the same data. This book does not describe how to obtain the data, but instead provides EIKON data as a sample file. With "get_timeseries" I couldn't reproduce the exact same data.

  • Book Name : Python for Finance, 2nd Edition [Book] - O'Reilly
  • CSV : tr_eikon_eod_data.csv (Data excerpt)

image

  • Code I created (The date data is slightly different from the sample.)
data = ek.get_timeseries(['AAPL.O', 'MSFT.O', 'INTC.O', 'AMZN.O', 'GS.N',' SPY', '.SPX', '.VIX', 'EUR=', 'XAU=', 'GDX', 'GLD'],
                         ['CLOSE'],
                         '2010-1-1','2020-10-1')
data
  • Result (Where should I modify the code to get the same result as this?)
ValueError: The truth value of a DataFrame is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().


  • Related code & Result (Add column)

image

Best Answer

  • @Takeshi.Matsuda You should be aware of the API limits - you can find these in this document. You will notice that the get_timeseries API call has a limit of '3,000 data points (rows) for interday intervals and 50,000 data points for intraday intervals. This limit applies to the whole request, whatever the number of requested instrument.'

    Please try this code which iterates across the instrument list to get the correct data without truncation due to limits.

    import eikon as ek
    import pandas as pd
    import numpy as np

    instruments = ['AAPL.O', 'MSFT.O', 'INTC.O', 'AMZN.O', 'GS.N',' SPY', '.SPX', '.VIX', 'EUR=', 'JPY=', 'GDX', 'GLD']

    s = '2010-01-01'
    e = '2020-10-1'
    inv = 'daily'
    data1 = pd.DataFrame()
    for i in instruments:
        df1 = ek.get_timeseries(i,  # RICs
                  fields=['CLOSE'],  # fields to be retrieved
                  start_date=s,  # start time
                  end_date=e,  # end time
                  interval=inv)
        df1.rename(columns = {'CLOSE': i}, inplace = True)
        if len(data1):
            data1 = pd.concat([data1, df1], axis=1)
        else:
            data1 = df1

    data1

    image

    I hope this can help.

Answers