-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathexample_amortization_test.go
184 lines (170 loc) · 4.6 KB
/
example_amortization_test.go
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
package gofinancial_test
import (
"time"
"github.com/shopspring/decimal"
gofinancial "github.com/razorpay/go-financial"
"github.com/razorpay/go-financial/enums/frequency"
"github.com/razorpay/go-financial/enums/interesttype"
"github.com/razorpay/go-financial/enums/paymentperiod"
)
// This example generates amortization table for a loan of 20 lakhs over 15years at 12% per annum.
func ExampleAmortization_GenerateTable() {
loc, err := time.LoadLocation("Asia/Kolkata")
if err != nil {
panic("location loading error")
}
currentDate := time.Date(2009, 11, 11, 4, 30, 0, 0, loc)
config := gofinancial.Config{
// start date is inclusive
StartDate: currentDate,
// end date is inclusive.
EndDate: currentDate.AddDate(15, 0, 0).AddDate(0, 0, -1),
Frequency: frequency.ANNUALLY,
// AmountBorrowed is in paisa
AmountBorrowed: decimal.NewFromInt(200000000),
// InterestType can be flat or reducing
InterestType: interesttype.REDUCING,
// interest is in basis points
Interest: decimal.NewFromInt(1200),
// amount is paid at the end of the period
PaymentPeriod: paymentperiod.ENDING,
// all values will be rounded
EnableRounding: true,
// it will be rounded to nearest int
RoundingPlaces: 0,
// no error is tolerated
RoundingErrorTolerance: decimal.Zero,
}
amortization, err := gofinancial.NewAmortization(&config)
if err != nil {
panic(err)
}
rows, err := amortization.GenerateTable()
if err != nil {
panic(err)
}
gofinancial.PrintRows(rows)
// Output:
// [
// {
// "Period": 1,
// "StartDate": "2009-11-11T04:30:00+05:30",
// "EndDate": "2010-11-10T23:59:59+05:30",
// "Payment": "-29364848",
// "Interest": "-24000000",
// "Principal": "-5364848"
// },
// {
// "Period": 2,
// "StartDate": "2010-11-11T00:00:00+05:30",
// "EndDate": "2011-11-10T23:59:59+05:30",
// "Payment": "-29364848",
// "Interest": "-23356218",
// "Principal": "-6008630"
// },
// {
// "Period": 3,
// "StartDate": "2011-11-11T00:00:00+05:30",
// "EndDate": "2012-11-10T23:59:59+05:30",
// "Payment": "-29364848",
// "Interest": "-22635183",
// "Principal": "-6729665"
// },
// {
// "Period": 4,
// "StartDate": "2012-11-11T00:00:00+05:30",
// "EndDate": "2013-11-10T23:59:59+05:30",
// "Payment": "-29364848",
// "Interest": "-21827623",
// "Principal": "-7537225"
// },
// {
// "Period": 5,
// "StartDate": "2013-11-11T00:00:00+05:30",
// "EndDate": "2014-11-10T23:59:59+05:30",
// "Payment": "-29364848",
// "Interest": "-20923156",
// "Principal": "-8441692"
// },
// {
// "Period": 6,
// "StartDate": "2014-11-11T00:00:00+05:30",
// "EndDate": "2015-11-10T23:59:59+05:30",
// "Payment": "-29364848",
// "Interest": "-19910153",
// "Principal": "-9454695"
// },
// {
// "Period": 7,
// "StartDate": "2015-11-11T00:00:00+05:30",
// "EndDate": "2016-11-10T23:59:59+05:30",
// "Payment": "-29364848",
// "Interest": "-18775589",
// "Principal": "-10589259"
// },
// {
// "Period": 8,
// "StartDate": "2016-11-11T00:00:00+05:30",
// "EndDate": "2017-11-10T23:59:59+05:30",
// "Payment": "-29364848",
// "Interest": "-17504878",
// "Principal": "-11859970"
// },
// {
// "Period": 9,
// "StartDate": "2017-11-11T00:00:00+05:30",
// "EndDate": "2018-11-10T23:59:59+05:30",
// "Payment": "-29364848",
// "Interest": "-16081682",
// "Principal": "-13283166"
// },
// {
// "Period": 10,
// "StartDate": "2018-11-11T00:00:00+05:30",
// "EndDate": "2019-11-10T23:59:59+05:30",
// "Payment": "-29364848",
// "Interest": "-14487702",
// "Principal": "-14877146"
// },
// {
// "Period": 11,
// "StartDate": "2019-11-11T00:00:00+05:30",
// "EndDate": "2020-11-10T23:59:59+05:30",
// "Payment": "-29364848",
// "Interest": "-12702445",
// "Principal": "-16662403"
// },
// {
// "Period": 12,
// "StartDate": "2020-11-11T00:00:00+05:30",
// "EndDate": "2021-11-10T23:59:59+05:30",
// "Payment": "-29364848",
// "Interest": "-10702956",
// "Principal": "-18661892"
// },
// {
// "Period": 13,
// "StartDate": "2021-11-11T00:00:00+05:30",
// "EndDate": "2022-11-10T23:59:59+05:30",
// "Payment": "-29364848",
// "Interest": "-8463529",
// "Principal": "-20901319"
// },
// {
// "Period": 14,
// "StartDate": "2022-11-11T00:00:00+05:30",
// "EndDate": "2023-11-10T23:59:59+05:30",
// "Payment": "-29364848",
// "Interest": "-5955371",
// "Principal": "-23409477"
// },
// {
// "Period": 15,
// "StartDate": "2023-11-11T00:00:00+05:30",
// "EndDate": "2024-11-10T23:59:59+05:30",
// "Payment": "-29364847",
// "Interest": "-3146234",
// "Principal": "-26218613"
// }
// ]
}