Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

LAB - 2

Basics of Numpy
In [1]: import numpy as np

In [2]: arr = np.array([1,4,5])


print(arr)

[1 4 5]

In [31]: arr1 = np.array([[4,5,6],[1,2,3]])


print(arr1)

[[4 5 6]
[1 2 3]]

No. of elements in an array


In [15]: arr.size

3
Out[15]:

In [16]: np.size(arr)

3
Out[16]:

In [17]: len(arr)

3
Out[17]:

No. of row and columns


In [23]: np.shape(arr)

(3,)
Out[23]:

In [25]: np.shape(arr1)

(2, 3)
Out[25]:

Displaying Rows
In [27]: arr1[0]

array([4, 5, 6])
Out[27]:

In [28]: arr1[1]

array([1, 2, 3])
Out[28]:

Suming elements of an array


In [34]: arr2 = np.array([20,30])
sum(arr2)

50
Out[34]:

In [62]: arr3 = np.array([[10, 20, 30],[40, 50, 60]])

In [63]: arr3[0]+ arr3[1]

array([50, 70, 90])


Out[63]:

In [64]: # using column index


arr3[:,0] + arr3[:,1] + arr3[:,2]

array([ 60, 150])


Out[64]:

In [79]: arr_3 = np.array([10, 20, 30])


arr_4 = np.array([40, 50, 60])

In [80]: np.sum(arr_3,axis=0)

60
Out[80]:

In [52]: np.trace(arr3)

60
Out[52]:

In [56]: arr4 = np.array([[1,2,3],[2,3,4],[3,4,5]])

In [57]: np.trace(arr4)

9
Out[57]:

In [76]: a = np.array([10,15,20])
b = np.array([25,30,35])

In [73]: sum(a+b)

135
Out[73]:

In [75]: c = np.array([[10,15,20],[25,30,35]])
np.sum(c)

135
Out[75]:

In [86]: np.concatenate([a,b])

array([10, 15, 20, 25, 30, 35])


Out[86]:

In [93]: np.vstack((a,b))

array([[10, 15, 20],


Out[93]:
[25, 30, 35]])

In [95]: np.hstack((a,b))

array([10, 15, 20, 25, 30, 35])


Out[95]:

In [96]: arr6 = ([25, 36, 49])


np.sqrt(arr6)

array([5., 6., 7.])


Out[96]:

In [97]: np.square(arr6)

array([ 625, 1296, 2401])


Out[97]:

In [103… np.square(arr6)*arr6

array([ 15625, 46656, 117649])


Out[103]:

In [104… np.power(arr6,3)

array([ 15625, 46656, 117649], dtype=int32)


Out[104]:

LAB - 3
In [2]: import numpy as np
import matplotlib.pyplot as plt
import math
from array import *

In [3]: def i_nom(i, m):


i_nom = (((1+i)**(1/m))-1)*m
return i_nom
def i_eff(i_nom, m):
i_eff = (1 + i_nom/m)**m - 1
return i_eff

Question 1: In what time will a sum of Rs. 12,000 become Rs. 18,000 at 10% pa. compund interest payable half yearly?
In [6]: print("Solution")

P = 12000

A = 18000

r = i_eff(0.12, 0.5)
N= math.log(A/P)/math.log(1+r)

print("In", N, "years the sum will become 18.000 at effective rate of interest", r*100)

Solution
In 3.7698155144575485 years the sum will become 18.000 at effective rate of interest 11.355287256600445

Question 2: Find Amount of Rs.3,000 lent for 10 years at 15% p.a. compund interest quarterly
In [16]: print("Solution")

P = 3000

N = 10

r = i_eff(0.15, 4)

A = P*(1+r)**N

print("The amount will be Rs.",A, "with effective rate of interest ", r*100)

Solution
The amount will be Rs. 13081.13627687616 with effective rate of interest 15.865041503906285

Question 3: Find the nominal rare and effective rate in each of the following.
(i) Rs.40,000 invested at 16% p.a. interest payable monthly.

(ii) Rs. 1,00,000 lent at 8% p.a. interest payable annually

In [21]: print("Solution")

P = 40000

T = 100000

r1 = i_nom(0.16, 12)

r2 = i_eff(0.16, 12)

r3 = i_nom(0.08, 1)
r4 = i_eff(0.08, 1)

print("(i) Rs.40,000 invested at 16% p.a. interest payable monthly:")


print("Nominal rate is", r1*100)
print("Effective rate is", r2*100)
print("(ii) Rs.1,00,000 lent at 8% p.a. interest payable annually:")
print("Nominal rate is", r3*100)
print("Effective rate is", r4*100)

Solution
(i) Rs.40,000 invested at 16% p.a. interest payable monthly:
Nominal rate is 14.93416550365616
Effective rate is 17.227079825887692
(ii) Rs.1,00,000 lent at 8% p.a. interest payable annually:
Nominal rate is 8.000000000000007
Effective rate is 8.000000000000007

Question 4: Find the nominal and effective rates and also find the realtion between them for the following cases:
1. Rs 20,000 lent at 20% p.a. interest payable half yearly.

2. Rs 45,000 lent at 12% pa interest payable quaterly.

In [9]: print("Solution:")

P = 20000

T = 45000

r1 = i_nom(0.2, 2)
r2 = i_eff(0.2, 2)
r3 = i_nom(0.12, 4)
r4 = i_eff(0.12, 4)

print("(i) Rs.20.000 invested at 20% p.a. interest payable half yearly:")

print("Nominal rate is", r1*100)

print("Effective rate is", r2*100)

print("Relation between Nominal and Effective Rate is:",

i_nom(r2,2)*100, ",1.e. rate of interest p.a.")

print("\n(ii) Rs. 45,000 lent at 12% p.a. interest payable quaterly:")

print("Nominal rate is", r3*100)

print("Effective rate is", r4*100)

print("Relation between Nominal and Effective Rate is:", i_nom(r4,4)*100, ",i.e. rate of interest p.a.")

print("\nNominal Rate <= Effective Rate in both cases.")

Solution:
(i) Rs.20.000 invested at 20% p.a. interest payable half yearly:
Nominal rate is 19.08902300206643
Effective rate is 21.000000000000018
Relation between Nominal and Effective Rate is: 20.000000000000018 ,1.e. rate of interest p.a.

(ii) Rs. 45,000 lent at 12% p.a. interest payable quaterly:


Nominal rate is 11.49493788883209
Effective rate is 12.550881000000015
Relation between Nominal and Effective Rate is: 12.00000000000001 ,i.e. rate of interest p.a.

Nominal Rate <= Effective Rate in both cases.

Lab 4

Implement the Concept of Annuity due


In [9]: from datetime import date
today = date.today()
print("Today's date:", today)

Today's date: 2024-02-12

In [10]: import numpy as np


import math

def due(A,i,n):
D = A/i*(1+i)*((1+i)**n -1)
P = A/i*(1+i)*(1 - (1+i)**(-n))
print("Accumulated Value of the annuity due is: Rs.", D)
print("Present Value of the annuity due is: Rs.", P)
return D

def dues(d, i, n):


a = d*i/((1+i)*((1+i)**n-1))
print("Amount invested in the annuity is:", a)

def imme(A,i,n):
D = A/i*((1+i)**n -1)
P = A/i*(1 - (1+i)**(-n))
print("Accumulated Value of the annuity immediate is: Rs.", D)
print("Present Value of the annuity immediate is: Rs.", P)
return D

Q1: Find the amount of the 15 monthly payments of Rs. 2500 made at the beginning of the each period that earn interest 12% p.a. compunded monthly.

In [11]: due(2500,0.01,15)

Accumulated Value of the annuity due is: Rs. 40644.66123092466


Present Value of the annuity due is: Rs. 35009.25760583433
40644.66123092466
Out[11]:

Q2: Find the present and accumulated value of an annuity due of Rs. 500 payable at the beginning of each month for 2 years if the money is worth 8% p.a. compunded annually.

In [12]: due(500, 0.0067, 24)

Accumulated Value of the annuity due is: Rs. 13058.58057503719


Present Value of the annuity due is: Rs. 11124.854162203388
13058.58057503719
Out[12]:

Question 3: I will invest Rs. 500 per quarter for my retirement at 7.3% compounding quarterly for 32 years. I have a choice of making that payment of Rs. 500 at the beginning or the
end of the quarter (regular annuity or annuity due). In which account will I have more money and by how much? Which account will earn the most interest and by how much?

In [13]: a = imme(500, 0.073, 32)


b = due(500, 0.073, 32)
o = a - 500
e = b - 500

print(a)
print(b)
print("Ammount of Interest earned in annuity immediate is: Rs.",o)
print("Ammount of Interest earned in annuity due is: Rs.",e)

if (o<e):
print("Ammount of Interest earned in annuity due is more than in annuity immediate.")
elif(o>e):
print("Ammount of Interest earned in annuity immediate is more than in annuity due.")
else:
print("Ammount of Interest earned in annuity due and annuity immediate is same.")

Accumulated Value of the annuity immediate is: Rs. 58439.41889424181


Present Value of the annuity immediate is: Rs. 6130.76664428471
Accumulated Value of the annuity due is: Rs. 62705.49647352147
Present Value of the annuity due is: Rs. 6578.312609317493
58439.41889424181
62705.49647352147
Ammount of Interest earned in annuity immediate is: Rs. 57939.41889424181
Ammount of Interest earned in annuity due is: Rs. 62205.49647352147
Ammount of Interest earned in annuity due is more than in annuity immediate.

Q4: How much worth of an annuity due should be there to have a present value of at least Rs. 20,00,000 at 10% p.a. compunded quarterly for 46 years.

In [14]: dues(2000000, 0.01, 46)

Amount invested in the annuity is: 34114.3563192846

LAB-5
In [1]: from datetime import date
today = date.today()
print("Today's date:", today)

Today's date: 2024-02-12

Annuities
Annuity due is an annuity in which the cash flows, or payments, occur at the beginning of the period.

A
D(n) =
i
(1 + i)[(1 + i)
n
− 1] #Matured Ammount

A
P (n) =
i
(1 + i)[1 − (1 + i)
−n
] #Present Value

In [3]: import numpy as np


import math
def due(A,i,n):
D = A/i*(1+i)*((1+i)**n -1)
P = A/i*(1+i)*(1 - (1+i)**(-n))
print("Accumulated Value of the annuity due is: Rs.", D)
print("Present Value of the annuity due is: Rs.", P)
return D
def dues(d, i, n):
a = d*i/((1+i)*((1+i)**n-1))
print("Amount invested in the annuity is:", a)
def imme(A,i,n):
D = A/i*((1+i)**n -1)
P = A/i*(1 - (1+i)**(-n))
print("Accumulated Value of the annuity immediate is: Rs.", D)
print("Prresent Value of the annuity immediate is: Rs.", P)
return D

Question 1: Find the amount of the 15 monthly payments of Rs. 2500 made at the beginning of the each period that earn interest 12%
p.a. compunded monthly.
In [5]: due(2500,0.01,15)

Accumulated Value of the annuity due is: Rs. 40644.66123092466


Present Value of the annuity due is: Rs. 35009.25760583433
40644.66123092466
Out[5]:

Question 2: Find the present and accumulated value of an annuity due of Rs. 500 payable at the beginning of each month for 2 years if
the money is worth 8% p.a. compunded annually.
In [4]: due(500, 0.0067, 24)

Accumulated Value of the annuity due is: Rs. 13058.58057503719


Present Value of the annuity due is: Rs. 11124.854162203388
13058.58057503719
Out[4]:

Question 3: I will invest Rs. 500 per quarter for my retirement at 7.3% compounding mquarterly for 32 years. I have a choice of making
that payment of Rs. 500 at the beginning or the end of the quarter (regular annuity or annuity due). In which account will I have more
money and by how much? Which account will earn the most interest and by how much?
In [7]: a = imme(500, 0.073, 32)
b = due(500, 0.073, 32)
o = a - 500
e = b - 500
print(a)
print(b)
print("Ammount of Interest earned in annuity immediate is: Rs.",o)
print("Ammount of Interest earned in annuity due is: Rs.",e)
if (o<e):
print("Ammount of Interest earned in annuity due is more than in annuity immediate.")
elif(o>e):
print("Ammount of Interest earned in annuity immediate is more than in annuity due.")
else:
print("Ammount of Interest earned in annuity due and annuity immediate is same.")

Accumulated Value of the annuity immediate is: Rs. 58439.41889424181


Prresent Value of the annuity immediate is: Rs. 6130.76664428471
Accumulated Value of the annuity due is: Rs. 62705.49647352147
Present Value of the annuity due is: Rs. 6578.312609317493
58439.41889424181
62705.49647352147
Ammount of Interest earned in annuity immediate is: Rs. 57939.41889424181
Ammount of Interest earned in annuity due is: Rs. 62205.49647352147
Ammount of Interest earned in annuity due is more than in annuity immediate.

Question 4: How much worth of an annuity due should be there to have a present value of at least Rs. 20,00,000 at 10% p.a.
compunded quarterly for 46 years.
In [8]: dues(2000000, 0.01, 46)

Amount invested in the annuity is: 34114.3563192846

LAB-6

Deferred Annuity
Deffered Annuity is an ordinary annuity in which the 3rst payment is post poned until the expiry of certain time payment. If the 3rst payment in an ordinary annuity is made at the end of (k+1) period
abd thereafter the paymements are made regularly for n periods, then it is called a deffered annuity

In [2]: from ast import increment_lineno


import numpy as np
import math
def deffered(A,i,n,k):
V = A/i*((1+i)**n - 1)
P = A/i * (1+i)**(-k)*(1-(1+i)**(-n))
print("Accumulated Value of deffered annuity is: Rs.",V)
print("Present Value of deffered annuitu is: Rs.",P)

Question 1:
A man paid his advance payment for house construction in equal installments of ₹25000 semiannually in 10 years. If the money was worth 8% p.a. compunded semi annually and payments started
after 5 years. Find the accumulated value and present value of annuity.

In [3]: deffered(25000,0.04,20,10)

Accumulated Value of deffered annuity is: Rs. 744451.964395888


Present Value of deffered annuitu is: Rs. 229528.43803273636

Question 2:
An annuity consists of 30 semi-annual payments of Rs. 500. the 3rst being payable at the end of 4.5 years. Find the accumulated ammount and present value of annuity if the money is worth 12%
p.a. compounded semi annually.

In [5]: deffered(500,0.06,22,8)

Accumulated Value of deffered annuity is: Rs. 21696.145138152973


Present Value of deffered annuitu is: Rs. 3777.5186702599353

Question 3:
A land is sold for ₹ 1,50,000 down payments and 120 monthly installments of ₹ 5,000 each. If 3rst due is three years hence, 3nd the cash value of the house if money worth is 18% p.a. compunded
monthly. Also, find the accumulated value of the land.

In [7]: deffered(5000,0.015,85,35)

Accumulated Value of deffered annuity is: Rs. 848326.127533899


Present Value of deffered annuitu is: Rs. 142114.29766471978

Question 4:
An annuity consists of 4 annual payments ₹ 1,500 each. First payment being made at the end of sixth year. Find the accumulated and present value of the annuity if the worth is 10% effective rate.

In [15]: deffered(1500,0.1,9,5)

Accumulated Value of deffered annuity is: Rs. 20369.21536500003


Present Value of deffered annuitu is: Rs. 5363.851031296128

Conclusion:We conclude that we can find the amount due and present matured amount using the concept deffered annuity.

LAB - 7
Perpetual Annuity
Aim: To implement the concept of perpetual annuity in Python

Perpetuity: Perpetuity is an annuity whose payments continue forever. Let P ve the discounted value of an ordinary simple perpetuity (OSP) which is an infinte series of equal payments made at the
end of interest periods.

P = A/i

In [9]: import numpy as np


import math
def per(A,i):
P = A/i
print("Present value of this perpetuity: ",P)

Question 1: How much money is needed to establish a scholorship fund paying ₹10,000 annually if the fund will earn a rate of interest of 12% p.a. and if the first payment will be made at the end of
first period?

In [10]: per(10000,0.12)

Present value of this perpetuity: 83333.33333333334

Question 2:
A certain stock is expected to pay divident of ₹ 75,000 at the end of each quater for an indefinite period in the future. If an investor wishes to realise an effective yield of 10% p.a., how much should
he pay for the stock?

In [11]: i = ((10 + 1)**(1/4) - 1)*4


per(75000,i)

Present value of this perpetuity: 22833.544559494705

Question 3:
A scholorship fund is established by a recognised body of ₹ 2,00,00,000 invested at 10% p.a. compund interest. What payment will this fund provide at the end of every two years?

In [12]: A = 20000000 * 0.2


print("Amount to be paid at the end of every 2 years for the scholorship fund: ",A)

Amount to be paid at the end of every 2 years for the scholorship fund: 4000000.0

Question 4:
A certain stock is expected to pay a dovident of ₹10,000 at the end of each quater for an indefinite period in the future. If an investor wishes an annual effective yeild of 12% p.a., how much should
be paid in the stock?

In [14]: i = ((0.12 + 1)**(1/4) - 1)*4


per(10000,i/4)

Present value of this perpetuity: 347979.26171364536

Conclusion:We conclude that we can find present value of a perpetuity which is the discounted value of an ordinary simple perpetuity (OSP) using python.

LAB - 8
Implement the Concept of Outstanding Loan Balance
In [17]: from sympy import *
from numpy import *
L = Symbol('L')
OLB_k = Symbol('OLB_k')
k = Symbol('k')
i = Symbol('i')
Q = Symbol('Q')
s_ki = Symbol('s_ki')
v = Symbol('v')
a_k = Symbol('a_k')
K = Eq(OLB_k, L*a_k - Q*s_ki)
pprint(K)

OLBₖ = L⋅aₖ - Q⋅sₖᵢ

In [18]: from sympy import *


from numpy import *
L = Symbol('L')
k = Symbol('k')
i = Symbol('i')
Q = Symbol('Q')
def OLB(L,k,Q,i):
v = (1+i)**(-k)
a_k = (1+i)**k
s_ki = ((1 +i)**k - 1)/i
a_ki = (1 - (1+i)**(-k))/i
OLB_k = L*a_k - Q*s_ki
print("v =",v)
print("a_k =",a_k)
print("a_ki =",a_ki)
print("s_ki =",s_ki)
print("OLB_k",OLB_k)

In [19]: OLB(450000,372,5109.03,0.01125)

v = 0.015582068931547323
a_k = 64.17633013902336
a_ki = 87.50381609497357
s_ki = 5615.67379013541
OLB_k 188702.69854500145

You might also like