Fetching a Government Bond Curve
Use the /gov_yield endpoint to retrieve government bond yields and construct yield curves for risk-free rate benchmarking.
Government bond yield curves show the relationship between yields and maturities for sovereign debt. They're commonly used as:
Risk-free rate benchmarks for discounting and valuation
Credit spread references (e.g., calculating swap spreads over treasuries)
Economic indicators (curve shape signals market expectations)
Example: US Treasury Curve
Fetch yields across multiple tenors to construct the full curve using the /gov_yield endpoint:
import requests
url = "https://api.bluegamma.io/v1/gov_yield"
headers = {"x-api-key": "your_api_key_here"}
tenors = ["1Y", "2Y", "3Y", "5Y", "7Y", "10Y", "20Y", "30Y"]
curve_data = []
for tenor in tenors:
params = {
"country_code": "US",
"maturity": tenor
}
response = requests.get(url, headers=headers, params=params)
data = response.json()
curve_data.append({
"tenor": tenor,
"yield": data["yield"] * 100 # Convert to percentage
})
for point in curve_data:
print(f"{point['tenor']}: {point['yield']:.2f}%")Example Output:
Understanding the Response
Each API call returns:
country_code
ISO country code (e.g., "US", "UK", "DE")
maturity
The resolved maturity date
forward_start
Start date for the yield calculation (spot by default)
valuation_time
Timestamp of the market data used
yield
The zero-coupon yield as a decimal (multiply by 100 for percentage)
Visualizing the Curve

💡 Note: The shape of the yield curve provides economic insights. An upward-sloping curve (as shown) is typical, indicating higher yields for longer maturities. An inverted curve can signal recession expectations.
Historical Government Bond Yields
Add valuation_time to fetch yields as of a specific historical date:
Forward-Starting Bond Yields
Use forward_start to get yields for bonds starting at a future date:
Available Government Bond Curves
US
US Treasury yields
USD
UK
UK Gilt yields
GBP
DE
German Bund yields
EUR
FR
French OAT yields
EUR
IT
Italian BTP yields
EUR
ES
Spanish Bonos yields
EUR
JP
Japanese Government Bond yields
JPY
CA
Canadian Government Bond yields
CAD
AU
Australian Government Bond yields
AUD
Complete Example: Building a Treasury Curve DataFrame
Output:
Key Conventions
Government bond yields in BlueGamma use the following conventions:
Compounding: Semi-annual (for US Treasuries)
Day Count: Actual/Actual ISMA
Output: Zero-coupon yields
📘 For more details on methodology, see How do you construct your govt. bond yield curves?
Last updated