def bond_mod_duration(price, par, T, coup, freq, dy=0.01):
	ytm = bond_ytm(price, par, T, coup, freq)

	ytm_minus = ytm - dy
	price_minus = bond_price(par, T, ytm_minus, coup, freq)

	ytm_plus = ytm + dy
	price_plus = bond_price(par, T, ytm_plus, coup, freq)

	duration = (price_minus - price_plus) / (2 * price * dy)
	return duration
Example #2
0
def bond_convexity(price, par, T, coup, freq, dy=0.01):
	ytm = bond_ytm(price, par, T, coup, freq)

	ytm_minus = ytm - dy
	price_minus = bond_price(par, T, ytm_minus, coup, freq)

	ytm_plus = ytm + dy
	price_plus = bond_price(par, T, ytm_plus, coup, freq)

	convexity = (price_minus + price_plus - 2 * price) / (price * dy ** 2)

	return convexity
Example #3
0
	def test_bond_price(self):
		ytm = 0.0936915534524

		price = bond_price(100, 1.5, ytm, 5.75, 2)
		print("price=%s" % price)

		self.assertAlmostEqual(price, 95.0428, places=7)