finrb 0.1.9 → 0.1.11

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: b83c6704f8cac65c1a60cfc40a6972b034d8973fdbedb0b9fe2876331bc22031
4
- data.tar.gz: 6a9be9fad747b92d84dca502131d00e529301514f1bf0a3e3a6fc8bf55ebaa8f
3
+ metadata.gz: 70ffddb4fc39b755fea5fc6999eb3b25d9da39f1384f84d21d2a1dd34d2e89b3
4
+ data.tar.gz: a34054fe375454259ccee5f5ac7cf46f12d67705301c0eba88b44c649bbf8046
5
5
  SHA512:
6
- metadata.gz: 6437f4e742ace2746729fefc2d337c306f9beb6e9a1b63b4d7ce5ae280f4204683d281ec33473b59360a723d639228d8034c09f214f6391f511a1a0ee89fe6b9
7
- data.tar.gz: ccf43a50273fc4d175ebc688dfceda0ad8a4bf70316096e5e843e2360dd621ade89f81b16da8d78798c06caac2a9bec252c0ed0b4656c8dfe04ea420b40186bb
6
+ metadata.gz: a7695ba1956716fd1e592ccbb01f4b0b45fba4ea7d4b3369d6fc8598070ccf3efeab66207ba1368d881453e21d3cdc6a2f9627bcc410d7345041c042b4cb3b1e
7
+ data.tar.gz: 664c65612915fd5319e844097ad328b95b7605204140f90eb5eb8773123602ff0fee536a87650d20d6fabc8dd57b02f549fabbb8bcc9fc2511d12a3726270da2
data/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # finrb changelog
2
2
 
3
+ ## 0.1.11
4
+
5
+ - fix activesupport configurable deprecation (thanks to @schinery)
6
+ - bump gem versions
7
+
8
+ ## 0.1.10
9
+
10
+ - bump gem versions
11
+ - sanitize Float/BigDecimal return from Utils model, assert Flt::DecNum return type across.
12
+
3
13
  ## 0.1.9
4
14
 
5
15
  - bump gem versions
@@ -21,7 +31,7 @@
21
31
 
22
32
  ## 0.1.4
23
33
 
24
- - transactions rails fix
34
+ - transactions rails fix (thanks to @MattHall)
25
35
  - rm ruby 3.0 support
26
36
 
27
37
  ## 0.1.2
@@ -100,12 +100,7 @@ module Finrb
100
100
  def xirr(guess = nil)
101
101
  # Make sure we have a valid sequence of cash flows.
102
102
  positives, negatives = partition { |t| t.amount >= 0 }
103
- if positives.empty? || negatives.empty?
104
- raise(
105
- ArgumentError,
106
- 'Calculation does not converge. Cashflow needs to have a least one positive and one negative value.'
107
- )
108
- end
103
+ raise(ArgumentError, 'Calculation does not converge. Cashflow needs to have a least one positive and one negative value.') if positives.empty? || negatives.empty?
109
104
 
110
105
  func = Function.new(self, :xnpv)
111
106
  rate = [valid(guess)]
data/lib/finrb/config.rb CHANGED
@@ -1,11 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Finrb
4
- include ActiveSupport::Configurable
4
+ Config = Struct.new(:eps, :guess, :business_days, :periodic_compound)
5
+ private_constant :Config
5
6
 
6
- default_values = { eps: '1.0e-16', guess: 1.0, business_days: false, periodic_compound: false }
7
+ def self.config
8
+ @config ||= Config.new(eps: '1.0e-16', guess: 1.0, business_days: false, periodic_compound: false)
9
+ end
7
10
 
8
- default_values.each do |key, value|
9
- config.__send__(:"#{key.to_sym}=", value)
11
+ def self.configure
12
+ yield(config)
10
13
  end
11
14
  end
data/lib/finrb/rates.rb CHANGED
@@ -8,6 +8,7 @@ module Finrb
8
8
  # @api public
9
9
  class Rate
10
10
  include Comparable
11
+
11
12
  # Accepted rate types
12
13
  TYPES = { apr: 'effective', apy: 'effective', effective: 'effective', nominal: 'nominal' }.freeze
13
14
  public_constant :TYPES
data/lib/finrb/utils.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'active_support'
3
4
  require 'active_support/core_ext/array/wrap'
4
5
  require_relative 'decimal'
5
6
  require 'bigdecimal'
@@ -220,7 +221,7 @@ module Finrb
220
221
 
221
222
  raise(FinrbError, 't should be larger than 1') if t < 2
222
223
 
223
- ddb = [0] * t
224
+ ddb = [Flt::DecNum(0)] * t
224
225
  ddb[0] = cost * 2 / t
225
226
  if cost - ddb.first <= rv
226
227
  ddb[0] = cost - rv
@@ -319,7 +320,7 @@ module Finrb
319
320
 
320
321
  root = [BigDecimal(((upper - lower) / 2).to_s)]
321
322
  nlsolve(nlfunc, root)
322
- root.first
323
+ Flt::DecNum(root.first)
323
324
  end
324
325
 
325
326
  # Convert stated annual rate to the effective annual rate
@@ -360,7 +361,7 @@ module Finrb
360
361
  def self.ear2bey(ear:)
361
362
  ear = Flt::DecNum(ear.to_s)
362
363
 
363
- ((((ear + 1)**0.5) - 1) * 2)
364
+ (((ear + 1).sqrt - 1) * 2)
364
365
  end
365
366
 
366
367
  # Computing HPR, the holding period return
@@ -500,7 +501,6 @@ module Finrb
500
501
  raise(FinrbError, 'Error: type should be 0 or 1!')
501
502
  else
502
503
  (pmt / r * (((r + 1)**n) - 1)) * ((r + 1)**type) * -1
503
-
504
504
  end
505
505
  end
506
506
 
@@ -550,7 +550,7 @@ module Finrb
550
550
  r = Array.wrap(r).map { |value| Flt::DecNum(value.to_s) }
551
551
 
552
552
  rs = r.map { |value| value + 1 }
553
- ((rs.reduce(:*)**(1.to_f / rs.size)) - 1)
553
+ ((rs.reduce(:*)**(Flt::DecNum(1) / rs.size)) - 1)
554
554
  end
555
555
 
556
556
  # gross profit margin -- Evaluate a company's financial performance
@@ -573,7 +573,7 @@ module Finrb
573
573
  def self.harmonic_mean(p:)
574
574
  p = Array.wrap(p).map { |value| Flt::DecNum(value.to_s) }
575
575
 
576
- (1.to_f / (p.sum { |val| 1.to_f / val } / p.size))
576
+ (Flt::DecNum(1) / (p.sum { |val| Flt::DecNum(1) / val } / p.size))
577
577
  end
578
578
 
579
579
  # Computing HPR, the holding period return
@@ -647,7 +647,7 @@ module Finrb
647
647
 
648
648
  root = [0]
649
649
  nlsolve(nlfunc, root)
650
- root.first
650
+ Flt::DecNum(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
@@ -717,8 +717,7 @@ module Finrb
717
717
  if type != 0 && type != 1
718
718
  raise(FinrbError, 'Error: type should be 0 or 1!')
719
719
  else
720
- (((fv * r) - (pmt * ((r + 1)**type))) * -1 / ((pv * r) + (pmt * ((r + 1)**type)))).to_dec.log / (r + 1).to_dec.log
721
-
720
+ (((fv * r) - (pmt * ((r + 1)**type))) * Flt::DecNum(-1) / ((pv * r) + (pmt * ((r + 1)**type)))).to_dec.log / (r + 1).to_dec.log
722
721
  end
723
722
  end
724
723
 
@@ -774,7 +773,7 @@ module Finrb
774
773
  if type != 0 && type != 1
775
774
  raise(FinrbError, 'Error: type should be 0 or 1!')
776
775
  else
777
- (pv + (fv / ((r + 1)**n))) * r / (1 - (1.to_f / ((r + 1)**n))) * -1 * ((r + 1)**(type * -1))
776
+ (pv + (fv / ((r + 1)**n))) * r / (1 - (Flt::DecNum(1) / ((r + 1)**n))) * -1 * ((r + 1)**(type * -1))
778
777
  end
779
778
  end
780
779
 
@@ -801,7 +800,6 @@ module Finrb
801
800
  raise(FinrbError, 'Error: type should be 0 or 1!')
802
801
  else
803
802
  Finrb::Utils.pv_simple(r:, n:, fv:) + Finrb::Utils.pv_annuity(r:, n:, pmt:, type:)
804
-
805
803
  end
806
804
  end
807
805
 
@@ -825,8 +823,7 @@ module Finrb
825
823
  if type != 0 && type != 1
826
824
  raise(FinrbError, 'Error: type should be 0 or 1!')
827
825
  else
828
- (pmt / r * (1 - (1.to_f / ((r + 1)**n)))) * ((r + 1)**type) * -1
829
-
826
+ (pmt / r * (1 - (Flt::DecNum(1) / ((r + 1)**n)))) * ((r + 1)**type) * -1
830
827
  end
831
828
  end
832
829
 
@@ -856,7 +853,6 @@ module Finrb
856
853
  raise(FinrbError, 'Error: g is not smaller than r!')
857
854
  else
858
855
  (pmt / (r - g)) * ((r + 1)**type) * -1
859
-
860
856
  end
861
857
  end
862
858
 
@@ -952,7 +948,7 @@ module Finrb
952
948
  pmt = Flt::DecNum(pmt.to_s)
953
949
  pv = Flt::DecNum(pv.to_s)
954
950
 
955
- (pmt * -1 / pv)
951
+ (pmt * Flt::DecNum(-1) / pv)
956
952
  end
957
953
 
958
954
  # Computing Sampling error
@@ -1041,14 +1037,14 @@ module Finrb
1041
1037
  r = ev.size
1042
1038
  s = bv.size
1043
1039
  t = cfr.size
1044
- wr = 1
1040
+ wr = Flt::DecNum(1)
1045
1041
  if r != s || r != t || s != t
1046
1042
  raise(FinrbError, 'Different number of values!')
1047
1043
  else
1048
1044
  (0...r).each do |i|
1049
1045
  wr *= (Finrb::Utils.hpr(ev: ev[i], bv: bv[i], cfr: cfr[i]) + 1)
1050
1046
  end
1051
- ((wr**(1.to_f / r)) - 1)
1047
+ ((wr**(Flt::DecNum(1) / r)) - 1)
1052
1048
  end
1053
1049
  end
1054
1050
 
data/lib/finrb.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'active_support/configurable'
3
+ require 'active_support'
4
4
  require 'finrb/cashflows'
5
5
  require 'finrb/config'
6
6
  require 'finrb/decimal'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: finrb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.9
4
+ version: 0.1.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nadir Cohen
@@ -65,6 +65,34 @@ dependencies:
65
65
  - - ">="
66
66
  - !ruby/object:Gem::Version
67
67
  version: '0'
68
+ - !ruby/object:Gem::Dependency
69
+ name: amazing_print
70
+ requirement: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ type: :development
76
+ prerelease: false
77
+ version_requirements: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ - !ruby/object:Gem::Dependency
83
+ name: ostruct
84
+ requirement: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ type: :development
90
+ prerelease: false
91
+ version_requirements: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
68
96
  - !ruby/object:Gem::Dependency
69
97
  name: pry
70
98
  requirement: !ruby/object:Gem::Requirement
@@ -235,7 +263,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
235
263
  - !ruby/object:Gem::Version
236
264
  version: '0'
237
265
  requirements: []
238
- rubygems_version: 3.6.9
266
+ rubygems_version: 4.0.8
239
267
  specification_version: 4
240
268
  summary: Ruby gem for financial calculations/modeling
241
269
  test_files: []