sgfixedincome_pkg.mas_api_client
Classes
API client for interacting with Monetary Authority of Singapore (MAS) bonds and bills endpoints. |
Module Contents
- class sgfixedincome_pkg.mas_api_client.MAS_bondsandbills_APIClient[source]
API client for interacting with Monetary Authority of Singapore (MAS) bonds and bills endpoints.
Initialize the API client.
- Parameters:
base_url (str) – Base URL for the MAS API.
- base_url = 'https://eservices.mas.gov.sg/statistics/api/v1/bondsandbills/m/'
- fetch_data(endpoint, params=None)[source]
Fetch data from the MAS API.
- Parameters:
endpoint (str) – The API endpoints (e.g., listbondsandbills, pricesandyields_chart, savingbondsinterest, listsavingbonds)
params (dict, optional) – Query parameters for the request.
- Returns:
The JSON response from the API.
- Return type:
dict
- Raises:
requests.HTTPError – If the request fails.
- get_latest_ssb_details()[source]
Get details of the latest Singapore Savings Bond (SSB).
- Returns:
details of the latest SSB bond.
- Return type:
dict
- Raises:
Exception – If API request fails to fetch latest SSB data.
- get_latest_ssb_issue_code()[source]
Get the latest Singapore Savings Bond (SSB) issue code.
- Returns:
The issue code of the latest bond.
- Return type:
str
- get_latest_ssb_last_day_to_apply()[source]
Get the latest Singapore Savings Bond’s (SSB) last day to apply.
- Returns:
The last day to apply to the latest SSB bond.
- Return type:
str
- get_ssb_interest(issue_code)[source]
Get interest details for a specific Singapore Savings Bond (SSB) issue.
- Parameters:
issue_code (str) – The bond’s issue code.
- Returns:
Interest details for the bond.
- Return type:
dict
- Raises:
Exception – If API request fails to fetch SSB rates and returns data.
- get_ssb_coupons(issue_code)[source]
Get list of year 1 to 10 coupon rates for a specific Singapore Savings Bond (SSB) issue.
- Parameters:
issue_code (str) – The bond’s issue code.
- Returns:
List of coupon rates for each year (year 1 to 10).
- Return type:
list
- static calculate_ssb_tenure_rates(coupons)[source]
Calculate Singapore Savings Bond’s (SSB) monthly tenure rates given coupons.
- Parameters:
coupons (list) – List of coupon rates for each year (year 1 to 10).
- Returns:
DataFrame containing tenure and corresponding annual rates.
- Return type:
pd.DataFrame
- Raises:
ValueError – If the coupon list provided does not have exactly 10 elements corresponding to coupon rates for 10 years.
- get_most_recent_6m_tbill()[source]
Fetches the most recent 6-month T-bill where the auction has occured.
This function sends a request to the MAS API to retrieve the most recent T-bill (tenor of 6 months) where the auction has occured so total_bids>0.001. Otherwise, the endpoint also provides information on upcoming T-bills with auctions that have yet to occur, in which case total_bids=0.0.
- Returns:
The most recent 6-month T-bill’s record containing details such as issue code, auction date, cutoff yield etc.
- Return type:
dict
- Raises:
Exception – If API request fails to fetch latest T-bill data.
- get_6m_tbill_bid_yield()[source]
Fetch the yield of the most recent bid on the most recent 6-month T-bill from the “pricesandyields_chart” endpoint.
- Returns:
The bid yield for the most recent 6-month T-bill.
- Return type:
float
- Raises:
Exception – If API request fails to fetch the most recent bid price and yield data.
- sudden_6m_tbill_yield_change_warning(threshold=10)[source]
Check if the yield difference between the most recent bid on the most recent 6-month T-bill and its cutoff yield exceeds the threshold. If it does, issue a warning.
Since the Monetary Authority of Singapore typically issues two 6-month T-bills per month, the remaining tenor for the most recent 6-month T-bill will never fall below 5 months. Hence, it should not be too different from the cut-off yield of this T-bill, unless there have been sudden unexpected changes in the macroeconomic environment.
- Parameters:
threshold (int) – he threshold for the yield difference in basis points (default is 10).
- Returns:
This function only issues a warning if the yield difference exceeds the threshold or if we fail to sucessfully check if the yield difference exceeds the threshold.
- Return type:
None
- past_last_day_to_apply_ssb_warning()[source]
Checks if the current date (in Singapore time) is past 23:59 on the last day to apply for the latest SSB. If it is, issues a warning.
In that case, users are unable to invest into the SSB in the dataset. However, the data is nevertheless useful as a benchmark for the next SSB’s rates. Hence, we still allow it to be in the dataset. This warning is unlikely to be triggered, since details on the next SSB is often provided promptly within day(s) of the prior SSB’s last day of application.
- Returns:
The function only issues a warning if the current date is past the application deadline or if we fail to successfully check if the current date is past the application deadline.
- Return type:
None