-
Notifications
You must be signed in to change notification settings - Fork 0
/
calculators.vb
44 lines (37 loc) · 1.29 KB
/
calculators.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
OPTION EXPLICIT
' A Set of Simple Functions to Quickly Calculate Values
'
' The script file is designed to provide utility functions for
' quick calculations that is not limited to fixed deposit, recurring
' deposit, calculators but much more. Most of the functions are
' derived using simple mathematical based formula as mentioned below.
'
'
' Author: Debmalya Pramanik
FUNCTION fixedDeposit(principal AS VARIANT, rate AS VARIANT, period AS VARIANT, OPTIONAL type_ AS STRING = "C", OPTIONAL compunding AS STRING = "Q") AS VARIANT
DIM maturityValue AS VARIANT ' final maturity amount
DIM n AS INTEGER ' compounding factor, monthly = 12, quarterly = 4, etc.
IF compunding = "Y" THEN
n = 1
ELSEIF compunding = "Q" THEN
n = 4
ELSEIF compunding = "M" THEN
n = 12
ELSE
n = 0 ' invalid input
END IF
' consider rate percentage as number, example rate = 6.5% = 0.065
IF rate > 1 THEN
rate = rate / 100
ELSE
rate = rate
END IF
IF type_ = "S" THEN
maturityValue = principal + (principal * rate * period)
ELSEIF type_ = "C" THEN
maturityValue = principal * (1 + rate / n) ^ (n * period)
ELSE
maturityValue = 0 ' some/one parameter is invalid
END IF
fixedDeposit = maturityValue
END FUNCTION