question

Upvotes
Accepted
4 0 0 1

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 5.0 MiB each and 10.0 MiB total.

Upvotes
Accepted
38.1k 69 35 53

@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 5.0 MiB each and 10.0 MiB total.

Upvotes
4 0 0 1

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 5.0 MiB each and 10.0 MiB total.

Click below to post an Idea Post Idea