question

Upvotes
Accepted
5 0 1 2

Datastream fetch call for multiple securities failing due to no data in one security

I am trying the below Python code to get price index for 50 securities, but it seems the the call is failing because some of the securities do not have history from the starting date, and hence failing to rebalance to 100; one example being UKBJK28Z9. Could you please help me figure this out? The error message Jupyter Notebook is showing is "

could not broadcast input array from shape (3) into shape (50)

"

-----------------------------------------------------------------------------------------------------------------

num_of_sedol_in_each_set = 45

str_fields = 'REB#(X(PI)~U$)'

char_freq = 'M'

first_day_str = '2019-04-16'

last_day_str = '2021-04-15'


isinlist = ['UKBW9RTW0', 'UK6718976', 'UKB01FLR7', 'UK6706250', 'UK6264048', 'UKB2Q5H56', 'UKB4TX8S1', 'UKB1JKTQ6', 'UKB297KM7', 'UKB2PFVH7', 'UKB0BM5T8', 'UKB2R2ZC9', 'UKB1L3XL6', 'UKBYYDFN0', 'UKB1R0FF9', 'UK6241483', 'UKB55ZBQ7', 'UKBF16M83', 'UK6247726', 'UKBD6FLL7', 'UKBJ0RTH3', 'UKBMC5RM7', 'UKBJVJP36', 'UKBLLJ4H7', 'UKB27WRM3', 'UK2579230', 'UK2606440', 'UKB00PV12', 'UKBF2HB11', 'UKBMMV2K8', 'UKB2NR3Y6', 'UK6465874', 'UKB5B23W2', 'UKB4JSTL6', 'UKB4P8HQ1', 'UKB1KYHF2', 'UKBSS6HX7', 'UKB02TT74', 'UKBLD9KX3', 'UKB0FXT17', 'UKBFNLRN6', 'UKBM67GG6', 'UKBYP71J9', 'UKBF4NQP6', 'UKBHHD4Q4', 'UKBYYNH90', 'UKBGJW376', 'UKBF3B6J5', 'UK2579230', 'UKBJK28Z9']


df_prices = pd.DataFrame()

df_prices = ds.fetch(tickers=isinlist, fields=[str_fields], \

date_from= first_day_str, date_to= last_day_str, freq= char_freq)


df_prices

pythondatastream-apidsws-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.

Upvote
Accepted
55.7k 144 45 65

I can run the code properly in my environment. The output is:

I also found a duplicated item in the list 'UK2579230'.

Please verify the version of PyDatastream library that you are using. The latest version is 0.6.4. You can get it from https://pypi.org/project/PyDatastream/. The PyDatastream library is a third-party Datastream library that is not from Refinitiv. . Therefore, if you find an issue, please directly contact the library's owner via GitHub.

The Python Datastream library from Refinitiv is DatastreamDSWS.


1618987460295.jpeg (16.9 KiB)
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.

Thanks, @jirapongse.phuriphanvichai! I will check my setup and try to replicate yours

Upvotes
55.7k 144 45 65

@Avik Saha

The code runs fine on my environment after removing the following items from the list: UKBMC5RM7, UKBJVJP36, UKBJK28Z9.


1618807596552.png (47.3 KiB)
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.

Thanks, jirapongse.phuriphanvichai.

Is it possible to tweak the code so that i can run for all the 50 sedols in the list? This list of sedols get generated by a different process that gets fed to me; so i dont have control on the sedols in the list. Any chance that it is possible to get the output for all the 50 tickers? For the 3 sedols (UKBMC5RM7, UKBJVJP36, UKBJK28Z9) that do not have full history, i would need to rebase those to 100 on the first day when the data was available.

@Avik Saha

You can set DS.raise_on_error = False so it will not throw the DatastreamException.

DS.raise_on_error = False


DatastreamException: "UKBMC5RM7"("REB#(X(PI)~U$)"): $$ER: 2361,NO DATA AVAILABLE


Upvotes
5 0 1 2

Thanks, again, @jirapongse.phuriphanvichai

Can you please help me figure out how to write the code regarding raising the error? I tried the code below but could not make it work.

-------------------------------------------------------------------

isinlist = ['UKBW9RTW0', 'UK6718976', 'UKB01FLR7', 'UK6706250', 'UK6264048', 'UKB2Q5H56', 'UKB4TX8S1', 'UKB1JKTQ6', 'UKB297KM7', 'UKB2PFVH7', 'UKB0BM5T8', 'UKB2R2ZC9', 'UKB1L3XL6', 'UKBYYDFN0', 'UKB1R0FF9', 'UK6241483', 'UKB55ZBQ7', 'UKBF16M83', 'UK6247726', 'UKBD6FLL7', 'UKBJ0RTH3', 'UKBMC5RM7', 'UKBJVJP36', 'UKBLLJ4H7', 'UKB27WRM3', 'UK2579230', 'UK2606440', 'UKB00PV12', 'UKBF2HB11', 'UKBMMV2K8', 'UKB2NR3Y6', 'UK6465874', 'UKB5B23W2', 'UKB4JSTL6', 'UKB4P8HQ1', 'UKB1KYHF2', 'UKBSS6HX7', 'UKB02TT74', 'UKBLD9KX3', 'UKB0FXT17', 'UKBFNLRN6', 'UKBM67GG6', 'UKBYP71J9', 'UKBF4NQP6', 'UKBHHD4Q4', 'UKBYYNH90', 'UKBGJW376', 'UKBF3B6J5', 'UK2579230', 'UKBJK28Z9']

ds.raise_on_error = False

df_prices_temp = ds.fetch(tickers=isinlist, fields=["REB#(X(PI)~U$)"], \

date_from= '2019-04-16', date_to= '2021-04-15', freq= 'M')

df_prices_temp

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.