-1
$\begingroup$

Anyone knows a way of getting trustworthy bonds data in python? I know that for stock there is yfinance package but it doesnt include bonds.

Thx

$\endgroup$
2
  • 1
    $\begingroup$ It's still mostly OTC and making data available for bonds was the reason Bloomberg turned into what it is today. So finding a trustworthy source for free is probably not possible. Generally, yfinance isn't particularly trustworthy either, and full of errors. $\endgroup$
    – AKdemy
    Commented May 10 at 4:29
  • $\begingroup$ What data - market data price/yield & volume? Indicative - oupon&maturity? $\endgroup$ Commented May 11 at 17:14

2 Answers 2

1
$\begingroup$

For US treasuries, treasurydirect.gov provides a rest API: https://www.treasurydirect.gov/legal-information/developers/web-api-security/

For corporates and everything else, you need either Bloomberg or Reuters / Refinitiv / LSEG. Bloomberg used to be kind enough to provide a free API in FIGI https://bsym.bloomberg.com/api that allowed you to get some indicative data for a limited number of bonds at a time. It may have been retired.

$\endgroup$
0
$\begingroup$

If you are interested in just yields, you can use FRED and Pandas Datareader.

# Import the libraries

import numpy as np
import pandas as pd
import pandas_datareader as pdr
import datetime

# Time range

start = datetime.date(2000, 1, 1)
end = datetime.date.today()

# Import the data

yields = ['DGS3MO', 'DGS1', 'DGS10']
df_yields = pdr.DataReader(yields, 'fred', start, end)
$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.