# [Step 1] Set up the environment
import refinitiv.dataplatform as rdp
import datetime
import pandas as pd
rdp.open_desktop_session('DEFAULT_CODE_BOOK_APP_KEY')
# [Step 2] Using RDP Search API to retrieve the data
df = rdp.search(
view = rdp.SearchViews.GovCorpInstruments,
top = 10000,
filter = "((DbType eq 'GOVT' or DbType eq 'CORP' or DbType eq 'AGNC' or DbType eq 'OMUN' or DbType eq 'OTHR') and IsActive eq true and (RCSParentDomicileGenealogy in ('G:53' 'G:3H') and RCSCurrencyLeaf eq 'US Dollar' and RCSCountryGenealogy ne 'M:DQ\G:B6'))",
select = "RIC,RCSTRBC2012Leaf,IssueDate,EOMAmountOutstanding,PricingRedemDate,IssuerLegalName,PricingClosingYield, CurrentYield, FaceIssuedTotal,EOMPriceChange,RCSBondGradeLeaf,EOMPriceReturn"
)
display(df)
# [Step 3] Visualize the Kungfu bonds
# 3.1 ) TRBC Pie
import plotly.express as px
rt = df.groupby("RCSTRBC2012Leaf",as_index=False).agg('count')
rt = rt.sort_values('RIC', ascending = False).head(10)
fig = px.pie(rt, values='RIC', names='RCSTRBC2012Leaf', title='TRBC Pie',color_discrete_sequence=px.colors.sequential.RdBu)
fig.show()