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.



Tagged:

Best Answer

  • zoya faberov
    zoya faberov ✭✭✭✭✭
    Answer ✓

    Hello @scott.barber , @haibo.chen , @Gurpreet, @raksina.samasiri,

    Please be informed:

    "... We have put a change in place to remedy this

    This issue was due to null currency for some instruments. The currency displayed will be 'NA' in case of null currency, instead of exceptions while uploading data to dataframe. We have uploaded the new version 1.0.10. "


Answers

  • 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
  • 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
  • Thanks @Gurpreet this works. Is there a reason for the change? Seems like an additional complication.

  • 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.
  • @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')

  • zoya faberov
    zoya faberov ✭✭✭✭✭

    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





  • 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.

  • @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.

  • zoya faberov
    zoya faberov ✭✭✭✭✭

    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.