loan_creator 0.9.0 → 0.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +6 -2
- data/lib/loan_creator/common.rb +34 -5
- data/lib/loan_creator/version.rb +1 -1
- data/scripts/convert_export_to_spec.rb +51 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e207b2a1a30e9f07b773f9d3071c8df1cb815e17602661efb72d4315ead65dba
|
4
|
+
data.tar.gz: c6760d02448a8a9bd6f40fa992aa09f1d716a06b94e2ce5afa8b54eddfeeddf6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 75d786838e61c1f342da8a3ebf3e0264e42f0e80909bc22ffe63f5c76acf4a1c36e1130ebcbcb4f8c72d87f7a99735c8e3d70f634889935dd57849f92bcdf98d
|
7
|
+
data.tar.gz: 768182d707c17e9f5b1f8f748f6dcaf1277e1a1bf0b68c33ed28a178464117272e8dfe294585baeac3fa1d9fb3f28945e1224b7e158fffea66bda89c5cb25dff
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
v0.9.1
|
2
|
+
-------------------------
|
3
|
+
- add spec importer `scripts/convert_export_to_spec.rb {csv_url}`
|
4
|
+
- fix period interests rate for realistic duration period overlapping leap & non leap years
|
5
|
+
|
1
6
|
v0.9.0
|
2
7
|
-------------------------
|
3
8
|
- add possibility to pass the argument `term_dates` for `LoanCreator::Bullet`, `LoanCreator::InFine` and `LoanCreator::Linear`
|
data/README.md
CHANGED
@@ -180,8 +180,12 @@ additional term with only interests for the time difference.
|
|
180
180
|
For example, with a `start_at` in january 2020 and a `interests_start_date` in october 2019, the timetable will include a
|
181
181
|
first term corresponding to 3 months of interests.
|
182
182
|
|
183
|
-
`realistic_durations`: Optional. A boolean
|
184
|
-
|
183
|
+
`realistic_durations`: Optional. A boolean that specifies whether or not to use the real number of days in each month when calculating the periodic interests rate (ie: for a period between January 1st 2021 and February 1st 2021 the period rate is annual_interests_rate * 31/355).
|
184
|
+
Note that leap years are taken into account (ie: for a period between January 1st 2020 and February 1st 2020 the period rate is annual_interests_rate * 31/356). Also, an overlaping period
|
185
|
+
take each parts into account (ie: for a period between December 1st 2020 and February 1st 2021, the period rate is (annual_interests_rate * (31/355) + annual_interests_rate * (31/356)))
|
186
|
+
Default: `false`.
|
187
|
+
The default behaviour is to use the `period` in relation to the number of months in a year (ie: for a monthly timetable annual_interests_rate * 1/12, for quarter annual_interests_rate * 3/12, etc.)
|
188
|
+
|
185
189
|
|
186
190
|
`term_dates`: Optional. Implemented for `LoanCreator::Bullet`, `LoanCreator::InFine` and `LoanCreator::Linear`. Can be used if you want to implement custom due dates for terms. Terms will be compute from date to date. Must be an array with following dates.
|
187
191
|
|
data/lib/loan_creator/common.rb
CHANGED
@@ -236,12 +236,41 @@ module LoanCreator
|
|
236
236
|
(interests_start_date && interests_start_date < term_zero_date) && !term_dates?
|
237
237
|
end
|
238
238
|
|
239
|
-
def
|
240
|
-
|
241
|
-
|
242
|
-
|
239
|
+
def leap_days_count(date, relative_to_date:)
|
240
|
+
start_year = relative_to_date.year
|
241
|
+
end_year = date.year
|
242
|
+
|
243
|
+
(start_year..end_year).sum do |year|
|
244
|
+
next 0 unless Date.gregorian_leap?(year)
|
243
245
|
|
244
|
-
|
246
|
+
start_date =
|
247
|
+
if start_year == year
|
248
|
+
relative_to_date
|
249
|
+
else
|
250
|
+
Date.new(year - 1, 12, 31)
|
251
|
+
end
|
252
|
+
|
253
|
+
end_date =
|
254
|
+
if end_year == year
|
255
|
+
date
|
256
|
+
else
|
257
|
+
Date.new(year, 12, 31)
|
258
|
+
end
|
259
|
+
|
260
|
+
end_date - start_date
|
261
|
+
end
|
262
|
+
end
|
263
|
+
|
264
|
+
def compute_realistic_periodic_interests_rate_percentage_for(date, relative_to_date:)
|
265
|
+
total_days = date - relative_to_date
|
266
|
+
leap_days = bigd(leap_days_count(date, relative_to_date: relative_to_date))
|
267
|
+
non_leap_days = bigd(total_days - leap_days)
|
268
|
+
|
269
|
+
annual_interests_rate.mult(
|
270
|
+
leap_days.div(366, BIG_DECIMAL_DIGITS) +
|
271
|
+
non_leap_days.div(365, BIG_DECIMAL_DIGITS),
|
272
|
+
BIG_DECIMAL_DIGITS
|
273
|
+
)
|
245
274
|
end
|
246
275
|
|
247
276
|
def realistic_durations?
|
data/lib/loan_creator/version.rb
CHANGED
@@ -0,0 +1,51 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'csv'
|
3
|
+
require 'open-uri'
|
4
|
+
require 'pry'
|
5
|
+
require 'securerandom'
|
6
|
+
|
7
|
+
csv_url = ARGV[0]
|
8
|
+
|
9
|
+
spec_order = %i[
|
10
|
+
index
|
11
|
+
due_on
|
12
|
+
crd_beginning_of_period
|
13
|
+
crd_end_of_period
|
14
|
+
period_theoric_interests
|
15
|
+
delta_interests
|
16
|
+
accrued_delta_interests
|
17
|
+
amount_to_add
|
18
|
+
period_interests
|
19
|
+
period_capital
|
20
|
+
total_paid_capital_end_of_period
|
21
|
+
total_paid_interests_end_of_period
|
22
|
+
period_amount_to_pay
|
23
|
+
due_interests_beginning_of_period
|
24
|
+
due_interests_end_of_period
|
25
|
+
]
|
26
|
+
|
27
|
+
column_getter = {
|
28
|
+
index: proc { |r| r['t'].to_i },
|
29
|
+
due_on: proc { |r| r['date'] },
|
30
|
+
crd_beginning_of_period: proc { |r| r['crd_start'].gsub(',', '.').to_f },
|
31
|
+
crd_end_of_period: proc { |r| r['crd_end'].gsub(',', '.').to_f },
|
32
|
+
period_theoric_interests: proc { |r| r['period_theoric_interests'].gsub(',', '.').to_f },
|
33
|
+
delta_interests: proc { |r| r['delta_interests'].gsub(',', '.').to_f },
|
34
|
+
accrued_delta_interests: proc { |r| r['cumulated_delta_interests'].gsub(',', '.').to_f },
|
35
|
+
amount_to_add: proc { |r| r['amount_to_add'].gsub(',', '.').to_f },
|
36
|
+
period_interests: proc { |r| r['period_interests'].gsub(',', '.').to_f },
|
37
|
+
period_capital: proc { |r| r['period_capital'].gsub(',', '.').to_f },
|
38
|
+
total_paid_capital_end_of_period: proc { |r| r['total_capital_paid'].gsub(',', '.').to_f },
|
39
|
+
total_paid_interests_end_of_period: proc { |r| r['total_interests_paid'].gsub(',', '.').to_f },
|
40
|
+
period_amount_to_pay: proc { |r| r['period_total'].gsub(',', '.').to_f },
|
41
|
+
due_interests_beginning_of_period: proc { |r| r['due_interests_beginning_of_period'].gsub(',', '.').to_f },
|
42
|
+
due_interests_end_of_period: proc { |r| r['due_interests_end_of_period'].gsub(',', '.').to_f }
|
43
|
+
}
|
44
|
+
|
45
|
+
data = CSV.parse(URI.open(csv_url), headers: true).map(&:to_hash)
|
46
|
+
|
47
|
+
CSV.open("./spec/fixtures/new/#{SecureRandom.alphanumeric}.csv", 'w') do |csv|
|
48
|
+
data.each do |row|
|
49
|
+
csv << spec_order.map { |column| column_getter[column].call(row) }
|
50
|
+
end
|
51
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: loan_creator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- thibaulth
|
@@ -12,7 +12,7 @@ authors:
|
|
12
12
|
autorequire:
|
13
13
|
bindir: exe
|
14
14
|
cert_chain: []
|
15
|
-
date: 2021-05-
|
15
|
+
date: 2021-05-11 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: bundler
|
@@ -182,6 +182,7 @@ files:
|
|
182
182
|
- lib/loan_creator/uncapitalized_bullet.rb
|
183
183
|
- lib/loan_creator/version.rb
|
184
184
|
- loan_creator.gemspec
|
185
|
+
- scripts/convert_export_to_spec.rb
|
185
186
|
homepage: https://github.com/CapSens/loan-creator
|
186
187
|
licenses:
|
187
188
|
- MIT
|