Unable to retrieve stock prices before 2008 with get_time_series

I'm trying to build a database with the adjusted close prices for all the components of the Stoxx 600, from 2000 to 2020. But I only get data no earlier than 2008, even for those stocks that existed before that year (i.e. volkswagen). I'm using this code and getting the result below.

adjusted_prices = []
for stock in range(len(rics)):
adjusted_prices.append(ek.get_timeseries(rics[stock], fields='CLOSE', start_date="2000-01-01", end_date="2020-12-30", interval="daily", corax="adjusted")image

Best Answer

Answers

  • Hi, thank you for the help, but there is a problem with it, I downloaded the ric's list of the STOXX 600 components as of today to run this code, the problem is that if I set a range from 2000 to 2008 a lot of these stocks won't have data for the specified range, so python will return an error code -1. Is there a way to get a list of Rics for the period I want? Or maybe a way to create exceptions on python for this error so that ignore that stocks with no data?

  • Hi @giosue.bruccoleri01

    You can use try/except code block.

    image

  • I tried with this solution, but it stops until the first error, so I get only the first six stocks, do you know how to make the process skip the error and go on with the other stocks? image

  • Hi @giosue.bruccoleri01

    You can arrange your code to be like this:

    Note that this is a pseudocode.

    for ric in ric_list:
        try:
            df = ek.get_timeseries(ric, xxx, xxx)
            #if you code is here, you get the data successfully
            #process df according to your requirement
        except ek.EikonError as err:
            print(err)
            #if you code is here, you get some error
        #this is end of try/except block, back to for loop


    Please also review Python For loop tutorial.