You are on page 1of 2

Function EMI(Principal As Double, intRate As Double, pmtDate As Variant, endDate

As Variant, pmtType As Integer)


'define variables
Dim m As Variant
Dim r As Double
Dim num As Double
Dim denom As Double
Dim frac As Double
'setting up the formula
m = DateDiff("m", pmtDate, endDate)
r = 1 + (intRate / 12)
num = 1 - ((1 / r) ^ m)
denom = intRate / 12
Select Case pmtType
Case 0:
frac = (num / denom)
Case 1:
frac = (num / denom) * r
End Select
EMI = Principal / frac
End Function
Function AEMI(Principal As Double, intRate As Double, gradDate As Variant, pmtDa
te As Variant, endDate As Variant, pmtType As Integer)
Dim m As Variant
Dim tm As Double
Dim acc As Double
Dim r As Double
Dim num As Double
Dim denom As Double
Dim frac As Double
'adjusting formula for months interest accrued, if payment doesn't start immedia
tely after the moratorium period
m = DateDiff("m", gradDate, pmtDate) - 6
If m < 0 Then Exit Function
If m = 0 Then acc = Principal
If m > 0 Then acc = Principal + (Principal * intRate / 12) * m
tm = DateDiff("m", pmtDate, endDate)
r = 1 + (intRate / 12)
num = 1 - ((1 / r) ^ tm)
denom = intRate / 12
Select Case pmtType
Case 0:
frac = (num / denom)
Case 1:
frac = (num / denom) * r
End Select
AEMI = acc / frac
End Function
Function AEMI2(Principal As Double, intRate As Double, strDate As Variant, gradD
ate As Variant, pmtDate As Variant, endDate As Variant, pmtType As Integer)
Dim m As Variant
Dim ma As Variant
Dim tm As Double
Dim acc As Double
Dim r As Double
Dim num As Double
Dim denom As Double
Dim frac As Double
'adjusting formula for months interest accrued from first day of loan, and also
if payment doesn't start immediately after the moratorium period
m = DateDiff("m", strDate, gradDate) + 6
ma = DateDiff("m", gradDate, pmtDate) - 6
If ma < 0 Then Exit Function
If ma = 0 Then acc = Principal + (Principal * intRate / 12) * m
If ma > 0 Then acc = Principal + (Principal * intRate / 12) * (m + ma)
tm = DateDiff("m", pmtDate, endDate)
r = 1 + (intRate / 12)
num = 1 - ((1 / r) ^ tm)
denom = intRate / 12
Select Case pmtType
Case 0:
frac = (num / denom)
Case 1:
frac = (num / denom) * r
End Select
AEMI2 = acc / frac
End Function

You might also like