The Data Library for Python  - Quick Reference Guide (Access layer)

Raksina Samasiri
Developer Advocate Developer Advocate

This is a quick reference guide for the Data Library for Python on different asset types

If you’re new to the library, a shallow dive into LSEG APIs landscape, including the introduction to data library can be found in article Summary of Common LSEG Refinitiv APIs

Please note that the data library in Codebook is the version 1 (Refinitiv Data Library). It will be upgraded to the newer version, version 2 - LSEG Data Library soon.

  • After the rebranding and release of LSEG Data Library 2.0, the Refinitiv Data Library will become " Feature Complete", but we will continue to support it and provide maintenance releases. This is essential for customers who cannot migrate to the LSEG Data Library 2.0. However, new features will only be added to the LSEG data library.

In this article, we are focusing on using the access layer, which is the easiest way to get data. It provides simple interfaces allowing you to rapidly prototype solutions within interactive environments such as Jupyter Notebooks. It has been designed for quick experimentation with our data and for Financial Coders specific needs. (To learn more about Data Library for Python’s layers: example codes can be found here)

Table of contents

Here’s what included in this quick reference guide.

  1. Search
  2. Symbology
    Convert symbols, Get data - get RIC from bond, Get data - get CUSIP and international CUSIP, Get data with Screener, Get data with Peers, Get data of instruments with all available fields, Get data of instruments with specific fields, Get constituent with Chain object
  3. Timeseries
    Get data with field level parameter, Get data with request level parameter (global parameter), Get history
  4. Company guidance
  5. Earnings
  6. Analyst recommendations
  7. Industry Analysis / The Reference data Business Classification (TRBC)
  8. Ownership data
  9. Corporate actions data
  10. Volatility
    Volatility, Equity implied volatility, Futures implied volatility
  11. Portfolio and Lists
    Portfolio, List, Monitor, Index/exchange constituents as of certain date, Index leavers/joiners
  12. Index and Constituents
  13. Fixed income data
    Bond status, Fixed income securities core reference data, Bond pricing, Bond analytics, Historical bond pricing, Historical analytics, Credit default swaps
  14. Pricing streams
    Using pricing streams with events, Using pricing streams as a data cache, Get a snapshot for a subset of instruments and fields

Quick Reference Guide

1) Search

  • The search() function identifies a matching set of documents which satisfy the caller's criteria, sorts it, and selects a subset of the matches to return as the result. The search can be performed easily with the help of Advanced Search tool provided in Workspace / Eikon application
  • To understand more about the search function, a powerful, search engine covering content such as quotes, instruments, organizations, and many other assets that can be programmatically integrated within your business Workflow, it’s introduced in this article
    	
            

# Search for Equities with Exchange Name is NYSE Consolidated, descending ordered by Market Cap Company in USD

search_df = ld.discovery.search(

    view = ld.discovery.Views.EQUITY_QUOTES,

    top = 10, # select only top 10 rows of the result

    filter = "(SearchAllCategoryv2 eq 'Equities' and ExchangeName xeq 'NYSE Consolidated')",

    select = "DTSubjectName,ExchangeName,RIC,IssueISIN,MktCapCompanyUsd",

    order_by = "MktCapCompanyUsd desc"

)

 

search_df

2) Symbology

Convert symbols

    	
            

# Example 1 - convert_symbols()

from lseg.data.discovery import (

    convert_symbols,

    SymbolTypes

)

 

# Convert to all available symbol types

response = convert_symbols(

    symbols=['IBM','LSEG.L','MSFT.O','AAPL.O']

)

response

    	
            

# Available SymbolTypes - run help(SymbolTypes)  

    # CUSIP = <SymbolTypes.CUSIP: 'CUSIP'>

    # ISIN = <SymbolTypes.ISIN: 'IssueISIN'>

    # LIPPER_ID = <SymbolTypes.LIPPER_ID: 'FundClassLipperID'>

    # OA_PERM_ID = <SymbolTypes.OA_PERM_ID: 'IssuerOAPermID'>

    # RIC = <SymbolTypes.RIC: 'RIC'>

    # SEDOL = <SymbolTypes.SEDOL: 'SEDOL'>

    # TICKER_SYMBOL = <SymbolTypes.TICKER_SYMBOL: 'TickerSymbol'>

 

# Convert from ticker to RIC, OA Perm ID

response = convert_symbols(

    symbols=['IBM','LSEG','MSFT','AAPL'], 

    from_symbol_type=SymbolTypes.TICKER_SYMBOL,

    to_symbol_types=[SymbolTypes.RIC, SymbolTypes.OA_PERM_ID],

    preferred_country_code="USA"

)

response

Get data

    	
            

# Example 2 - Get RIC from bond

preferred_ric = ld.get_data('US9128283J70',fields=['TR.PreferredRIC'])

preferred_ric

    	
            

# Example 3 - Get CUSIP and international CUSIP

rics = ['IBM.N', 'VOD.L', 'GOOG.O', '0005.HK']

fields = ['TR.CUSIP', 'TR.CUSIPExtended', 'TR.PriceClose']

 

cusip_df = ld.get_data(rics, fields)

cusip_df

    	
            

# Example 4 - Screener

from lseg.data.discovery import Screener

 

screener_request = Screener('U(IN(Equity(active,public,primary))), IN(TR.TRBCEconSectorCode,"51"), TR.CompanyMarketCap>=10000000000,CURN=USD')

#print(list(screener_request))

screener_df = ld.get_data(screener_request, fields=['TR.RIC','TR.CompanyName'])

screener_df

    	
            

# Example 5 - Peers

from lseg.data.discovery import Peers

 

microsoft_peers = Peers('MSFT.O')

print(list(microsoft_peers))

    	
            ['CRM.N', 'ORCL.N', 'ADBE.OQ', 'AMZN.OQ', 'META.OQ', 'IBM.N', 'OKTA.OQ', 'AAPL.OQ', 'CSCO.OQ', '0700.HK', 'SAPG.DE', 'HPE.N', '6758.T', '7974.T', 'ZTNO.PK', 'SNOW.N', 'NOW.N', 'WDAY.OQ', 'INTU.OQ', 'DDOG.OQ', 'TEAM.OQ', 'DOCU.OQ', 'MDB.OQ', 'HUBS.N', 'CFLT.OQ', 'PANW.OQ', 'PLTR.N', 'PATH.N', 'GOOGL.OQ', 'ZM.OQ', 'ZI.OQ', 'NVDA.OQ', 'TWLO.N', 'CRWD.OQ', 'ZS.OQ', 'DT.N', 'NET.N', 'SHOP.N', 'ADSK.OQ', 'HCP.O', 'FTNT.OQ', 'VEEV.N', 'INFA.N', 'ESTC.N', 'SMAR.N', 'IOT.N', 'MNDY.OQ', 'ASAN.N', 'GTLB.OQ', 'AMD.OQ']
        
        
    
    	
            

# Use the microsoft peers with get_history()

peers_df = ld.get_history(microsoft_peers, ['BID', 'ASK'], start = '2024-02-01', end = '2024-02-08')

peers_df

    	
            

# Example 6 - get data of instruments with specific fields - pricing snapshot

df = ld.get_data(['LSEG.L', 'VOD.L'], ['BID', 'ASK'])

df

    	
            

# Example 7 - get data of instruments with specific fields (add field name in field parameter)

df = ld.get_data(['LSEG.L', 'VOD.L'], ['TR.CommonName', 'TR.Revenue'])

df

    	
            

# Example 8 - get constituent with Chain object

from lseg.data.discovery import Chain

fchi = Chain("0#.FCHI")

print(fchi.constituents)

    	
            ['ACCP.PA', 'AIRP.PA', 'AIR.PA', 'MT.AS', 'AXAF.PA', 'BNPP.PA', 'BOUY.PA', 'CAPP.PA', 'CARR.PA', 'CAGR.PA', 'DANO.PA', 'DAST.PA', 'EDEN.PA', 'ENGIE.PA', 'ESLX.PA', 'EUFI.PA', 'HRMS.PA', 'PRTP.PA', 'OREP.PA', 'LVMH.PA', 'LEGD.PA', 'MICP.PA', 'ORAN.PA', 'PERP.PA', 'PUBP.PA', 'RENA.PA', 'SAF.PA', 'SGOB.PA', 'SASY.PA', 'SCHN.PA', 'SOGN.PA', 'STLAM.PA', 'STMPA.PA', 'TEPRF.PA', 'TCFP.PA', 'TTEF.PA', 'URW.PA', 'VIE.PA', 'SGEF.PA', 'VIV.PA']
        
        
    
    	
            print(fchi.summary_links)
        
        
    
    	
            ['.DJI', 'EUR=', '/.STOXX50E', '.FCHI', '.AD.FCHI']
        
        
    
    	
            

# Example 8.1 - use the chain with get_data()

ld.get_data(fchi, ['BID', 'ASK', 'TR.Revenue'])

    	
            

# Example 8.2 - use the chain with get_history()

ld.get_history(fchi, ['BID', 'ASK'])

3) Timeseries

3.1) Get data with field level parameters

Available parameters of each field can be found in Parameters tab in CodeCreator app of Workspace.

    	
            

# Example 1 - field level parameters are applied into each field

rics = ['AAPL.O','IBM','MSFT.O','LSEG.L']

 

# Parameters used are

    # SDate=2024-01-15 # start date

    # EDate=2024-01-17 # end date

    # Frq=D # frequency = daily

 

df = ld.get_data(rics,

                   ['TR.PriceClose(SDate=2024-01-15,EDate=2024-01-17,Frq=D).date',

                    'TR.PriceClose(SDate=2024-01-15,EDate=2024-01-17,Frq=D)',

                    'TR.TotalReturn1Mo(SDate=2024-01-15,EDate=2024-01-17,Frq=D)'])

df

3.2) Get data with request level parameter (global parameter)

    	
            

#Example 2 - request level parameters are applied to all fields in the request

rics = ['AAPL.O','IBM','MSFT.O','LSEG.L']

 

# Parameters used are

    # SDate=2024-01-15 # start date

    # EDate=2024-01-17 # end date

    # Frq=D # frequency = daily

 

df = ld.get_data(rics,

                 ['TR.PriceClose.date','TR.PriceClose','TR.TotalReturn1Mo'],

                 {'SDate':'2024-01-15','EDate':'2024-01-17','Frq':'D'}

                )

df

3.3) Get history

    	
            

#Example 3 - retrieve timeseries data with get_history() function

 

rics = ['MSFT.O','LSEG.L']

 

# no field specified -> all available field will be returned

df = ld.get_history(rics,

                    start = '2024-01-15',

                    end = '2024-01-17'

                   )

df

    	
            

# pick only interested fields, add them into the 'fields' parameter

 

# Supported intervals are:

    # tick, tas, taq, minute, 1min, 5min, 10min, 30min, 60min, hourly, 1h, daily,

    # 1d, 1D, 7D, 7d, weekly, 1W, monthly, 1M, quarterly, 3M, 6M, yearly, 1Y

        

df = ld.get_history(universe = rics,

                    fields = ['BID', 'ASK'],

                    start = '2024-01-15',

                    end = '2024-01-17',

                    interval = 'daily'

                   )

df

4) Company Guidance

    	
            

fields = ['TR.GuidanceMeasure',

          'TR.GuidancePeriodYear',

          'TR.GuidancePeriodMonth',

          'TR.GuidanceDate',

          'TR.GuidanceText',

          'TR.GuidanceSpeaker',

          'TR.GuidanceDocType']

 

guidance = ld.get_data('TSLA.O', fields, {'Period': 'FY1'})

guidance

5) Earnings

    	
            

rics = ['TSLA.O','AAPL.O','IBM','AMZN.O','JPM','GS']

fields = ['TR.EpsSmartEst','TR.EPSMean','TR.EpsPreSurprisePct','TR.EpsPreSurprise',

          'TR.EpsPreSurpriseFlag','TR.EPSMedian','TR.EPSLow','TR.EPSHigh']

 

earnings_df = ld.get_data(rics, fields)

earnings_df

6) Analyst Recommendations

    	
            

fields = ['TR.AnalystName','TR.RecLabelEstBrokerName','TR.RecEstValue',

          'TR.BrkRecLabel','TR.TPEstValue','TR.EPSLTGEstValue',

          'TR.SingleStockRatingRecommendation1to5T24M',

          'TR.SingleStockRatingRecommendation1to100T24M',

          'TR.RecMean','TR.PriceTargetMean','TR.LTGMean']

 

analysts_df = ld.get_data(['TSLA.O'], fields)

analysts_df

7) Industry Analysis / The Reference data Business Classification (TRBC)

    	
            

rics = ['AIRP.PA','BASFn.DE','1COV.DE','AKZO.AS','DSMN.AS','LXSG.DE','SOLB.BR','CLN.S']

fields = ['TR.CommonName','TR.TRBCEconomicSector','TR.TRBCBusinessSector',

          'TR.TRBCIndustryGroup','TR.TRBCIndustry','TR.TRBCActivity',

          'TR.TRBCEconSectorCode','TR.TRBCBusinessSectorCode','TR.TRBCIndustryGroupCode',

          'TR.TRBCIndustryCode','TR.TRBCActivityCode']

 

trbc_df = ld.get_data(rics, fields)

trbc_df

8) Ownership Data

    	
            

# Example 1

fields = ['TR.InsiderFullName','TR.InsiderFullName.date',

          'TR.AdjSharesTraded','TR.TransactionDate','TR.AdjSharesHeld']

 

own = ld.get_data('LSEG.L', fields ,{'SDate':'2022-02-16','EDate':'2024-02-15','Frq':'Q'})

own

    	
            

# Example 2

fields = ['TR.FundPortfolioName','TR.FundInvestorType','TR.FdAdjPctOfShrsOutHeld',

          'TR.FundAdjShrsHeld','TR.FdAdjSharesHeldValue','TR.FundHoldingsDate']

 

own = ld.get_data('MSFT.O', fields,{'SDate':-25,'EDate':-24,'Frq':'D'})

own = own[own["Fund Shares Held (Adjusted)"]!=0].reset_index(drop=True)

own

9) Corporate Actions Data

    	
            

fields = ['TR.EventType','TR.EventTitle','TR.EventStartDate','TR.EventLastUpdate']

parameters = {'SDate':'2021-08-01','EventType':'ALL','EDate':'2023-11-20'}

 

corax = ld.get_data('AAPL.O', fields, parameters)

corax

10) Volatility

    	
            

# Example 1

vols_profile=['TR.Volatility2D','TR.Volatility5D','TR.Volatility10D',

              'TR.Volatility15D','TR.Volatility20D','TR.Volatility25D',

              'TR.Volatility30D','TR.Volatility40D','TR.Volatility50D',

              'TR.Volatility60D','TR.Volatility90D','TR.Volatility100D',

              'TR.Volatility120D','TR.Volatility150D','TR.Volatility160D',

              'TR.Volatility180D','TR.Volatility240D','TR.Volatility250D',

              'TR.Volatility260D']

 

vols = ld.get_data(['AAPL.O','IBM.N','AOT.BK'], vols_profile)

vols.transpose()

    	
            

# Example 2

# EQUITY IMPLIED VOLS  = Ticker + "ATMIV.U" (Reference the IMPLIEDVOL speed_guide within Eikon)

RIC = 'WMT' + 'ATMIV.U'

 

fields = ['TR.30DAYATTHEMONEYIMPLIEDVOLATILITYINDEXFORCALLOPTIONS',

          'TR.30DAYATTHEMONEYIMPLIEDVOLATILITYINDEXFORPUTOPTIONS',

          'TR.60DAYATTHEMONEYIMPLIEDVOLATILITYINDEXFORCALLOPTIONS',

          'TR.60DAYATTHEMONEYIMPLIEDVOLATILITYINDEXFORPUTOPTIONS',

          'TR.90DAYATTHEMONEYIMPLIEDVOLATILITYINDEXFORCALLOPTIONS',

          'TR.90DAYATTHEMONEYIMPLIEDVOLATILITYINDEXFORCALLOPTIONS']

 

implied_vol = ld.get_data(RIC, fields,{'SDate':0,'EDate':-10,'Frq':'D'})

implied_vol

    	
            

# Example 3

# Futures Implied Vols = Ticker + 'ATMIV' (refernce FUT/IMPLIEDVOL1 Speed Guide in Eikon)

# Examples,  Corn (1CATMIV), Wheat (1WATMIV), Crude Oil (CLATMIV), 10Y UST(2TYATMIV)...

 

RICS = ['1CATMIV','1WATMIV','CLATMIV']

fields = ['TR.30DAYATTHEMONEYIMPLIEDVOLATILITYINDEXFORCALLOPTIONS',

          'TR.30DAYATTHEMONEYIMPLIEDVOLATILITYINDEXFORPUTOPTIONS',

          'TR.60DAYATTHEMONEYIMPLIEDVOLATILITYINDEXFORCALLOPTIONS',

          'TR.60DAYATTHEMONEYIMPLIEDVOLATILITYINDEXFORPUTOPTIONS',

          'TR.90DAYATTHEMONEYIMPLIEDVOLATILITYINDEXFORCALLOPTIONS',

          'TR.90DAYATTHEMONEYIMPLIEDVOLATILITYINDEXFORCALLOPTIONS']

 

fut_implied_vol = ld.get_data(RICS, fields)

fut_implied_vol

11) Portfolios and Lists

    	
            

# Example 1 - Portfolio

fields = ['TR.PortfolioStatementDate','TR.PortfolioModifiedDate','TR.PortfolioConstituentName',

          'TR.PortfolioShares','TR.PortfolioWeight','TR.PortfolioDate',

          'TR.PriceClose','TR.CompanyMarketCap']

 

port_data = ld.get_data(["Portfolio('TEST-PORTFOLIO','20240221')"], fields)

port_data

    	
            

# Example 2 - List

list_data = ld.get_data("List('test-list')",['TR.RIC','CF_LAST'])

list_data

    	
            

# Example 3 - Monitor

monitor_data = ld.get_data("Monitor('TEST-MONITOR')",['TR.RIC','CF_LAST'])

monitor_data

12) Index and Constituents

There's an article Building historical index constituents, which explain the process of building historical constituents of a market index, underscoring its importance for investors, researchers, and various participants in the financial markets.

    	
            

# Example 1 - Index/Exchange Constituents as of certain date

index_data = ld.get_data('0#.IXIC(20230102)',['TR.RIC'])

index_data

    	
            

# Example 2 - Index Leavers/Joiners

fields = ['TR.IndexJLConstituentRIC','TR.IndexJLConstituentName','TR.IndexJLConstituentChangeDate.change']

 

leavers_joiners = ld.get_data('.SPX', fields,{'SDate':'20190101','EDate':'20191201','IC':'B'})

leavers_joiners

13) Fixed Income Data

    	
            

# Example 1 - Bond Status

rics = ['841338AA4=','717081EP4=','US10YT=RR','FR201534887=','931142BF9=','909279AG6=']

fields = ['TR.FiIssuerName','TR.FiNetCoupon','TR.FiMaturityDate','TR.FIAssetStatus','TR.FiAssetStatusDescription']

 

bond_status = ld.get_data(rics, fields)

bond_status

    	
            

# Example 2 - Fixed Income Securities Core Reference Data

rics = ['717081EP4=','US10YT=RR','FR201534887=','931142BF9=','DE182350257=']

fields = ['TR.FiIssuerName','TR.FiParentTicker','TR.ISIN','TR.CUSIP','TR.FiCurrency',

          'TR.FiNetCoupon','TR.FiMaturityDate','TR.FiIndustrySubSectorDescription',

          'TR.FiSPRating','TR.FiMoodysRating','TR.FiFitchsRating','TR.FiFaceOutstanding']

 

fi_sec_master = ld.get_data(rics, fields)

fi_sec_master

    	
            

# Example 3 - Bond Pricing

bond_rics=['US931142CB75=TE','931142CB7=RRPS','931142CB7=','931142CB7=2M','931142CB7=1M']

fields = ['CF_SOURCE','TR.BIDPRICE','TR.ASKPRICE','TR.MIDPRICE','TR.BIDYIELD','TR.MIDYIELD','TR.ASKYIELD']

 

bond_prices = ld.get_data(bond_rics, fields)

bond_prices.sort_values(['Mid Price'])

    	
            

# Example 4 - Bond Analytics

RICS = ['717081EP4=','US10YT=RR','FR201534887=','931142BF9=','DE182350257=']

fields = ['TR.YieldToMaturityAnalytics','TR.YieldToWorstAnalytics','TR.DurationAnalytics',

          'TR.ModifiedDurationAnalytics','TR.ConvexityAnalytics','TR.GovernmentSpreadAnalytics',

          'TR.SwapSpreadAnalytics','TR.AssetSwapSpreadAnalytics','TR.ZSpreadAnalytics','TR.OASAnalytics']

 

fi_analytics = ld.get_data(RICS, fields)

fi_analytics

    	
            

# Example 5 - Historical Bond Pricing

point_in_time = ld.get_data(['717081EP4='],

                                ['TR.YieldToMaturityAnalytics'],

                                {'SDate':'2024-01-17','EDate':'2024-01-17','Frq':'D'})

point_in_time

    	
            

# Example 6 - Historical Analytics

ytm = ld.get_data(['717081EP4='],

                     ['TR.YieldToMaturityAnalytics(ValuationDate=2024-02-10)',

                      'TR.ModifiedDurationAnalytics(ValuationDate=2024-02-10)',

                      'TR.ConvexityAnalytics(ValuationDate=2024-02-10)'])

ytm

    	
            

# Example 7 - Credit Default Swaps

import time

 

# Expanding the chain with function (in case the Chain RIC is not supported by the library)

def get_underlying(base_ric):

    LONGNEXTLR = base_ric

    #For LONGLING1 to LONGLINK15 and LONGNEXTLR fields

    fields = ['LONGLINK{}'.format(x) for x in range(1, 15)]

    fields.append('LONGNEXTLR')

 

    all_underlying_rics = []

 

    #if LONGNEXTLR is not empty, try to retrieve the data fields

    while LONGNEXTLR!='':

        df = ld.get_data(LONGNEXTLR,fields)

        LONGNEXTLR = df.iloc[0]['LONGNEXTLR'] if pd.notnull(df.iloc[0]['LONGNEXTLR']) else ''

        

        #If LONGLINK<x> field is not null, append its value to all_underlying_rics list

        for x in range(1, 15):

            currentField = 'LONGLINK{}'.format(x)

            all_underlying_rics.append(df.iloc[0][currentField]) if pd.notnull(df.iloc[0][currentField]) else None

        #delay between each API call for 1 second

        time.sleep(1)

    return all_underlying_rics

 

cdx = get_underlying('0#CDXIG5YC=R')

print(cdx)

    	
            ['CDXIG5Y=R', 'MSPRDHEADER=', 'AEP5YUSAX=R', 'AESC5YUSAX=R', 'AIG5YUSAX=R', 'ALL5YUSAX=R', 'GMAC5YUSAX=R', 'MO5YUSAX=R', 'AMD5YUSAX=R', 'AXP5YUSAX=R', 'AMGN5YUSAX=R', 'APA5YUSAX=R', 'ARW5YUSAX=R', 'FSFF5YUSAX=R', 'T5YUSAX=R', 'AZO5YUSAX=R', 'AVT5YUSAX=R', 'ABX5YUSAX=R', 'BAX5YUSAX=R', 'BRK5YUSAX=R', 'BBY5YUSAX=R', 'BLCK5YUSAX=R', 'BA5YUSAX=R', 'BWA5YUSAX=R', 'BSX5YUSAX=R', 'BMY5YUSAX=R', 'CPB5YUSAX=R', 'COF5YUSAX=R', 'CAH5YUSAX=R', 'CAT5YUSAX=R', 'CNQ5YUSAX=R', 'CSCF5YUSAX=R', 'CMCS5YUSAX=R', 'CAG5YUSAX=R', 'COX5YUSAX=R', 'CSX5YUSAX=R', 'CVS5YUSAX=R', 'DHR5YUSAX=R', 'DRI5YUSAX=R', 'DE5YUSAX=R', 'DELL5YUSAX=R', 'DVN5YUSAX=R', 'D5YUSAX=R', 'DOW5YUSAX=R', 'DHI5YUSAX=R', 'DXC5YUSAX=R', 'EMN5YUSAX=R', 'ENB5YUSAX=R', 'ETE5YUSAX=R', 'EXC5YUSAX=R', 'EXPE5YUSAX=R', 'FDX5YUSAX=R', 'FE5YUSAX=R', 'F5YUSAX=R', 'FCX5YUSAX=R', 'GE5YUSAX=R', 'GIS5YUSAX=R', 'GMA5YUSAX=R', 'HAL5YUSAX=R', 'HCA5YUSAX=R', 'HES5YUSAX=R', 'HD5YUSAX=R', 'HON5YUSAX=R', 'HSTL5YUSAX=R', 'HPQ5YUSAX=R', 'IBM5YUSAX=R', 'IP5YUSAX=R', 'TYCH5YUSAX=R', 'JNJ5YUSAX=R', 'KINE5YUSAX=R', 'HNZ5YUSAX=R', 'KR5YUSAX=R', 'LEN5YUSAX=R', 'LNC5YUSAX=R', 'LMT5YUSAX=R', 'LTR5YUSAX=R', 'LOW5YUSAX=R', 'MPCA5YUSAX=R', 'MAR5YUSAX=R', 'MCD5YUSAX=R', 'MCK5YUSAX=R', 'MDC5YUSAX=R', 'MET5YUSAX=R', 'KFT5YUSAX=R', 'MOT5YUSAX=R', 'NRUF5YUSAX=R', 'NFLX5YUSAX=R', 'NEM5YUSAX=R', 'FPLG5YUSAX=R', 'NSC5YUSAX=R', 'NORV5YUSAX=R', 'OXY5YUSAX=R', 'OMC5YUSAX=R', 'ORCL5YUSAX=R', 'PKG5YUSAX=R', 'CBS5YUSAX=R', 'PFE5YUSAX=R', 'PG5YUSAX=R', 'PRUX5YUSAX=R', 'PHM5YUSAX=R', 'DGX5YUSAX=R', 'RDN5YUSAX=R', 'UTX5YUSAX=R', 'R5YUSAX=R', 'SRE5YUSAX=R', 'SHW5YUSAX=R', 'SPGL5YUSAX=R', 'SO5YUSAX=R', 'LUV5YUSAX=R', 'DTEI5YUSAX=R', 'TGT5YUSAX=R', 'TECK5YUSAX=R', 'TOL5YUSAX=R', 'TCA5YUSAX=R', 'TSN5YUSAX=R', 'UNP5YUSAX=R', 'UNH5YUSAX=R', 'UPS5YUSAX=R', 'VLO5YUSAX=R', 'VZ5YUSAX=R', 'WMT5YUSAX=R', 'DISY5YUSAX=R', 'WY5YUSAX=R', 'WHR5YUSAX=R', 'WMB5YUSAX=R', 'AVGE5YUSAX=R', 'OVV5YUSAX=R']
        
        
    
    	
            

fields = ['TR.CDSOrgShortName','TR.CDSTenor','TR.PARMIDSPREAD','TR.SPREADOVERRATING',

          'TR.SPREADOVERSECTOR','TR.SPREADOVERSUBSECTOR','TR.DEFAULTPROBABILITY']

 

cds = ld.get_data(cdx, fields)

cds.dropna()

14) Pricing streams

EX-1.01.03-PricingStream.ipynb

    	
            

# Example 1 - Using pricing streams with events

 

import datetime

from IPython.display import display, clear_output

 

# Define a callback to receive data events

def display_data(data, instrument, stream):

    clear_output(wait=True)

    current_time = datetime.datetime.now().time()

    print(current_time, "- Data received for", instrument)

    display(data)

 

# Open the stream and register the callback

stream = ld.open_pricing_stream(

    universe=['GBP=', 'EUR=', 'JPY='],

    fields=['BID', 'ASK'],

    on_data=display_data

)

    	
            

# Close the stream

stream.close()

    	
            <OpenState.Closed: 'Closed'>
        
        
    
    	
            

# Example 2 - Using pricing streams as a data cache

# Create and open a Pricing stream object

stream = ld.open_pricing_stream(

    universe=['GBP=', 'EUR=', 'JPY='],

    fields=['BID', 'ASK']

)

# Extract snapshot data from the streaming cache

stream.get_snapshot()

    	
            

# Example 3 - Get a snapshot for a subset of instruments and fields

stream.get_snapshot(

    universe = ['EUR=', 'GBP='], 

    fields = ['BID', 'ASK']

)

  • Register or Log in to applaud this article
  • Let the author know how much this article helped you
If you require assistance, please contact us here