|
|
@@ -0,0 +1,192 @@
|
|
|
+{
|
|
|
+ "cells": [
|
|
|
+ {
|
|
|
+ "cell_type": "code",
|
|
|
+ "execution_count": 6,
|
|
|
+ "id": "9a5b00b8-2d18-4540-80ff-cf985f653dce",
|
|
|
+ "metadata": {},
|
|
|
+ "outputs": [
|
|
|
+ {
|
|
|
+ "name": "stdout",
|
|
|
+ "output_type": "stream",
|
|
|
+ "text": [
|
|
|
+ "100 30 0.5 3 5 False\n"
|
|
|
+ ]
|
|
|
+ }
|
|
|
+ ],
|
|
|
+ "source": [
|
|
|
+ "class Bond:\n",
|
|
|
+ " def __init__(\n",
|
|
|
+ " self,\n",
|
|
|
+ " par,\n",
|
|
|
+ " term,\n",
|
|
|
+ " couponInt,\n",
|
|
|
+ " paymentFreq,\n",
|
|
|
+ " intRate,\n",
|
|
|
+ " amortizing=False):\n",
|
|
|
+ " self.par=par\n",
|
|
|
+ " self.term=term\n",
|
|
|
+ " self.couponInt=couponInt\n",
|
|
|
+ " self.paymentFreq=paymentFreq\n",
|
|
|
+ " self.intRate=intRate\n",
|
|
|
+ " self.amortizing=amortizing\n",
|
|
|
+ " \n",
|
|
|
+ " def calculate(self):\n",
|
|
|
+ " if self.amortizing==True:\n",
|
|
|
+ " self.par*self.couponInt\n",
|
|
|
+ " \n",
|
|
|
+ " print(self.par,self.term,self.couponInt,self.paymentFreq,self.intRate,self.amortizing)\n",
|
|
|
+ "\n",
|
|
|
+ "Ex1=Bond(100, 30,0.5, 3,5, False)\n",
|
|
|
+ "Ex1.calculate()"
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "cell_type": "code",
|
|
|
+ "execution_count": 1,
|
|
|
+ "id": "7d04967a-d8b9-46f1-8bd4-60b38370a956",
|
|
|
+ "metadata": {},
|
|
|
+ "outputs": [],
|
|
|
+ "source": [
|
|
|
+ "#Price = ( Coupon × 1 − ( 1 + r ) − n r ) + Par Value ( 1 + r ) n"
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "cell_type": "code",
|
|
|
+ "execution_count": 1,
|
|
|
+ "id": "365a82d5-7799-4ef0-9735-8f6eb0da9e67",
|
|
|
+ "metadata": {},
|
|
|
+ "outputs": [],
|
|
|
+ "source": [
|
|
|
+ "#Bond Premium Amortized= P x R – N x Y\n",
|
|
|
+ "#P = Bond issue price, R = Market Rate of interest, N = Nominal or face value and, Y = coupon rate of interest/ Yield."
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "cell_type": "code",
|
|
|
+ "execution_count": 10,
|
|
|
+ "id": "f0143155-7445-417a-ac26-4a7bab893295",
|
|
|
+ "metadata": {},
|
|
|
+ "outputs": [
|
|
|
+ {
|
|
|
+ "data": {
|
|
|
+ "text/plain": [
|
|
|
+ "1375.7049230300258"
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ "execution_count": 10,
|
|
|
+ "metadata": {},
|
|
|
+ "output_type": "execute_result"
|
|
|
+ }
|
|
|
+ ],
|
|
|
+ "source": [
|
|
|
+ "class Bond:\n",
|
|
|
+ " def __init__(\n",
|
|
|
+ " self,\n",
|
|
|
+ " par,\n",
|
|
|
+ " term,\n",
|
|
|
+ " couponInt,\n",
|
|
|
+ " paymentFreq,\n",
|
|
|
+ " intRate,\n",
|
|
|
+ " amortizing=False):\n",
|
|
|
+ " self.par=par\n",
|
|
|
+ " self.term=term\n",
|
|
|
+ " self.couponInt=couponInt\n",
|
|
|
+ " self.paymentFreq=paymentFreq\n",
|
|
|
+ " self.intRate=intRate\n",
|
|
|
+ " self.amortizing=amortizing\n",
|
|
|
+ " \n",
|
|
|
+ " def calculate(self):\n",
|
|
|
+ " if self.amortizing==False:\n",
|
|
|
+ " price=(((self.par*self.couponInt)*(1-(1+self.intRate)**-self.paymentFreq)/self.intRate)+(self.par/(1+self.intRate)**self.term))\n",
|
|
|
+ " return(price)\n",
|
|
|
+ " else:\n",
|
|
|
+ " 1==1\n",
|
|
|
+ " \n",
|
|
|
+ "\n",
|
|
|
+ "Ex1 = Bond(1000, 4, .25, 4, .125, False)\n",
|
|
|
+ "Ex1.calculate()\n",
|
|
|
+ "\n"
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "cell_type": "raw",
|
|
|
+ "id": "ca78ef5f-b510-4046-9e25-b25774acc50f",
|
|
|
+ "metadata": {},
|
|
|
+ "source": [
|
|
|
+ "non-amortizing\n",
|
|
|
+ "month balance principal interest\n",
|
|
|
+ "0 100 0 5\n",
|
|
|
+ "1 100 0 5\n",
|
|
|
+ "2\n",
|
|
|
+ "3\n",
|
|
|
+ "...\n",
|
|
|
+ "119 100 0 5\n",
|
|
|
+ "120 0 100 5\n",
|
|
|
+ "\n",
|
|
|
+ "\n",
|
|
|
+ "Amortizing bond:\n",
|
|
|
+ "r = 6%\n",
|
|
|
+ "month balance principal interest\n",
|
|
|
+ "0 100 0. 0\n",
|
|
|
+ "1 99.9 .1 0.5\n",
|
|
|
+ "2 99.799 .101 0.499\n",
|
|
|
+ "...\n",
|
|
|
+ "119 1 1 0.051\n",
|
|
|
+ "120 0 1 0.05\n",
|
|
|
+ "\n",
|
|
|
+ "condition: \n",
|
|
|
+ "r = a given number (yearly interest rate) \n",
|
|
|
+ "interest = previuos balance * r / 12\n",
|
|
|
+ "principal + intersst = constant for the life of the bond\n",
|
|
|
+ "balance at the final month = 0\n",
|
|
|
+ "\n",
|
|
|
+ "create a function:\n",
|
|
|
+ "f( first principal) -> last balance\n",
|
|
|
+ "\n",
|
|
|
+ "def lastBalance( fp):\n",
|
|
|
+ " ....\n",
|
|
|
+ " ....\n",
|
|
|
+ " ....\n",
|
|
|
+ " \n",
|
|
|
+ "lastBalance(0.1) \n",
|
|
|
+ "2\n",
|
|
|
+ "\n",
|
|
|
+ "lastBalance(1) \n",
|
|
|
+ "-20\n",
|
|
|
+ "\n",
|
|
|
+ "\n",
|
|
|
+ "\n"
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "cell_type": "code",
|
|
|
+ "execution_count": null,
|
|
|
+ "id": "b1adb876-0acb-439f-a32c-5b20d87c0e02",
|
|
|
+ "metadata": {},
|
|
|
+ "outputs": [],
|
|
|
+ "source": []
|
|
|
+ }
|
|
|
+ ],
|
|
|
+ "metadata": {
|
|
|
+ "kernelspec": {
|
|
|
+ "display_name": "Python 3 (ipykernel)",
|
|
|
+ "language": "python",
|
|
|
+ "name": "python3"
|
|
|
+ },
|
|
|
+ "language_info": {
|
|
|
+ "codemirror_mode": {
|
|
|
+ "name": "ipython",
|
|
|
+ "version": 3
|
|
|
+ },
|
|
|
+ "file_extension": ".py",
|
|
|
+ "mimetype": "text/x-python",
|
|
|
+ "name": "python",
|
|
|
+ "nbconvert_exporter": "python",
|
|
|
+ "pygments_lexer": "ipython3",
|
|
|
+ "version": "3.10.7"
|
|
|
+ }
|
|
|
+ },
|
|
|
+ "nbformat": 4,
|
|
|
+ "nbformat_minor": 5
|
|
|
+}
|