blend_spreadsheet_loan_generator 0.1.12 → 0.1.17

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: 429804f58506c0a6cdda42e92f010df902da84f08b86821a104c67f3f7e8f697
4
- data.tar.gz: 7b201c96e8d916ea9e8e7f56a7288102e22de2cf7be43a05f15804120f3bbd05
3
+ metadata.gz: ab1273f7e038e128f03cb7880db2c0233968e48369f564ddb2e9626df330b8dd
4
+ data.tar.gz: 90ab851c0a9bd1dd2800a28fe7e293391815ee97072e8be1cd902b0677d23d71
5
5
  SHA512:
6
- metadata.gz: 22327802c88e6127bc5580d1cd129d057ccb4bd85321b2d948dd52a6a43e6fbeee72048ae3128427271580449de2f557e8640c424888929295ef3cc44381893e
7
- data.tar.gz: 9ac1b5d6182455f833f25904c7b022d1153c9983b0d57b7656d57174cf342cef8ac4c589de75e7d29a24354ee34ba0cdc672e91b9fb6247be365cdee066362a4
6
+ metadata.gz: 83a322704b32486bc37ab697f1fa625646cd424fb12696d822bca1cb44693f59c0ca66e1cf6cb4ea108f586d7904b39e167ce974563e765cc0f3d17d5d581e61
7
+ data.tar.gz: ceeef05aa0320b1823cb250d74505e24548f5812334e4efd24f5af9f480762bbd6a5533d8041a502e5110a89f21ced424ffc444645efa5361fefb19bb5b580b9
@@ -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 + 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)} + #{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.12'
4
+ VERSION = '0.1.17'.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.12
4
+ version: 0.1.17
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