How can I use Python's Datastream DSWS to collect data above the limit of 50 instruments?
I use Python's DSWS a lot, and often need to collect few data points for many instruments (more than 50). How can I use Python to loop through instruments and get results in one Pandas data-frame?
Tagged:
0
Best Answer
-
Hi @danieluphromes,
For - as an e.g. - a string 'tickers_of_interest_str' (see comment) from 2020-01-01 to 2020-03-01 and the default field ('X'), you can use the below:
# We need pandas in addition to DSWS as ds
import pandas
# We need to split our string of instruments as a list
tickers_of_interest_lst = tickers_of_interest_str.split(",")
# Get 1st instrument's data
df = ds.get_data(tickers = tickers_of_interest_lst[0],
fields = ['X'],
start = '2020-01-01',
end = '2020-03-01').T
# Define a function to get chunks of 50 instrument lots
def chunks(lst, n):
"""Yield successive n-sized chunks from lst."""
_lst = []
for i in range(0, len(lst), n):
_lst.append(lst[i:i + n])
return _lst
# Use the pre-defined function up to the limit of DSWS - i.e.: 50
tickers_of_interest_chunks = chunks(lst = tickers_of_interest_lst[1:], n = 50)
# Now collect all data and append to df
for i in tickers_of_interest_chunks:
_df = ds.get_data(tickers = ','.join(i),
fields = ['X'],
start = '2020-01-01',
end = '2020-03-01').T
df = df.append(_df)
df = df.T
display(df)0
Answers
-
tickers_of_interest_str = "US01Y00,US02Y00,US03Y00,US04Y00,US05Y00,US06Y00,US07Y00,US08Y00,US09Y00,US10Y00,US11Y00,US12Y00,US13Y00,US14Y00,US15Y00,US16Y00,US17Y00,US18Y00,US19Y00,US20Y00,US21Y00,US22Y00,US23Y00,US24Y00,US25Y00,US26Y00,US27Y00,US28Y00,US29Y00,US30Y00,US31Y00,US32Y00,US33Y00,US34Y00,US35Y00,US36Y00,US37Y00,US38Y00,US39Y00,US40Y00,US41Y00,US42Y00,US43Y00,US44Y00,US45Y00,US46Y00,US47Y00,US48Y00,US49Y00,US50Y00,UK01Y00,UK02Y00,UK03Y00,UK04Y00,UK05Y00,UK06Y00,UK07Y00,UK08Y00,UK09Y00,UK10Y00,UK11Y00,UK12Y00"
0
Categories
- All Categories
- 6 AHS
- 39 Alpha
- 161 App Studio
- 4 Block Chain
- 4 Bot Platform
- 16 Connected Risk APIs
- 47 Data Fusion
- 30 Data Model Discovery
- 608 Datastream
- 1.3K DSS
- 577 Eikon COM
- 4.9K Eikon Data APIs
- 7 Electronic Trading
- Generic FIX
- 7 Local Bank Node API
- Trading API
- 2.7K Elektron
- 1.3K EMA
- 236 ETA
- 519 WebSocket API
- 33 FX Venues
- 10 FX Market Data
- 1 FX Post Trade
- 1 FX Trading - Matching
- 12 FX Trading – RFQ Maker
- 5 Intelligent Tagging
- 2 Legal One
- 20 Messenger Bot
- 2 Messenger Side by Side
- 9 ONESOURCE
- 7 Indirect Tax
- 59 Open Calais
- 264 Open PermID
- 39 Entity Search
- 2 Org ID
- PAM
- PAM - Logging
- 8.4K Private Comments
- 6 Product Insight
- Project Tracking
- ProView
- ProView Internal
- 20 RDMS
- 1.4K Refinitiv Data Platform
- 367 Refinitiv Data Platform Libraries
- 3 Refinitiv Due Diligence
- LSEG Due Diligence Portal API
- 3 Refinitiv Due Dilligence Centre
- Rose's Space
- 1.1K Screening
- 18 Qual-ID API
- 13 Screening Deployed
- 23 Screening Online
- 10 World-Check Customer Risk Screener
- 990 World-Check One
- 44 World-Check One Zero Footprint
- 45 Side by Side Integration API
- Test Space
- 3 Thomson One Smart
- 1.2K TR Internal
- Global Hackathon 2015
- 2 Specialists Who Code
- 10 TR Knowledge Graph
- 150 Transactions
- 142 REDI API
- 1.7K TREP APIs
- 4 CAT
- 21 DACS Station
- 117 Open DACS
- 1.1K RFA
- 103 UPA
- 172 TREP Infrastructure
- 224 TRKD
- 886 TRTH
- 5 Velocity Analytics
- 5 Wealth Management Web Services
- 59 Workspace SDK
- 9 Element Framework
- 5 Grid
- 13 World-Check Data File
- Yield Book Analytics
- 46 中文论坛