question

Upvotes
Accepted
5 1 1 3

Date arguments in datastream call

Hi,

I'm new to datastream and have the below two python calls. The first calculates the return over the period in the field brackets and the second is a daily return series of S&P 500.


OneYear=ds.get_data(tickers=Ticker_list, fields=['PCH#(X(RI),6-30-20,6-30-21)'], kind = 0)

Return_Series=ds.get_data (tickers='S&PCOMP', fields=['PCH#(X(RI),-1D)','RI'], start='-4Q', end='-1Q', kind=1)

I have a couple questions.

1) I got some help from the helpdesk on these, but what is the difference between the two formats (other than the dates are within the field argument in the OneYear example) and under what circumstances would I use one option vs. the other?

2) Related to question 1), how can i specify a variable for the date argument in these examples (e.g., if i have an "end_date" variable? I tried entering that in the end field in the Return_Series example but it didn't seem to work.

3) Are there any training resources where I should check for these types of answers?

Thanks very much.

datastream-apidsws-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
Accepted
38.1k 71 35 53

@jason.miller

Yes, you can. However, from the usage guide, the date formats are different.

The data format of the PCH expression is DD/MM/YY while the data format of the start and end parameters in the get_data method is YYYY-MM-DD.

The code looks like this:

start_date_qtr = '2021-03-31' 
end_date = '2021-06-30'


start_date_pch = '31/03/21'
end_date_pch = '30/06/21'


fields = "PCH#(X(RI),{},{})".format(start_date_pch, end_date_pch)
OneYear=ds.get_data(tickers='S&PCOMP', fields=[fields], kind = 0)
Return_Series=ds.get_data (tickers='S&PCOMP', fields=['PCH#(X(RI),-1D)','RI'], start=start_date_qtr, end=end_date, kind=1)
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
38.1k 71 35 53

@jason.miller

Refer to the PCH expression's usage guide, "PCH#(Expression,Start Date,End Date)" calculates a single percentage change in value between two dates so it uses the data on the start date and the end date to calculate a percentage change.

1631069906405.png

"PCH#(Expression,Period)" calculates the percentage change for a time period continuously between the start and end dates for the display period.

1631070119389.png


1631069906405.png (8.8 KiB)
1631070119389.png (21.1 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
5 1 1 3

Great, thanks very much. What about question 2)? Is it possible to include variables in the date arguments for either (both) functions ?

Something like the below?

OneYear=ds.get_data(tickers=Ticker_list, fields=['PCH#(X(RI),start_date_qtr,end_date)'], kind = 0)

Return_Series=ds.get_data (tickers='S&PCOMP', fields=['PCH#(X(RI),-1D)','RI'], start=start_date_qtr, end=end_date, kind=1)

where start_date_qtr = '3-31-21' and end_date = '6-30-21'

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
5 1 1 3

Great, thank you. Last question on this tag I think. Is there a way within the get_data call to only display trade dates (i.e., exclude holidays)?

For example, when i run the aforementioned time series for Q2 (March 31, 2021-June 30, 2021), I notice that April 2, 2021 comes up as having zero as return value and the same RI as April 1, 2021 (because April 2, 2021 was Good Friday and the market was closed). Can i exclude holidays within the function or do i have to take care of this with python functions? Thanks.

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
5 1 1 3

Hi, does anybody know the answer to my question on excluding holidays? Thanks!

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 answer has been provided on this discussion thread.
Click below to post an Idea Post Idea