finrb 0.1.3 → 0.1.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9b5bd49e4cf559fb2444e5b02d9ef9cf07179f550654cb96d30c872dcb1e4afb
4
- data.tar.gz: 6a9b8425cc3bb48eb699e666787530b213527a31123e6da47f8d4f0317e8f310
3
+ metadata.gz: e895ab637979af1754b20e1c661adfcaafaadda5537628a3df5ea15dc5fe79fc
4
+ data.tar.gz: 68a533652b9864f327be58882817926b7abff6ebc25787dc53508bc59db4720c
5
5
  SHA512:
6
- metadata.gz: 8c381215b764feb8bd1f02742a0c53b271e93a325efd7d968a0a52284715127f73a545f050eb7d13554f8c5db1a52614d55b34e4e16a19ed960c703ef6b33f08
7
- data.tar.gz: e5a06268ea08df5efe66fdba9e37b6c07f2a80f5b98caa82d1622351ba38fd975631bea65959cc286aaa1b16a965e49814e6662363c8094892baa903751de6f0
6
+ metadata.gz: a845b6f3b83b733a5d881f1374f31d56a2719d1efc85d9ca7b76e3bbf31668bf576e3fc8e1a444a601efd42184f6cf95d015da60c1367a2a7c30d8580848875c
7
+ data.tar.gz: 90c2dd4e4af0e74a120498950a9b8111d31ab0d159bb35588e54353345e9216651e88ff257cddb3a09bc294e344fba66e006be81df9deadf6819e52688058ee8
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # finrb changelog
2
2
 
3
+ ## 0.1.4
4
+
5
+ - transactions rails fix
6
+ - rm ruby 3.0 support
7
+
3
8
  ## 0.1.2
4
9
 
5
10
  - refactoring
@@ -140,7 +140,7 @@ module Finrb
140
140
  @balance = 0
141
141
  end
142
142
 
143
- @payment = (payments[0] if @rates.length == 1)
143
+ @payment = (payments.first if @rates.length == 1)
144
144
 
145
145
  @transactions.freeze
146
146
  end
@@ -9,11 +9,11 @@ require 'bigdecimal/newton'
9
9
  require 'business_time'
10
10
 
11
11
  module Finrb
12
- include Newton
13
-
14
12
  # Provides methods for working with cash flows (collections of transactions)
15
13
  # @api public
16
14
  module Cashflow
15
+ include Newton
16
+
17
17
  # Base class for working with Newton's Method.
18
18
  # @api private
19
19
  class Function
@@ -31,7 +31,7 @@ module Finrb
31
31
  end
32
32
 
33
33
  def values(x)
34
- value = @transactions.public_send(@function, Flt::DecNum.new(x[0].to_s))
34
+ value = @transactions.public_send(@function, Flt::DecNum.new(x.first.to_s))
35
35
  begin
36
36
  [BigDecimal(value.to_s)]
37
37
  rescue ArgumentError
@@ -55,10 +55,10 @@ module Finrb
55
55
  func = Function.new(self, :npv)
56
56
  rate = [valid(guess)]
57
57
  nlsolve(func, rate)
58
- rate[0]
58
+ rate.first
59
59
  end
60
60
 
61
- def method_missing(name, *args, &block)
61
+ def method_missing(name, *args, &)
62
62
  return sum if name.to_s == 'sum'
63
63
 
64
64
  super
@@ -110,7 +110,7 @@ module Finrb
110
110
  func = Function.new(self, :xnpv)
111
111
  rate = [valid(guess)]
112
112
  nlsolve(func, rate)
113
- Rate.new(rate[0], :apr, compounds: Finrb.config.periodic_compound ? :continuously : :annually)
113
+ Rate.new(rate.first, :apr, compounds: Finrb.config.periodic_compound ? :continuously : :annually)
114
114
  end
115
115
 
116
116
  # calculate the net present value of a sequence of cash flows
@@ -149,11 +149,11 @@ module Finrb
149
149
  end
150
150
 
151
151
  def start
152
- @start ||= self[0].date
152
+ @start ||= first.date
153
153
  end
154
154
 
155
155
  def stop
156
- @stop ||= self[-1].date.to_date
156
+ @stop ||= last.date.to_date
157
157
  end
158
158
 
159
159
  def valid(guess)
data/lib/finrb/config.rb CHANGED
@@ -6,6 +6,6 @@ module Finrb
6
6
  default_values = { eps: '1.0e-16', guess: 1.0, business_days: false, periodic_compound: false }
7
7
 
8
8
  default_values.each do |key, value|
9
- config.__send__("#{key.to_sym}=", value)
9
+ config.__send__(:"#{key.to_sym}=", value)
10
10
  end
11
11
  end
data/lib/finrb/rates.rb CHANGED
@@ -67,12 +67,12 @@ module Finrb
67
67
 
68
68
  # Set optional attributes..
69
69
  opts.each do |key, value|
70
- __send__("#{key}=", value)
70
+ __send__(:"#{key}=", value)
71
71
  end
72
72
 
73
73
  # Set the rate in the proper way, based on the value of type.
74
74
  begin
75
- __send__("#{TYPES.fetch(type)}=", Flt::DecNum.new(rate.to_s))
75
+ __send__(:"#{TYPES.fetch(type)}=", Flt::DecNum.new(rate.to_s))
76
76
  rescue KeyError
77
77
  raise(ArgumentError, "type must be one of #{TYPES.keys.join(', ')}", caller)
78
78
  end
@@ -33,7 +33,7 @@ module Finrb
33
33
 
34
34
  # Set optional attributes..
35
35
  opts.each do |key, value|
36
- __send__("#{key}=", value)
36
+ __send__(:"#{key}=", value)
37
37
  end
38
38
  end
39
39
 
data/lib/finrb/utils.rb CHANGED
@@ -188,8 +188,8 @@ module Finrb
188
188
  end
189
189
 
190
190
  {
191
- cost_of_goods: cost_of_goods,
192
- ending_inventory: ending_inventory
191
+ cost_of_goods:,
192
+ ending_inventory:
193
193
  }
194
194
  end
195
195
 
@@ -222,10 +222,10 @@ module Finrb
222
222
 
223
223
  ddb = [0] * t
224
224
  ddb[0] = cost * 2 / t
225
- if cost - ddb[0] <= rv
225
+ if cost - ddb.first <= rv
226
226
  ddb[0] = cost - rv
227
227
  else
228
- cost -= ddb[0]
228
+ cost -= ddb.first
229
229
  (1...t).each do |i|
230
230
  ddb[i] = cost * 2 / t
231
231
  if cost - ddb[i] <= rv
@@ -236,7 +236,7 @@ module Finrb
236
236
  end
237
237
  end
238
238
  end
239
- { t: (0...t).to_a, ddb: ddb }
239
+ { t: (0...t).to_a, ddb: }
240
240
  end
241
241
 
242
242
  # debt ratio -- Solvency ratios measure the firm's ability to satisfy its long-term obligations.
@@ -314,12 +314,12 @@ module Finrb
314
314
  nlfunc = NlFunctionStub.new
315
315
  nlfunc.func =
316
316
  lambda do |x|
317
- [BigDecimal((Finrb::Utils.fv_simple(r: x[0], n: n, pv: pv) + Finrb::Utils.fv_annuity(r: x[0], n: n, pmt: pmt, type: type) - fv).to_s)]
317
+ [BigDecimal((Finrb::Utils.fv_simple(r: x.first, n:, pv:) + Finrb::Utils.fv_annuity(r: x.first, n:, pmt:, type:) - fv).to_s)]
318
318
  end
319
319
 
320
320
  root = [(upper - lower) / 2]
321
321
  nlsolve(nlfunc, root)
322
- root[0]
322
+ root.first
323
323
  end
324
324
 
325
325
  # Convert stated annual rate to the effective annual rate
@@ -475,7 +475,7 @@ module Finrb
475
475
  if type != 0 && type != 1
476
476
  raise(FinrbError, 'Error: type should be 0 or 1!')
477
477
  else
478
- (Finrb::Utils.fv_simple(r: r, n: n, pv: pv) + Finrb::Utils.fv_annuity(r: r, n: n, pmt: pmt, type: type))
478
+ (Finrb::Utils.fv_simple(r:, n:, pv:) + Finrb::Utils.fv_annuity(r:, n:, pmt:, type:))
479
479
  end
480
480
  end
481
481
 
@@ -536,7 +536,7 @@ module Finrb
536
536
  sum = 0
537
537
  (0...m).each do |i|
538
538
  n = m - (i + 1)
539
- sum += Finrb::Utils.fv_simple(r: r, n: n, pv: cf[i])
539
+ sum += Finrb::Utils.fv_simple(r:, n:, pv: cf[i])
540
540
  end
541
541
  sum
542
542
  end
@@ -642,12 +642,12 @@ module Finrb
642
642
  nlfunc = NlFunctionStub.new
643
643
  nlfunc.func =
644
644
  lambda do |x|
645
- [BigDecimal(((Finrb::Utils.pv_uneven(r: x[0], cf: subcf) * -1) + cf[0]).to_s)]
645
+ [BigDecimal(((Finrb::Utils.pv_uneven(r: x.first, cf: subcf) * -1) + cf.first).to_s)]
646
646
  end
647
647
 
648
648
  root = [0]
649
649
  nlsolve(nlfunc, root)
650
- root[0]
650
+ root.first
651
651
  end
652
652
 
653
653
  # calculate the net increase in common shares from the potential exercise of stock options or warrants
@@ -746,7 +746,7 @@ module Finrb
746
746
  cf = Array.wrap(cf).map { |value| Flt::DecNum(value.to_s) }
747
747
 
748
748
  subcf = cf.drop(1)
749
- ((Finrb::Utils.pv_uneven(r: r, cf: subcf) * -1) + cf[0])
749
+ ((Finrb::Utils.pv_uneven(r:, cf: subcf) * -1) + cf.first)
750
750
  end
751
751
 
752
752
  # Estimate period payment
@@ -800,7 +800,7 @@ module Finrb
800
800
  if type != 0 && type != 1
801
801
  raise(FinrbError, 'Error: type should be 0 or 1!')
802
802
  else
803
- Finrb::Utils.pv_simple(r: r, n: n, fv: fv) + Finrb::Utils.pv_annuity(r: r, n: n, pmt: pmt, type: type)
803
+ Finrb::Utils.pv_simple(r:, n:, fv:) + Finrb::Utils.pv_annuity(r:, n:, pmt:, type:)
804
804
 
805
805
  end
806
806
  end
@@ -891,7 +891,7 @@ module Finrb
891
891
  n = cf.size
892
892
  sum = 0
893
893
  (0...n).each do |i|
894
- sum += Finrb::Utils.pv_simple(r: r, n: i + 1, fv: cf[i])
894
+ sum += Finrb::Utils.pv_simple(r:, n: i + 1, fv: cf[i])
895
895
  end
896
896
  sum
897
897
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: finrb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nadir Cohen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-10-24 00:00:00.000000000 Z
11
+ date: 2024-04-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -230,14 +230,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
230
230
  requirements:
231
231
  - - ">="
232
232
  - !ruby/object:Gem::Version
233
- version: '3.0'
233
+ version: '3.1'
234
234
  required_rubygems_version: !ruby/object:Gem::Requirement
235
235
  requirements:
236
236
  - - ">="
237
237
  - !ruby/object:Gem::Version
238
238
  version: '0'
239
239
  requirements: []
240
- rubygems_version: 3.4.21
240
+ rubygems_version: 3.5.7
241
241
  signing_key:
242
242
  specification_version: 4
243
243
  summary: Ruby gem for financial calculations/modeling