blend_spreadsheet_loan_generator 0.1.13 → 0.1.18

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 618d3364164eaf1ace3bcc3ac97c45e43a2d500d051c5f1df4bb6fcb6c996d44
4
- data.tar.gz: cbef182d16b9ea12ab58fc088f9c2a3de502984e113473b56fdc4e2b7f9740dd
3
+ metadata.gz: 6f1bd528dfab34e5a542c71fb717a135514bcd836c514459aa3cd48370d8c6ce
4
+ data.tar.gz: 158fd28b4211df4ba3bc97b9fb79aa585267e2fb430974454f81780e3582c0aa
5
5
  SHA512:
6
- metadata.gz: b76eb4e785d03ea71309bde25517a4f3b164074ceb015cde53e37c9b398c42eae38db3f95509adeae186cf7bfa465a7f1d58cf7bd8453f188f134c88734f154c
7
- data.tar.gz: 6239c5066987b013a0bcbaf0d03bb2b78905fcae65a3f3d35d895251162f7d4ebbbe619467c517ed2ff33566aaacd6079edb04187f443ab05e2d42adb3075d0a
6
+ metadata.gz: 26472f95146cb98da47c04b28cb1fd1fc03e318cdcf1f960cce59b8faca80e4a007b8bcfd85a24ee259babdce978acae868b0fe20d0132694d45dcc0d8ba5853
7
+ data.tar.gz: e88f0c3853586ecbc59cdbc0c255543dc19816e1873f35b3242bb6701f4aeef5b9a9a0dce4335efbfb6f5af0bdd3861c68931fcc10c54a66e56500a7db8cb212
@@ -27,3 +27,24 @@ module BlendSpreadsheetLoanGenerator
27
27
  end
28
28
  end
29
29
  end
30
+
31
+
32
+ def generate_csv(data:, name:)
33
+ CSV.open(name, 'wb') do |csv|
34
+ data.each do |datum|
35
+ row = []
36
+ datum.each.with_index do |value, index|
37
+ row << (
38
+ if index == 0
39
+ value.to_i
40
+ elsif index == 1
41
+ Date.parse(value).strftime('%m/%d/%Y')
42
+ else
43
+ value.gsub(',', '.').to_f
44
+ end
45
+ )
46
+ end
47
+ csv << row
48
+ end
49
+ end
50
+ end
@@ -3,7 +3,7 @@ module BlendSpreadsheetLoanGenerator
3
3
  extend ActiveSupport::Concern
4
4
 
5
5
  included do
6
-
6
+
7
7
  def columns
8
8
  %w[
9
9
  index
@@ -12,6 +12,8 @@ module BlendSpreadsheetLoanGenerator
12
12
  argument :from_path, type: :string, required: true, desc: 'csv to restructure'
13
13
  argument :rate, type: :float, required: true, desc: 'year rate post restructuration'
14
14
 
15
+ option :guaranteed_terms, type: :integer, default: 0
16
+ option :duration, type: :integer, desc: 'duration'
15
17
  option :period_duration, type: :integer, default: 1, desc: 'duration of a period in months'
16
18
  option :due_on, type: :date, default: Date.today, desc: 'date of the pay day of the first period DD/MM/YYYY'
17
19
  option :deferred_and_capitalized, type: :integer, default: 0, desc: 'periods with no capital or interests paid'
@@ -42,6 +44,14 @@ module BlendSpreadsheetLoanGenerator
42
44
  values.map! { |r| set_types([columns, r].transpose.to_h.with_indifferent_access) }
43
45
 
44
46
  last_paid_line = values.index { |term| term[:index] == last_paid_term.to_i }
47
+ guaranteed_line = values.index { |term| term[:index] == options.fetch(:guaranteed_terms, nil) } || nil
48
+ total_guaranteed_interests = (
49
+ if guaranteed_line.present? && guaranteed_line > last_paid_line
50
+ values[(last_paid_line + 1)..guaranteed_line].sum { |value| value[:period_calculated_interests] }
51
+ else
52
+ 0
53
+ end
54
+ )
45
55
 
46
56
  total_to_be_paid = (
47
57
  values[last_paid_line + 1][:remaining_capital_start] +
@@ -54,19 +64,21 @@ module BlendSpreadsheetLoanGenerator
54
64
  if total_to_be_paid == amount_paid
55
65
  1
56
66
  else
57
- values.last[:index] - values[last_paid_line][:index]
67
+ options.fetch(:duration, values.last[:index] - values[last_paid_line][:index])
58
68
  end
59
69
  )
60
70
 
61
- starting_capitalized_interests = 0.0
62
- starting_capitalized_fees = 0.0
63
-
64
71
  due_on = values[last_paid_line + 1][:due_on] + 1.month
65
72
 
66
73
  capital_paid = amount_paid.to_f - (
67
74
  values[last_paid_line + 1][:capitalized_interests_start] +
68
75
  values[last_paid_line + 1][:capitalized_fees_start]
69
76
  )
77
+ guaranteed_interests_paid = (
78
+ (capital_paid.to_f / values[last_paid_line + 1][:remaining_capital_start]) *
79
+ total_guaranteed_interests
80
+ )
81
+ capital_paid -= guaranteed_interests_paid
70
82
 
71
83
  @loan = Loan.new(
72
84
  amount: values[last_paid_line][:remaining_capital_end],
@@ -79,8 +91,8 @@ module BlendSpreadsheetLoanGenerator
79
91
  deferred: options.fetch(:deferred),
80
92
  type: options.fetch(:type),
81
93
  interests_type: options.fetch(:interests_type),
82
- starting_capitalized_interests: starting_capitalized_interests,
83
- starting_capitalized_fees: starting_capitalized_fees
94
+ starting_capitalized_interests: 0.0,
95
+ starting_capitalized_fees: 0.0
84
96
  )
85
97
 
86
98
  spreadsheet = session.create_spreadsheet(loan.name)
@@ -97,7 +109,7 @@ module BlendSpreadsheetLoanGenerator
97
109
  "=#{excel_float(values[last_paid_line][:remaining_capital_end])} - #{period_capital(2)}"
98
110
 
99
111
  worksheet[2, columns.index('period_interests') + 1] =
100
- "=ARRONDI(#{period_theoric_interests(2)}; 2)"
112
+ "=ARRONDI(#{period_theoric_interests(2)} + #{excel_float(guaranteed_interests_paid)}; 2)"
101
113
 
102
114
  worksheet[2, columns.index('period_theoric_interests') + 1] =
103
115
  "=#{excel_float(values[last_paid_line + 1][:period_calculated_interests])}"
@@ -11,7 +11,6 @@ module BlendSpreadsheetLoanGenerator
11
11
  "=#{excel_float(loan.rate)} * ((#{period_leap_days(line)} / 366) + (#{period_non_leap_days(line)} / 365))"
12
12
  end
13
13
 
14
-
15
14
  def period_fees_rate_formula(line:)
16
15
  "=#{excel_float(loan.fees_rate)} * ((#{period_leap_days(line)} / 366) + (#{period_non_leap_days(line)} / 365))"
17
16
  end
@@ -1,7 +1,7 @@
1
1
  require 'dry/cli'
2
2
 
3
3
  module BlendSpreadsheetLoanGenerator
4
- VERSION = '0.1.13'
4
+ VERSION = '0.1.18'.freeze
5
5
 
6
6
  class Version < Dry::CLI::Command
7
7
  desc 'Print version'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blend_spreadsheet_loan_generator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.13
4
+ version: 0.1.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - MZiserman
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-05-21 00:00:00.000000000 Z
11
+ date: 2021-07-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport