qfinbox.tvm.bonds

Bond valuation and analysis.

Functions

bond_convexity(face_value, coupon_rate, ...)

Calculate convexity of a bond.

bond_duration(face_value, coupon_rate, ...)

Calculate Macaulay duration of a bond.

bond_modified_duration(face_value, ...[, ...])

Calculate modified duration of a bond.

bond_price(face_value, coupon_rate, ...[, ...])

Calculate bond price given yield to maturity.

bond_yield_to_maturity(price, face_value, ...)

Calculate bond yield to maturity given price.

brentq(f, a, b[, args, xtol, rtol, maxiter, ...])

Find a root of a function in a bracketing interval using Brent's method.

validate_positive(value[, name])

Validate that a value is positive.

qfinbox.tvm.bonds.bond_price(face_value: float, coupon_rate: float, years_to_maturity: float, yield_to_maturity: float, payments_per_year: int = 2) float[source]

Calculate bond price given yield to maturity.

Parameters:
  • face_value (float) – Face value of the bond.

  • coupon_rate (float) – Annual coupon rate (as decimal).

  • years_to_maturity (float) – Years until maturity.

  • yield_to_maturity (float) – Yield to maturity (as decimal).

  • payments_per_year (int, default 2) – Number of coupon payments per year.

Returns:

Bond price.

Return type:

float

Examples

>>> bond_price(1000, 0.06, 10, 0.08)
864.10
qfinbox.tvm.bonds.bond_yield_to_maturity(price: float, face_value: float, coupon_rate: float, years_to_maturity: float, payments_per_year: int = 2) float[source]

Calculate bond yield to maturity given price.

Parameters:
  • price (float) – Current bond price.

  • face_value (float) – Face value of the bond.

  • coupon_rate (float) – Annual coupon rate (as decimal).

  • years_to_maturity (float) – Years until maturity.

  • payments_per_year (int, default 2) – Number of coupon payments per year.

Returns:

Yield to maturity (as decimal).

Return type:

float

Examples

>>> bond_yield_to_maturity(864.10, 1000, 0.06, 10)
0.08
qfinbox.tvm.bonds.bond_duration(face_value: float, coupon_rate: float, years_to_maturity: float, yield_to_maturity: float, payments_per_year: int = 2) float[source]

Calculate Macaulay duration of a bond.

Parameters:
  • face_value (float) – Face value of the bond.

  • coupon_rate (float) – Annual coupon rate (as decimal).

  • years_to_maturity (float) – Years until maturity.

  • yield_to_maturity (float) – Yield to maturity (as decimal).

  • payments_per_year (int, default 2) – Number of coupon payments per year.

Returns:

Macaulay duration in years.

Return type:

float

Examples

>>> bond_duration(1000, 0.06, 10, 0.08)
7.25
qfinbox.tvm.bonds.bond_modified_duration(face_value: float, coupon_rate: float, years_to_maturity: float, yield_to_maturity: float, payments_per_year: int = 2) float[source]

Calculate modified duration of a bond.

Parameters:
  • face_value (float) – Face value of the bond.

  • coupon_rate (float) – Annual coupon rate (as decimal).

  • years_to_maturity (float) – Years until maturity.

  • yield_to_maturity (float) – Yield to maturity (as decimal).

  • payments_per_year (int, default 2) – Number of coupon payments per year.

Returns:

Modified duration.

Return type:

float

Examples

>>> bond_modified_duration(1000, 0.06, 10, 0.08)
6.71
qfinbox.tvm.bonds.bond_convexity(face_value: float, coupon_rate: float, years_to_maturity: float, yield_to_maturity: float, payments_per_year: int = 2) float[source]

Calculate convexity of a bond.

Parameters:
  • face_value (float) – Face value of the bond.

  • coupon_rate (float) – Annual coupon rate (as decimal).

  • years_to_maturity (float) – Years until maturity.

  • yield_to_maturity (float) – Yield to maturity (as decimal).

  • payments_per_year (int, default 2) – Number of coupon payments per year.

Returns:

Convexity.

Return type:

float

Examples

>>> bond_convexity(1000, 0.06, 10, 0.08)
64.93