{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"name": "bond_pricing2.ipynb",
"provenance": [],
"collapsed_sections": [],
"authorship_tag": "ABX9TyPIvQI3UOX77ZiSaAgsAexX",
"include_colab_link": true
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
}
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
""
]
},
{
"cell_type": "markdown",
"source": [
"# Bond Pricing\n",
"$$price \\ of \\ a \\ coupon \\ bond = \\Sigma \\frac{Coupon}{(1+YTM)^t} + \\frac{Par \\ Value}{(1 + YTM)^t} \n",
"$$"
],
"metadata": {
"id": "U7ic90H8WFEA"
}
},
{
"cell_type": "code",
"source": [
"def bondprice(ytm, period, par, coupon):\n",
" price_bond = par*coupon/2*(1-(1+ytm/2)**(-2*period))/(ytm/2) + par/(1+ytm/2)**(2*period)\n",
" return price_bond"
],
"metadata": {
"id": "12VmbHwzJe-H"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"# create a list of YTMs from 0.01 to 0.50\n",
"ytm_list = [x/100 for x in range(1, 51)]\n",
"\n",
"print(ytm_list)"
],
"metadata": {
"id": "Qouu1luRiN6h",
"outputId": "397c1aaa-8bf9-4318-fdee-82eb912cfb5e",
"colab": {
"base_uri": "https://localhost:8080/"
}
},
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"[0.01, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07, 0.08, 0.09, 0.1, 0.11, 0.12, 0.13, 0.14, 0.15, 0.16, 0.17, 0.18, 0.19, 0.2, 0.21, 0.22, 0.23, 0.24, 0.25, 0.26, 0.27, 0.28, 0.29, 0.3, 0.31, 0.32, 0.33, 0.34, 0.35, 0.36, 0.37, 0.38, 0.39, 0.4, 0.41, 0.42, 0.43, 0.44, 0.45, 0.46, 0.47, 0.48, 0.49, 0.5]\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"# create a list of bond prices\n",
"output = []\n",
"for element in ytm_list:\n",
" output.append(bondprice(ytm=element, period=50, par=1000, coupon=0.10))\n",
"\n",
"print(output)"
],
"metadata": {
"id": "k-ffCLqpiN1_",
"outputId": "280f6129-b470-4f41-ee35-2d034ec8f66e",
"colab": {
"base_uri": "https://localhost:8080/"
}
},
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"[4534.419014459948, 3521.155150683525, 2806.8646283949465, 2292.9505492033823, 1915.3526316119737, 1631.9781067665274, 1414.831381030019, 1245.0499899715198, 1109.7492637116093, 1000.0, 909.5208030589646, 833.82453770479, 769.655601135766, 714.6149858198504, 666.907675144676, 625.170473045163, 588.3532379676428, 555.6359391991529, 526.3699991720615, 500.0362828579507, 476.2146277727387, 454.56146710237505, 434.7931946198022, 416.6736508322453, 400.0046014955424, 384.61841363639905, 370.3723633323073, 357.14416822330287, 344.82844880189464, 333.3339010409298, 322.5810189784025, 312.5002463053128, 303.03046544351673, 294.11775424681923, 285.7143565227709, 277.7778246019509, 270.27030126779437, 263.1579152805246, 256.4102700417318, 250.00000905600507, 243.90244504822635, 238.09524210726335, 232.5581422104622, 227.27272905939245, 222.22222341688865, 217.39130514772208, 212.76595798310893, 208.3333336933925, 204.081632895127, 200.00000016296286]\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"from matplotlib import pyplot as plt\n",
"plt.plot(ytm_list, output)\n",
"plt.show()"
],
"metadata": {
"id": "OphzxslYiNzZ",
"outputId": "18061a60-0ede-4592-f404-6cd766c9cb11",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 265
}
},
"execution_count": null,
"outputs": [
{
"output_type": "display_data",
"data": {
"text/plain": [
"