question

Upvotes
Accepted
4 2 5 7

How to recreate DS.get_epit_vintage_matrix('USCONPRCE', date_from='1950-01-01') in DSWS library?

Hi,

I wish to create a vintage matrix as shown below for Economic Point in Time data. I created this using the 3rd party "pydatastream" library, with the following function:

DS.get_epit_vintage_matrix('USCONPRCE', date_from='1950-01-01').

I was advised to use the supported DSWS library instead to achieve this goal, however I am unable to do so with the limited documentation available

This vintage matrix contains all releases for this instrument, as well as all dates that this data was revised.

Could somebody please show me how to create this using the DSWS library?

Thanks!

datastream-apidsws-api
1580319504543.png (28.0 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.

Hello @pvilleneuve

Thank you for your participation in the forum. Is the reply below satisfactory in resolving your query?


If so please can you click the 'Accept' text next to the appropriate reply. This will guide all community members who have a similar question.

Thanks,


AHS


Please be informed that a reply has been verified as correct in answering the question, and has been marked as such.

Thanks,

AHS

Upvotes
Accepted
79.1k 250 52 74

@pvilleneuve

Refer to the source code of pydatastream on GitHub, DS.get_epit_vintage_matrix uses a lot of requests to generate the data. You can translate the code that calls self.fetch to the get_data method of DatastreamDSWS.

For example, the code for get_epit_vintage_matrix looks like:

def get_epit_vintage_matrix(mnemonic, date_from='1951-01-01', date_to=None):
    rel1 = ds.get_data (tickers=mnemonic,fields= ['REL1'], start=date_from, end=date_to, kind=1)
    date_0 = rel1.dropna().index[0]
    reld123 = ds.get_data(tickers=mnemonic, fields= ['RELD1', 'RELD2', 'RELD3'],
                          start=date_0, end=date_to, kind=1).dropna(how='all')
    res = {}
    for date in reld123.index:
        try:
            _tmp = ds.get_data(tickers=mnemonic, fields= ['RELV'], 
                               start=date_0, end=date, kind=1).dropna()    
        except DatastreamException:
            continue
        res[date] = _tmp[mnemonic]
    return pd.concat(res).RELV.unstack()

ds represents the DSWS.Datastream.

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.

Upvotes
4 2 5 7

Thanks, this worked. Just had to remove "DatastreamException" and fix one "mnuemonic" typo and it ran.

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.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

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