Develop a program to find
EMI (Equated Monthly Installment) and the amortization schedule for loan
repayment. Three primary inputs for doing loan arithmetic are Loan Amount, Rate
of interest and Tenure. Rate of interest can vary over certain months and affect
the tenure. Write a program to calculate EMI, total interest paid over entire
tenure of the loan and amortization schedule. Amortization schedule is
explained in text below.
This problem will take into account frequency of payment viz. MONTHLY/YEARLY/ DAILY. The
EMI is payable at this frequency. The interest rate variation is captured in
form of From Installment number to To Installment number. The interest rate may
vary or may remain constant over the tenure of the loan repayment schedule.
Program should accept name of the file as input on console. The file will
contain inputs such as loan amount, rate etc. See details in input
specification section below. In case of a bad input, program should notify user
with invalid input.
Information:
·
EMI
are the payments one makes in order to pay off the loan. On a specific date
every month,one needs to pay the EMI. EMI depends upon loan amount, interest
rate, loan tenure and the frequency in which one wants to pay EMI i.e can be
monthly/quarterly/yearly etc
·
Round
off the interest paid to the nearest rupee.
·
EMI
can be calculated using the formula:
EMI = (L*I)* {((1+I)^N) /
([(1+I)^N]-1)}
where
L = loan amount
I = interest Rate(rate per annum divided by 12)
^ = to the power of
N = Loan Period in months
Example
Mr. Gonsalves borrowed Rs
57,00,000 Lakhs (Rs 5.7 million) at 10% per annum for a tenure of 20 years with
EMI payable monthly. According to his loan plan after 100 months for next 50
months, the rate of interest changes to 10.5.
So here, Loan amount=Rs
57,00,000 Lakhs (Rs 5.7 million)
Rate of interest= 10
Tenure=240(20*12)
Frequency=MONTHLY
From Installment:100
To Installment:150
Rate of interest= 10.5
EMI calculated, using
formula mentioned above is 55006.23376921851. Rounded off to two digits after
decimal point, EMI becomes Rs 55006.23. Amortization schedule for this loan
case looks similar to the table shown below :
Amortization Schedule:
|
InstNo. |
Opening
Principal |
Installment
Amount |
Principal
Component |
Interest
Component |
Closing
Principal |
Rate
Of Interest |
|
1 |
5700000 |
55006.23 |
7506.23 |
47500 |
5692493.77 |
10 |
|
2 |
5692493.77 |
55006.23 |
7568.79 |
47437.45 |
5684924.98 |
10 |
|
3 |
5684924.98 |
55006.23 |
7631.86 |
47374.37 |
5677293.12 |
10 |
|
4 |
... |
... |
... |
... |
... |
|
|
5 |
||||||
|
99 |
4569291.63 |
55006.23 |
16928.8 |
38077.43 |
4552362.83 |
10 |
|
100 |
4552362.83 |
55006.23 |
15173.06 |
39833.17 |
4537189.77 |
10.5 |
|
101 |
4537189.77 |
55006.23 |
15305.82 |
39700.41 |
4521883.95 |
10.5 |
|
245 |
||||||
|
246 |
10.5 |
|||||
|
247 |
54551.64 |
55006.23 |
54551.64 |
454.6 |
0 |
10.5 |
Total interest paid on
57,00,000 at rate 10.50 is 78,77,467.47 in 247 installments.
While printing the output report interest paid rounded off to the nearest
multiple of hundered (100). In this case it will be 78,77,500 .Refer
section on Output Format for precise instructions.
Note, two things from the
table and the sentence above
1.
Since
the rate of change of interest is marked from 100th month to
150th month, but no additional information is provided about
the rate from 151st month till the end of the tenure. Hence
rate of interest in this case will remain as 10.5 until any explicit rate
change, to take place later is provided. In this case, since no information is
provided, rate will remain 10.5% until end of tenure.
2.
At
the start of the problem, it was stated that the tenure is 240 months. But due
to increase in rate of interest and no change in EMI, the tenure increased to
247 months. You are assured that rate of interest will never change in such a
way that with the current EMI amount the loan can never be repaid. Such test
cases are out of scope for this problem.
Input Format
|
Line 1 |
Name of the file from which inputs are to be taken. The input file format
is described next. |
|
Line 2 |
A particular installment number whose opening principle is to be calculated
using amortization schedule. |
Note:
The Input in file column in table below on Sample Test Cases
is provided to help you visualize how the input file will look like.
File Format
|
Line 1 |
Loan Amount (L) |
|
Line 2 |
Rate of Interest per annum (R) in percentage |
|
Line 3 |
Tenure (N) |
|
Line 4 |
Frequency of payment Frequency can be
MONTHLY/YEARLY/DAILY for MONTHLY Rate of
Interest =Rate of Interest per annum (R) /12 DAILY Rate of
Interest=Rate of Interest per annum (R)/365 |
|
If there is a change of rate of interest then following lines will be a
part of the input |
|
|
Line 5 |
From installment |
|
Line 6 |
To installment |
|
Line 7 |
Changed Rate of Interest |
Constraints
1.
Here:
0 <= L <= 10,000,000,000
0 <= R <= 100
1 <= N <= 1188
2.
In
case of change of rate of interest, the To installment value should be greater
than From installment value
Output Format
|
Line 1 |
For valid input,print EMI amount rounded to 2
digits after decimal point For Invalid input,print Invalid Input |
|
Line 2 |
For valid input,print Opening Principal
before installment X is Rs Y where X is the input
provided in Line 2 (installment number) and Y is Prinicipal
outstanding in Rs rounded to nearest multiple of hundered (100) For Invalid input,print Please
Mention Frequency Of EMI As MONTHLY/YEARLY/DAILY |
|
Line 3 |
Interest paid is Rs Z where Z = interest paid over entire tenure rounded to nearest multiple of
hundered (100) |
Sample Input and Output
|
SR.no |
Input |
Input
in File |
Output |
|
1 |
EMIinput.txt
|
15000 |
EMI
is Rs 149.76 |
|
2 |
EMIinput.txt
|
1000 |
Invalid
Input |
|
3 |
EMIinput.txt |
5 |
Invalid
Input |
|
4 |
EMIinput.txt |
1200000 |
EMI
is Rs 30423.11 |


0 Comments