Error when trying to convert the result from historic.pricing to dataframe

Hi, I'm using the python lseg library and the historic_pricing module. When getting the result and converting it to dataframe, I am getting the error:

ndexError Traceback (most recent call last)
Cell In[7], line 2
1 response = historical_pricing.summaries.Definition(TT).get_data()
----> 2 response.data.df

File c:\Users\Public\Programs\Python_64bit_3.10.04\lib\site-packages\lseg\data\content\_content_data.py:18, in Data.df(self)
15 @property
16 def df(self):
17 if self._dataframe is None:
---> 18 self._dataframe = self._dfbuilder(self.raw, **self._kwargs)
20 return self._dataframe

File c:\Users\Public\Programs\Python_64bit_3.10.04\lib\site-packages\lseg\data\content\_historical_df_builder.py:402, in HistoricalBuilder.build(self, raws, universe, fields, axis_name, use_multiindex, **_)
398 return pd.DataFrame()
400 bad_raws.insert_to(listofcolumns)
--> 402 data, columns, index = items_by_date.process_data(len(raws), listofcolumns, use_multiindex)
404 index = pd.Index(data=index, name=axis_name)
405 df = pd.DataFrame(data=data, columns=columns, index=index)

File c:\Users\Public\Programs\Python_64bit_3.10.04\lib\site-packages\lseg\data\content\_historical_df_builder.py:301, in ItemsByDate.process_data(self, num_raws, listofcolumns, use_multiindex)
299 right_idx = left_idx + len(raw_columns)
300 for item, i in zip(raw_data, range(left_idx, right_idx)):
--> 301 template[i] = item
303 index_append(date)
304 data_append(template)

IndexError: list assignment index out of range

The strange thing about this is that this error occurs when passing some lists of instruments and depending on the order of the list the code works. For example, if I pass "PETR4.SA" as the first item in the list, the code works, but when passing it as the last item, I receive the mentioned error.

This is my code:

import lseg.data as ld
from lseg.data.content import historical_pricing


TT = ['SX3',
'.BNPIUIL5',
'LHJ24',
'CCMF25',
'PETR4.SA']

response = historical_pricing.summaries.Definition(TT).get_data()
response.data.df

Could you help me with how I can get around this problem? My goal is to pass a list with about a thousand different tickers

Best Answer

  • Jirapongse
    Jirapongse ✭✭✭✭✭
    Answer ✓

    @wilker.sousa

    Thank you for reaching out to us.

    I found that 'SX3', '.BNPIUIL5', and 'LHJ24' are invalid instruments.

    The API doesn't work when the first item is invalid. Please contact the helpdesk team directly via MyAccount to verify the instruments.

Answers

  • Thanks for the quick response!!
    Is there any call I can make to check if the instrument is valid? Do you have any recommendations for good practice or what is commonly used by other users?

  • @Jirapongse
    I don't know if the notification will reach you, so this message is just to mark you

  • Jirapongse
    Jirapongse ✭✭✭✭✭

    @wilker.sousa

    You can try the get_data method.

    ld.get_data(
        universe= ['SX3','.BNPIUIL5','LHJ24','CCMF25','PETR4.SA'],
        fields=['TR.RIC']
    )

    1727155206491.png


  • @Jirapongse


    Your suggestion helped me, thank you! However, I still had one doubt. There is the symbol_conversion method. I did a test and gave him the "SX3" instrument. It should return the RIC, but it returned an empty dataframe

    This is my code:

    response = symbol_conversion.Definition("SX3").get_data()

    response.data.df


    Why did it return empty? Why using the symbol_conversion method returns empty and following ld.get_data(

    universe= ['SX3'],

    fields=['TR.RIC']

    ) does it work? Is this expected?

  • Jirapongse
    Jirapongse ✭✭✭✭✭

    They are using the different services or endpoints so the behaviors can be different.

    SX3 is expired so it is not valid RIC anymore. It has been renamed to SX3^2. I think this is why symbol_conversion can't convert this RIC.

    1727861264193.png