question

Upvotes
1 0 1 1

Datastream DSWS combining series with and without currency

Hi, I am trying to run ds.get_data(tickers='USSRXBDFB,USCARTKSO', start='2021-01-01', end='-0D', freq='M') but I get error:

ValueError: Item must have length equal to number of levels.

It looks like the first ticker gives a currency level and the 2nd ticker doesn't - is there a way to run these series together in one request? This seemed to work fine until recently.



dsws-api
icon clock
10 |1500

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

Upvotes
13k 32 12 18

Hi @scott.barber ,

There must be some other issue. The query works fine for me:

>>> ds.get_data(tickers='USSRXBDFB,USCARTKSO', start='2021-01-01', end='-0D', freq='M')
Instrument USSRXBDFB USCARTKSO
Field
Dates
2021-01-15   327.796    16.778
2021-02-15   316.879    15.930
2021-03-15   344.077    17.640
2021-04-15   342.689    18.300
2021-05-15   339.043    16.890
2021-06-15   344.230    15.473
2021-07-15   338.013    14.666
2021-08-15   346.884    13.087
2021-09-15   349.714    12.215
2021-10-15       NaN    12.989
2021-11-15       NaN       NaN
icon clock
10 |1500

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

Upvotes
13k 32 12 18

Update, The latest version of DSWS module (1.1.0) has modified the response and is now returning a multiindex instead of single index which was the case in previous version (1.0.9).

There is no different in the JSON request and response from the server and this new index is added at the module level. To get the same desired response, please drop the Currency index from the dataframe and merge them as shown:

df1 = ds.get_data(tickers='USSRXBDFB', start='2021-01-01', end='-0D', freq='M').droplevel('Currency', axis=1)
df2 = ds.get_data(tickers='USCARTKSO', start='2021-01-01', end='-0D', freq='M')
print(df1.merge(df2, on=['Dates']))

Instrument USSRXBDFB USCARTKSO
Field
Dates
2021-01-15   327.796    16.778
2021-02-15   316.879    15.930
2021-03-15   344.077    17.640
2021-04-15   342.689    18.300
2021-05-15   339.043    16.890
2021-06-15   344.230    15.473
2021-07-15   338.013    14.666
2021-08-15   346.884    13.087
2021-09-15   349.714    12.215
2021-10-15       NaN    12.989
2021-11-15       NaN       NaN
icon clock
10 |1500

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

Upvotes
1 0 1 1

Thanks @Gurpreet this works. Is there a reason for the change? Seems like an additional complication.

icon clock
10 |1500

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

The currency response was always returned by server, but previous versions of DSWS didn't include it in the dataframe. The latest version fixed it.
Upvotes
1 0 0 1

@Gurpreet I have similar issue when running below with version 1.1.0. it has been working until the upgrade. It is a hassle to call get_data() one ticker at a time, esp given currency is identical across tickers in my case. Any way to allow calling get_data() with MULTIPLE tickers like we were able to do in the past? Or are you going to allow this feature in your future development? thx

df = ds.get_data(

'CLCURBALA,CTCURBALA',

fields=['DPL#(4*MAV#(X~USD*X(ESMAG)/1000000.0,1Y),4)'],

start=start.strftime('%Y-%m-%d'),

freq='Q')

icon clock
10 |1500

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

Upvotes
23k 22 9 14

Hello @haibo.chen ,

In full alignment with the approach as suggested by @Gurpreet, you can group the instruments enriched with the currency information, together, and the instruments that are not, together, as well. For example:

df1 = ds.get_data(tickers='USSRXBDFB,VOD', start='2021-01-01', end='-0D', freq='M')
df2 = ds.get_data(tickers='USCARTKSO', start='2021-01-01', end='-0D', freq='M')
print(df1.merge(df2, on=['Dates']))

resulting in:

            (USSRXBDFB, , U$)  (VOD, , £)  (USCARTKSO, )
Dates                                                   
2021-01-15            327.796      120.94         16.778
2021-02-15            316.879      126.40         15.930
2021-03-15            344.077      123.64         17.640
2021-04-15            342.689      133.66         18.300
2021-05-15            339.043      136.80         16.890
2021-06-15            344.230      128.26         15.473
2021-07-15            338.013      121.70         14.666
2021-08-15            347.213      116.80         13.087
2021-09-15            348.838      122.26         12.215
2021-10-15            354.388      112.20         12.989
2021-11-15                NaN      109.36            NaN





icon clock
10 |1500

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

Upvotes
1 0 1 1

Agree with @haibo.chen that while this is a solution it is an annoying extra step, especially when I have a long list of tickers. I have to go through and see which ones have currency.

icon clock
10 |1500

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

Upvotes
1 0 0 1

@zoya faberov @scott.barber this is not only inconvenient, this is problematic. in my example,

df = ds.get_data('CLCURBALA,CTCURBALA',fields=['DPL#(4*MAV#(X~USD*X(ESMAG)/1000000.0,1Y),4)'],...) if the ticker raw data has currency in USD, it comes back with currency (CLCURBABA), but if it is in non-USD currency, it comes back with no currency. I have to spend huge amount of time to GO THROUGH the list. The way the package releases are managed is NOT PROFESSIONAL. it should be backward-compatible, and if not, it should raise future warning, or provide a way (such as an additional argument) to allow users, in this case, to ignore currency.

icon clock
10 |1500

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

Upvotes
23k 22 9 14

Hello @scott.barber and @haibo.chen ,

We appreciate your feedback!

We have conveyed your information and suggestions to Datastream product management, for review and consideration.

The feedback from valued customers helps us to continuously improve and actively evolve our products and APIs.

icon clock
10 |1500

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

Click below to post an Idea Post Idea