blend_spreadsheet_loan_generator 0.1.11 → 0.1.16

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: ce1d12c2dd7a108fdcf9e39835ae85d4e736f531d2972f464e310ebb84ace3b5
4
- data.tar.gz: a4237cfbe74341a5b4d60701cfe48c0f5c453476758ad21d4e7ec554ce52f7e3
3
+ metadata.gz: bbb638c6b9da3b44d76b3c6bdcd25ff0c72c859e1f972e5f032b58e202bbb411
4
+ data.tar.gz: b104a0c811a1cc485a9914831db47e613af2a7f873aeffa0cb5dfc45859ba8b7
5
5
  SHA512:
6
- metadata.gz: ea7aad155a20f3065d47536f7a8168681c05bab59e52a54c12ea957a03cb76e56098a81e43ff114e113c7019da011a36f40f6cc392a0fdce090dac0fb46669b7
7
- data.tar.gz: 4405bdd39aa1b68eafb56221a5a5782ce9434a65a5cbc799ee2a8b2933c41ffc722be20357be5b20d16e8681357123dcb9cd1b9066aef50d168bd05181f3949a
6
+ metadata.gz: af51b53a9b4073e41d898ee41d8ca6725b04ce50c16300d00f25a0867af0c3ce874290343ac66d3edb5e2096d7210b287b91b77640ce2cd1304557125146dc08
7
+ data.tar.gz: 22b8948a0826f7f184672a3a0741514f17a7f133f61c46f7699f73dcd78b27dccf31b0cd24cd531a946b6addc404b6e1ee4b72d24cd555cf2d00bcac6ab17238
@@ -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,6 +3,7 @@ module BlendSpreadsheetLoanGenerator
3
3
  extend ActiveSupport::Concern
4
4
 
5
5
  included do
6
+
6
7
  def columns
7
8
  %w[
8
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..guaranteed_line].sum(: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)
@@ -94,10 +106,10 @@ module BlendSpreadsheetLoanGenerator
94
106
  excel_float(values[last_paid_line][:remaining_capital_end])
95
107
 
96
108
  worksheet[2, columns.index('remaining_capital_end') + 1] =
97
- "=#{excel_float(values[last_paid_line][:remaining_capital_end] - capital_paid)} - #{period_interests(2)} - #{period_fees(2)}"
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)} + #{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,8 +11,7 @@ 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
- def period_fees_rate_formula(*)
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
18
17
  end
@@ -1,7 +1,7 @@
1
1
  require 'dry/cli'
2
2
 
3
3
  module BlendSpreadsheetLoanGenerator
4
- VERSION = '0.1.11'
4
+ VERSION = '0.1.16'.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.11
4
+ version: 0.1.16
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-20 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