Yield to Maturity
Calculates the yield to maturity for a bond. The yield to maturity is the internal rate of return of the bond, which is the discount rate that equates the present value of the bond’s cash flows to its market price. The yield to maturity is used to estimate the bond’s return and to compare the bond’s return to other investments.
The yield to maturity is calculated using the following formula:
\[\text{Bond Price} = (C / r) \cdot (1 - (1 + r) ^{-n}) + F / (1 + r) ^{n}\]where:
- C = Coupon payment per period
- r = Yield to maturity per period
- n = Number of periods
- F = Face value of the bond
The goal is to find the yield to maturity that satisfies the equation above. This is done using the secant method which is an iterative method that converges to the root of a function.
Also known as: YTM, bond return to maturity.
No programming experience? With the Finance Toolkit MCP server, AI assistants such as Claude and ChatGPT can calculate the Yield to Maturity for you. Just ask in plain English.
Calculate the Yield to Maturity in Python
The Yield to Maturity is available in the Fixed Income module of the open-source Finance Toolkit. Install it with:
pip install financetoolkit -U
Then call get_yield_to_maturity as shown below.
from financetoolkit import FixedIncome
fixedincome = FixedIncome()
fixedincome.get_yield_to_maturity(
coupon_rate=0.05,
years_to_maturity=[5, 10, 15],
bond_price=[95, 100, 105],
show_input_info=False,
)
Which returns:
| Bond Price | 5 | 10 | 15 |
|---|---|---|---|
| 95 | 0.0619 | 0.0567 | 0.055 |
| 100 | 0.05 | 0.05 | 0.05 |
| 105 | 0.0388 | 0.0437 | 0.0453 |
Parameters
get_yield_to_maturity accepts the following parameters:
- par_value (float): The par value (face value) of the bond. This is the original price when it was issued by the issuer.
- coupon_rate (float, optional): The coupon rate of the bond. Defaults to 0.05.
- years_to_maturity (float, optional): The years to maturity of the bond in years. Defaults to None.
- bond_price (float, optional): The price of the bond. Defaults to None.
- frequency (int, optional): The number of coupon payments per year. Defaults to 1.
- guess (float, optional): The initial guess for the yield to maturity. Defaults to 0.05.
- tolerance (float, optional): The tolerance level for convergence. Defaults to 0.0001.
- max_iterations (int, optional): The maximum number of iterations for convergence. Defaults to 100.
- show_input_info (bool, optional): Whether to display input information. Defaults to True.
Related Bond Valuations
The Fixed Income module page introduces the module, and the sidebar lists all of its functions.