finrb 0.1.8 → 0.1.10

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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +10 -0
  3. data/lib/finrb/utils.rb +13 -18
  4. metadata +15 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f3b6d3b8d77dfc3804a971f4f3338c1a47fbd4198ea9ca57f01bef89e68866d0
4
- data.tar.gz: ff519aba0cb7e9e405a5b980d8a350c0646be63929c4c3874038f734e24c89ea
3
+ metadata.gz: 5d1facf891947f1761bb42daf4941bf8557e5fc1fb0388d28265cb7e52bd5876
4
+ data.tar.gz: ce0c145c292f33254edafa6ace4aeb257dde55dea04b99c662ad34933d108c4c
5
5
  SHA512:
6
- metadata.gz: 1ae39fa89168de7095358f7054047c2936b3f76906b3b6b81e0ad80fdc8aba8c571d9ed439c428ec29c99efa1bb95fe1ec640b799c481c54dd2527cc1818a42b
7
- data.tar.gz: a773cbaa86fd79402fbe51be37fd73848ccf2cdfc819fb4991ceab10e974c4aa7796631e498c2d182e7124af1c98f43f4f54c353e8bc010f5d173fc4b173bb1b
6
+ metadata.gz: c589343b7b081456571dbc1644be1c75a301c99232ebe8a87eefcf093357cb116e6de85d2769f40b9e9a4c1edf261a0e96c1b9f6036f267e5c0068cb5e429d99
7
+ data.tar.gz: 9267d28b64bdbf8c1e6c4b1faa4a980c7c2449039e89cb2db10e807a234fc5657fac4aaa536a361fa3c8dfe9b3f553eb23e57189c2530937097338fe883a32d5
data/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # finrb changelog
2
2
 
3
+ ## 0.1.10
4
+
5
+ - bump gem versions
6
+ - sanitize Float/BigDecimal return from Utils model, assert Flt::DecNum return type across.
7
+
8
+ ## 0.1.9
9
+
10
+ - bump gem versions
11
+ - fix BigDecimal 3.2 compatibility
12
+
3
13
  ## 0.1.8
4
14
 
5
15
  - bump gem versions
data/lib/finrb/utils.rb CHANGED
@@ -220,7 +220,7 @@ module Finrb
220
220
 
221
221
  raise(FinrbError, 't should be larger than 1') if t < 2
222
222
 
223
- ddb = [0] * t
223
+ ddb = [Flt::DecNum(0)] * t
224
224
  ddb[0] = cost * 2 / t
225
225
  if cost - ddb.first <= rv
226
226
  ddb[0] = cost - rv
@@ -317,9 +317,9 @@ module Finrb
317
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
- root = [(upper - lower) / 2]
320
+ root = [BigDecimal(((upper - lower) / 2).to_s)]
321
321
  nlsolve(nlfunc, root)
322
- root.first
322
+ Flt::DecNum(root.first)
323
323
  end
324
324
 
325
325
  # Convert stated annual rate to the effective annual rate
@@ -360,7 +360,7 @@ module Finrb
360
360
  def self.ear2bey(ear:)
361
361
  ear = Flt::DecNum(ear.to_s)
362
362
 
363
- ((((ear + 1)**0.5) - 1) * 2)
363
+ (((ear + 1).sqrt - 1) * 2)
364
364
  end
365
365
 
366
366
  # Computing HPR, the holding period return
@@ -500,7 +500,6 @@ module Finrb
500
500
  raise(FinrbError, 'Error: type should be 0 or 1!')
501
501
  else
502
502
  (pmt / r * (((r + 1)**n) - 1)) * ((r + 1)**type) * -1
503
-
504
503
  end
505
504
  end
506
505
 
@@ -550,7 +549,7 @@ module Finrb
550
549
  r = Array.wrap(r).map { |value| Flt::DecNum(value.to_s) }
551
550
 
552
551
  rs = r.map { |value| value + 1 }
553
- ((rs.reduce(:*)**(1.to_f / rs.size)) - 1)
552
+ ((rs.reduce(:*)**(Flt::DecNum(1) / rs.size)) - 1)
554
553
  end
555
554
 
556
555
  # gross profit margin -- Evaluate a company's financial performance
@@ -573,7 +572,7 @@ module Finrb
573
572
  def self.harmonic_mean(p:)
574
573
  p = Array.wrap(p).map { |value| Flt::DecNum(value.to_s) }
575
574
 
576
- (1.to_f / (p.sum { |val| 1.to_f / val } / p.size))
575
+ (Flt::DecNum(1) / (p.sum { |val| Flt::DecNum(1) / val } / p.size))
577
576
  end
578
577
 
579
578
  # Computing HPR, the holding period return
@@ -647,7 +646,7 @@ module Finrb
647
646
 
648
647
  root = [0]
649
648
  nlsolve(nlfunc, root)
650
- root.first
649
+ Flt::DecNum(root.first)
651
650
  end
652
651
 
653
652
  # calculate the net increase in common shares from the potential exercise of stock options or warrants
@@ -717,8 +716,7 @@ module Finrb
717
716
  if type != 0 && type != 1
718
717
  raise(FinrbError, 'Error: type should be 0 or 1!')
719
718
  else
720
- (((fv * r) - (pmt * ((r + 1)**type))) * -1 / ((pv * r) + (pmt * ((r + 1)**type)))).to_dec.log / (r + 1).to_dec.log
721
-
719
+ (((fv * r) - (pmt * ((r + 1)**type))) * Flt::DecNum(-1) / ((pv * r) + (pmt * ((r + 1)**type)))).to_dec.log / (r + 1).to_dec.log
722
720
  end
723
721
  end
724
722
 
@@ -774,7 +772,7 @@ module Finrb
774
772
  if type != 0 && type != 1
775
773
  raise(FinrbError, 'Error: type should be 0 or 1!')
776
774
  else
777
- (pv + (fv / ((r + 1)**n))) * r / (1 - (1.to_f / ((r + 1)**n))) * -1 * ((r + 1)**(type * -1))
775
+ (pv + (fv / ((r + 1)**n))) * r / (1 - (Flt::DecNum(1) / ((r + 1)**n))) * -1 * ((r + 1)**(type * -1))
778
776
  end
779
777
  end
780
778
 
@@ -801,7 +799,6 @@ module Finrb
801
799
  raise(FinrbError, 'Error: type should be 0 or 1!')
802
800
  else
803
801
  Finrb::Utils.pv_simple(r:, n:, fv:) + Finrb::Utils.pv_annuity(r:, n:, pmt:, type:)
804
-
805
802
  end
806
803
  end
807
804
 
@@ -825,8 +822,7 @@ module Finrb
825
822
  if type != 0 && type != 1
826
823
  raise(FinrbError, 'Error: type should be 0 or 1!')
827
824
  else
828
- (pmt / r * (1 - (1.to_f / ((r + 1)**n)))) * ((r + 1)**type) * -1
829
-
825
+ (pmt / r * (1 - (Flt::DecNum(1) / ((r + 1)**n)))) * ((r + 1)**type) * -1
830
826
  end
831
827
  end
832
828
 
@@ -856,7 +852,6 @@ module Finrb
856
852
  raise(FinrbError, 'Error: g is not smaller than r!')
857
853
  else
858
854
  (pmt / (r - g)) * ((r + 1)**type) * -1
859
-
860
855
  end
861
856
  end
862
857
 
@@ -952,7 +947,7 @@ module Finrb
952
947
  pmt = Flt::DecNum(pmt.to_s)
953
948
  pv = Flt::DecNum(pv.to_s)
954
949
 
955
- (pmt * -1 / pv)
950
+ (pmt * Flt::DecNum(-1) / pv)
956
951
  end
957
952
 
958
953
  # Computing Sampling error
@@ -1041,14 +1036,14 @@ module Finrb
1041
1036
  r = ev.size
1042
1037
  s = bv.size
1043
1038
  t = cfr.size
1044
- wr = 1
1039
+ wr = Flt::DecNum(1)
1045
1040
  if r != s || r != t || s != t
1046
1041
  raise(FinrbError, 'Different number of values!')
1047
1042
  else
1048
1043
  (0...r).each do |i|
1049
1044
  wr *= (Finrb::Utils.hpr(ev: ev[i], bv: bv[i], cfr: cfr[i]) + 1)
1050
1045
  end
1051
- ((wr**(1.to_f / r)) - 1)
1046
+ ((wr**(Flt::DecNum(1) / r)) - 1)
1052
1047
  end
1053
1048
  end
1054
1049
 
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.8
4
+ version: 0.1.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nadir Cohen
@@ -65,6 +65,20 @@ 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'
68
82
  - !ruby/object:Gem::Dependency
69
83
  name: pry
70
84
  requirement: !ruby/object:Gem::Requirement