finrb 0.1.1 → 0.1.3

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: b999dd6faadf24d9020be497526bbf8a2614fbcc994232e84b8d2cc693eb283f
4
- data.tar.gz: 5611c3ab6cc8abc69e95fdb58e3d5913c1e47eaaf599f0aa097ba82f1377893b
3
+ metadata.gz: 9b5bd49e4cf559fb2444e5b02d9ef9cf07179f550654cb96d30c872dcb1e4afb
4
+ data.tar.gz: 6a9b8425cc3bb48eb699e666787530b213527a31123e6da47f8d4f0317e8f310
5
5
  SHA512:
6
- metadata.gz: a631f3777e169081228e91e08f94835780e479a63604828a89c649cf8ca0303d2ef2a9ad11de60376c14bc14d2652e700455523d232d45d4581ddb06b430e8c4
7
- data.tar.gz: 74d40ad091e7cc2756e58371ea53bf10ade3b5e6573be78813cfadfb90c67e54d7595bc57947d4b9f5b5b74fb9423dc835a10541144a65b9747c0017f6cb297f
6
+ metadata.gz: 8c381215b764feb8bd1f02742a0c53b271e93a325efd7d968a0a52284715127f73a545f050eb7d13554f8c5db1a52614d55b34e4e16a19ed960c703ef6b33f08
7
+ data.tar.gz: e5a06268ea08df5efe66fdba9e37b6c07f2a80f5b98caa82d1622351ba38fd975631bea65959cc286aaa1b16a965e49814e6662363c8094892baa903751de6f0
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # finrb changelog
2
2
 
3
+ ## 0.1.2
4
+
5
+ - refactoring
6
+
3
7
  ## 0.1.1
4
8
 
5
9
  - documentation additions and fixes
@@ -21,28 +21,28 @@ module Finrb
21
21
  # extra_payments = 250000.amortize(rate){ |period| period.payment - 150 }
22
22
  # @api public
23
23
  class Amortization
24
- # @return [DecNum] the balance of the loan at the end of the amortization period (usually zero)
24
+ # @return [Flt::DecNum] the balance of the loan at the end of the amortization period (usually zero)
25
25
  # @api public
26
26
  attr_reader :balance
27
- # @return [DecNum] the required monthly payment. For loans with more than one rate, returns nil
27
+ # @return [Flt::DecNum] the required monthly payment. For loans with more than one rate, returns nil
28
28
  # @api public
29
29
  attr_reader :payment
30
- # @return [DecNum] the principal amount of the loan
30
+ # @return [Flt::DecNum] the principal amount of the loan
31
31
  # @api public
32
32
  attr_reader :principal
33
33
  # @return [Array] the interest rates used for calculating the amortization
34
34
  # @api public
35
35
  attr_reader :rates
36
36
 
37
- # @return [DecNum] the periodic payment due on a loan
38
- # @param [DecNum] principal the initial amount of the loan or investment
37
+ # @return [Flt::DecNum] the periodic payment due on a loan
38
+ # @param [Flt::DecNum] principal the initial amount of the loan or investment
39
39
  # @param [Rate] rate the applicable interest rate (per period)
40
40
  # @param [Integer] periods the number of periods needed for repayment
41
41
  # @note in most cases, you will probably want to use rate.monthly when calling this function outside of an Amortization instance.
42
42
  # @example
43
43
  # rate = Rate.new(0.0375, :apr, :duration => (30 * 12))
44
44
  # rate.duration #=> 360
45
- # Amortization.payment(200000, rate.monthly, rate.duration) #=> DecNum('-926.23')
45
+ # Amortization.payment(200000, rate.monthly, rate.duration) #=> Flt::DecNum('-926.23')
46
46
  # @see https://en.wikipedia.org/wiki/Amortization_calculator
47
47
  # @api public
48
48
  def self.payment(principal, rate, periods)
@@ -56,7 +56,7 @@ module Finrb
56
56
 
57
57
  # create a new Amortization instance
58
58
  # @return [Amortization]
59
- # @param [DecNum] principal the initial amount of the loan or investment
59
+ # @param [Flt::DecNum] principal the initial amount of the loan or investment
60
60
  # @param [Rate] rates the applicable interest rates
61
61
  # @param [Proc] block
62
62
  # @api public
@@ -84,7 +84,7 @@ module Finrb
84
84
  # @example
85
85
  # rate = Rate.new(0.0375, :apr, :duration => (30 * 12))
86
86
  # amt = 300000.amortize(rate){ |payment| payment.amount-100}
87
- # amt.additional_payments #=> [DecNum('-100.00'), DecNum('-100.00'), ... ]
87
+ # amt.additional_payments #=> [Flt::DecNum('-100.00'), Flt::DecNum('-100.00'), ... ]
88
88
  # @api public
89
89
  def additional_payments
90
90
  @transactions.filter_map { |trans| trans.difference if trans.payment? }
@@ -135,7 +135,7 @@ module Finrb
135
135
  end
136
136
 
137
137
  # Add any remaining balance due to rounding error to the last payment.
138
- unless @balance.zero?
138
+ if @balance.nonzero?
139
139
  @transactions.reverse.find(&:payment?).amount -= @balance
140
140
  @balance = 0
141
141
  end
@@ -168,11 +168,11 @@ module Finrb
168
168
  # @example find the total cost of interest for a loan
169
169
  # rate = Rate.new(0.0375, :apr, :duration => (30 * 12))
170
170
  # amt = 300000.amortize(rate)
171
- # amt.interest.sum #=> DecNum('200163.94')
171
+ # amt.interest.sum #=> Flt::DecNum('200163.94')
172
172
  # @example find the total interest charges in the first six months
173
173
  # rate = Rate.new(0.0375, :apr, :duration => (30 * 12))
174
174
  # amt = 300000.amortize(rate)
175
- # amt.interest[0,6].sum #=> DecNum('5603.74')
175
+ # amt.interest[0,6].sum #=> Flt::DecNum('5603.74')
176
176
  # @api public
177
177
  def interest
178
178
  @transactions.filter_map { |trans| trans.amount if trans.interest? }
@@ -182,7 +182,7 @@ module Finrb
182
182
  # @example find the total payments for a loan
183
183
  # rate = Rate.new(0.0375, :apr, :duration => (30 * 12))
184
184
  # amt = 300000.amortize(rate)
185
- # amt.payments.sum #=> DecNum('-500163.94')
185
+ # amt.payments.sum #=> Flt::DecNum('-500163.94')
186
186
  # @api public
187
187
  def payments
188
188
  @transactions.filter_map { |trans| trans.amount if trans.payment? }
@@ -193,7 +193,7 @@ end
193
193
  class Numeric
194
194
  # @see Amortization#new
195
195
  # @api public
196
- def amortize(*rates, &block)
197
- Finrb::Amortization.new(self, *rates, &block)
196
+ def amortize(...)
197
+ Finrb::Amortization.new(self, ...)
198
198
  end
199
199
  end
@@ -7,9 +7,10 @@ require_relative 'rates'
7
7
  require 'bigdecimal'
8
8
  require 'bigdecimal/newton'
9
9
  require 'business_time'
10
- include Newton
11
10
 
12
11
  module Finrb
12
+ include Newton
13
+
13
14
  # Provides methods for working with cash flows (collections of transactions)
14
15
  # @api public
15
16
  module Cashflow
@@ -30,7 +31,7 @@ module Finrb
30
31
  end
31
32
 
32
33
  def values(x)
33
- value = @transactions.send(@function, Flt::DecNum.new(x[0].to_s))
34
+ value = @transactions.public_send(@function, Flt::DecNum.new(x[0].to_s))
34
35
  begin
35
36
  [BigDecimal(value.to_s)]
36
37
  rescue ArgumentError
@@ -40,7 +41,7 @@ module Finrb
40
41
  end
41
42
 
42
43
  # calculate the internal rate of return for a sequence of cash flows
43
- # @return [DecNum] the internal rate of return
44
+ # @return [Flt::DecNum] the internal rate of return
44
45
  # @param [Numeric] guess Initial guess rate, Defaults to 1.0
45
46
  # @example
46
47
  # [-4000,1200,1410,1875,1050].irr #=> 0.143
@@ -63,8 +64,12 @@ module Finrb
63
64
  super
64
65
  end
65
66
 
67
+ def respond_to_missing?(name, include_private = false)
68
+ name.to_s == 'sum' || super
69
+ end
70
+
66
71
  # calculate the net present value of a sequence of cash flows
67
- # @return [DecNum] the net present value
72
+ # @return [Flt::DecNum] the net present value
68
73
  # @param [Numeric] rate the discount rate to be applied
69
74
  # @example
70
75
  # [-100.0, 60, 60, 60].npv(0.1) #=> 49.211
@@ -109,7 +114,7 @@ module Finrb
109
114
  end
110
115
 
111
116
  # calculate the net present value of a sequence of cash flows
112
- # @return [DecNum]
117
+ # @return [Flt::DecNum]
113
118
  # @example
114
119
  # @transactions = []
115
120
  # @transactions << Transaction.new(-1000, :date => Time.new(1985,01,01))
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/decimal.rb CHANGED
@@ -2,22 +2,21 @@
2
2
 
3
3
  require 'flt'
4
4
  require 'rubygems'
5
- include Flt
6
5
 
7
- DecNum.context.define_conversion_from(BigDecimal) do |x, _context|
8
- DecNum(x.to_s)
6
+ Flt::DecNum.context.define_conversion_from(BigDecimal) do |x, _context|
7
+ Flt::DecNum(x.to_s)
9
8
  end
10
9
 
11
- DecNum.context.define_conversion_to(BigDecimal) do |x|
10
+ Flt::DecNum.context.define_conversion_to(BigDecimal) do |x|
12
11
  BigDecimal(x.to_s)
13
12
  end
14
13
 
15
14
  class Numeric
16
15
  def to_dec
17
- if instance_of?(DecNum)
16
+ if instance_of?(Flt::DecNum)
18
17
  self
19
18
  else
20
- DecNum(to_s)
19
+ Flt::DecNum(to_s)
21
20
  end
22
21
  end
23
22
  end
data/lib/finrb/rates.rb CHANGED
@@ -10,12 +10,14 @@ module Finrb
10
10
  include Comparable
11
11
  # Accepted rate types
12
12
  TYPES = { apr: 'effective', apy: 'effective', effective: 'effective', nominal: 'nominal' }.freeze
13
+ public_constant :TYPES
14
+
13
15
  # convert a nominal interest rate to an effective interest rate
14
- # @return [DecNum] the effective interest rate
16
+ # @return [Flt::DecNum] the effective interest rate
15
17
  # @param [Numeric] rate the nominal interest rate
16
18
  # @param [Numeric] periods the number of compounding periods per year
17
19
  # @example
18
- # Rate.to_effective(0.05, 4) #=> DecNum('0.05095')
20
+ # Rate.to_effective(0.05, 4) #=> Flt::DecNum('0.05095')
19
21
  # @api public
20
22
  def self.to_effective(rate, periods)
21
23
  rate = Flt::DecNum.new(rate.to_s)
@@ -29,11 +31,11 @@ module Finrb
29
31
  end
30
32
 
31
33
  # convert an effective interest rate to a nominal interest rate
32
- # @return [DecNum] the nominal interest rate
34
+ # @return [Flt::DecNum] the nominal interest rate
33
35
  # @param [Numeric] rate the effective interest rate
34
36
  # @param [Numeric] periods the number of compounding periods per year
35
37
  # @example
36
- # Rate.to_nominal(0.06, 365) #=> DecNum('0.05827')
38
+ # Rate.to_nominal(0.06, 365) #=> Flt::DecNum('0.05827')
37
39
  # @see https://www.miniwebtool.com/nominal-interest-rate-calculator/
38
40
  # @api public
39
41
  def self.to_nominal(rate, periods)
@@ -65,12 +67,12 @@ module Finrb
65
67
 
66
68
  # Set optional attributes..
67
69
  opts.each do |key, value|
68
- send("#{key}=", value)
70
+ __send__("#{key}=", value)
69
71
  end
70
72
 
71
73
  # Set the rate in the proper way, based on the value of type.
72
74
  begin
73
- send("#{TYPES.fetch(type)}=", Flt::DecNum.new(rate.to_s))
75
+ __send__("#{TYPES.fetch(type)}=", Flt::DecNum.new(rate.to_s))
74
76
  rescue KeyError
75
77
  raise(ArgumentError, "type must be one of #{TYPES.keys.join(', ')}", caller)
76
78
  end
@@ -79,10 +81,10 @@ module Finrb
79
81
  # @return [Integer] the duration for which the rate is valid, in months
80
82
  # @api public
81
83
  attr_accessor :duration
82
- # @return [DecNum] the effective interest rate
84
+ # @return [Flt::DecNum] the effective interest rate
83
85
  # @api public
84
86
  attr_reader :effective
85
- # @return [DecNum] the nominal interest rate
87
+ # @return [Flt::DecNum] the nominal interest rate
86
88
  # @api public
87
89
  attr_reader :nominal
88
90
 
@@ -131,7 +133,7 @@ module Finrb
131
133
 
132
134
  # set the effective interest rate
133
135
  # @return none
134
- # @param [DecNum] rate the effective interest rate
136
+ # @param [Flt::DecNum] rate the effective interest rate
135
137
  # @api private
136
138
  def effective=(rate)
137
139
  @effective = rate
@@ -142,11 +144,11 @@ module Finrb
142
144
  "Rate.new(#{apr.round(6)}, :apr)"
143
145
  end
144
146
 
145
- # @return [DecNum] the monthly effective interest rate
147
+ # @return [Flt::DecNum] the monthly effective interest rate
146
148
  # @example
147
149
  # rate = Rate.new(0.15, :nominal)
148
- # rate.apr.round(6) #=> DecNum('0.160755')
149
- # rate.monthly.round(6) #=> DecNum('0.013396')
150
+ # rate.apr.round(6) #=> Flt::DecNum('0.160755')
151
+ # rate.monthly.round(6) #=> Flt::DecNum('0.013396')
150
152
  # @api public
151
153
  def monthly
152
154
  (effective / 12).round(15)
@@ -154,7 +156,7 @@ module Finrb
154
156
 
155
157
  # set the nominal interest rate
156
158
  # @return none
157
- # @param [DecNum] rate the nominal interest rate
159
+ # @param [Flt::DecNum] rate the nominal interest rate
158
160
  # @api private
159
161
  def nominal=(rate)
160
162
  @nominal = rate
@@ -6,7 +6,7 @@ module Finrb
6
6
  # the Transaction class provides a general interface for working with individual cash flows.
7
7
  # @api public
8
8
  class Transaction
9
- # @return [DecNum] the cash value of the transaction
9
+ # @return [Flt::DecNum] the cash value of the transaction
10
10
  # @api public
11
11
  attr_reader :amount
12
12
  # @return [Integer] the period number of the transaction
@@ -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
 
@@ -49,12 +49,12 @@ module Finrb
49
49
  @amount = Flt::DecNum.new(value.to_s) || 0
50
50
  end
51
51
 
52
- # @return [DecNum] the difference between the original transaction
52
+ # @return [Flt::DecNum] the difference between the original transaction
53
53
  # amount and the current amount
54
54
  # @example
55
55
  # t = Transaction.new(500)
56
56
  # t.amount = 750
57
- # t.difference #=> DecNum('250')
57
+ # t.difference #=> Flt::DecNum('250')
58
58
  # @api public
59
59
  def difference
60
60
  @amount - @original
data/lib/finrb/utils.rb CHANGED
@@ -5,9 +5,9 @@ require_relative 'decimal'
5
5
  require 'bigdecimal'
6
6
  require 'bigdecimal/newton'
7
7
 
8
- include Newton
9
-
10
8
  module Finrb
9
+ include Newton
10
+
11
11
  class Utils
12
12
  class NlFunctionStub
13
13
  attr_accessor :func
@@ -33,9 +33,9 @@ module Finrb
33
33
  # @example
34
34
  # Finrb::Utils.bdy(d=1500,f=100000,t=120)
35
35
  def self.bdy(d:, f:, t:)
36
- d = DecNum(d.to_s)
37
- f = DecNum(f.to_s)
38
- t = DecNum(t.to_s)
36
+ d = Flt::DecNum(d.to_s)
37
+ f = Flt::DecNum(f.to_s)
38
+ t = Flt::DecNum(t.to_s)
39
39
 
40
40
  (d * 360 / f / t)
41
41
  end
@@ -47,8 +47,8 @@ module Finrb
47
47
  # @example
48
48
  # Finrb::Utils.bdy2mmy(bdy=0.045,t=120)
49
49
  def self.bdy2mmy(bdy:, t:)
50
- bdy = DecNum(bdy.to_s)
51
- t = DecNum(t.to_s)
50
+ bdy = Flt::DecNum(bdy.to_s)
51
+ t = Flt::DecNum(t.to_s)
52
52
 
53
53
  (bdy * 360 / (360 - (t * bdy)))
54
54
  end
@@ -61,9 +61,9 @@ module Finrb
61
61
  # @example
62
62
  # Finrb::Utils.cash_ratio(cash=3000,ms=2000,cl=2000)
63
63
  def self.cash_ratio(cash:, ms:, cl:)
64
- cash = DecNum(cash.to_s)
65
- ms = DecNum(ms.to_s)
66
- cl = DecNum(cl.to_s)
64
+ cash = Flt::DecNum(cash.to_s)
65
+ ms = Flt::DecNum(ms.to_s)
66
+ cl = Flt::DecNum(cl.to_s)
67
67
 
68
68
  ((cash + ms) / cl)
69
69
  end
@@ -75,8 +75,8 @@ module Finrb
75
75
  # @example
76
76
  # Finrb::Utils.coefficient_variation(sd=0.15,avg=0.39)
77
77
  def self.coefficient_variation(sd:, avg:)
78
- sd = DecNum(sd.to_s)
79
- avg = DecNum(avg.to_s)
78
+ sd = Flt::DecNum(sd.to_s)
79
+ avg = Flt::DecNum(avg.to_s)
80
80
 
81
81
  (sd / avg)
82
82
  end
@@ -98,11 +98,11 @@ module Finrb
98
98
  # @example
99
99
  # Finrb::Utils.cogs(uinv=2,pinv=2,units=[3,5],price=[3,5],sinv=7,method="WAC")
100
100
  def self.cogs(uinv:, pinv:, units:, price:, sinv:, method: 'FIFO')
101
- uinv = DecNum(uinv.to_s)
102
- pinv = DecNum(pinv.to_s)
103
- units = Array.wrap(units).map { |value| DecNum(value.to_s) }
104
- price = Array.wrap(price).map { |value| DecNum(value.to_s) }
105
- sinv = DecNum(sinv.to_s)
101
+ uinv = Flt::DecNum(uinv.to_s)
102
+ pinv = Flt::DecNum(pinv.to_s)
103
+ units = Array.wrap(units).map { |value| Flt::DecNum(value.to_s) }
104
+ price = Array.wrap(price).map { |value| Flt::DecNum(value.to_s) }
105
+ sinv = Flt::DecNum(sinv.to_s)
106
106
  method = method.to_s
107
107
 
108
108
  n = units.size
@@ -200,8 +200,8 @@ module Finrb
200
200
  # @example
201
201
  # Finrb::Utils.current_ratio(ca=8000,cl=2000)
202
202
  def self.current_ratio(ca:, cl:)
203
- ca = DecNum(ca.to_s)
204
- cl = DecNum(cl.to_s)
203
+ ca = Flt::DecNum(ca.to_s)
204
+ cl = Flt::DecNum(cl.to_s)
205
205
 
206
206
  (ca / cl)
207
207
  end
@@ -214,9 +214,9 @@ module Finrb
214
214
  # @example
215
215
  # Finrb::Utils.ddb(cost=1200,rv=200,t=5)
216
216
  def self.ddb(cost:, rv:, t:)
217
- cost = DecNum(cost.to_s)
218
- rv = DecNum(rv.to_s)
219
- t = DecNum(t.to_s)
217
+ cost = Flt::DecNum(cost.to_s)
218
+ rv = Flt::DecNum(rv.to_s)
219
+ t = Flt::DecNum(t.to_s)
220
220
 
221
221
  raise(FinrbError, 't should be larger than 1') if t < 2
222
222
 
@@ -246,8 +246,8 @@ module Finrb
246
246
  # @example
247
247
  # Finrb::Utils.debt_ratio(td=6000,ta=20000)
248
248
  def self.debt_ratio(td:, ta:)
249
- td = DecNum(td.to_s)
250
- ta = DecNum(ta.to_s)
249
+ td = Flt::DecNum(td.to_s)
250
+ ta = Flt::DecNum(ta.to_s)
251
251
 
252
252
  (td / ta)
253
253
  end
@@ -275,15 +275,15 @@ module Finrb
275
275
  # @example
276
276
  # Finrb::Utils.diluted_eps(ni=115600,pd=10000,cpd=10000,cdi=42000,tax=0.4,w=200000,cps=40000,cds=60000,iss=2500)
277
277
  def self.diluted_eps(ni:, pd:, w:, cpd: 0, cdi: 0, tax: 0, cps: 0, cds: 0, iss: 0)
278
- ni = DecNum(ni.to_s)
279
- pd = DecNum(pd.to_s)
280
- w = DecNum(w.to_s)
281
- cpd = DecNum(cpd.to_s)
282
- cdi = DecNum(cdi.to_s)
283
- tax = DecNum(tax.to_s)
284
- cps = DecNum(cps.to_s)
285
- cds = DecNum(cds.to_s)
286
- iss = DecNum(iss.to_s)
278
+ ni = Flt::DecNum(ni.to_s)
279
+ pd = Flt::DecNum(pd.to_s)
280
+ w = Flt::DecNum(w.to_s)
281
+ cpd = Flt::DecNum(cpd.to_s)
282
+ cdi = Flt::DecNum(cdi.to_s)
283
+ tax = Flt::DecNum(tax.to_s)
284
+ cps = Flt::DecNum(cps.to_s)
285
+ cds = Flt::DecNum(cds.to_s)
286
+ iss = Flt::DecNum(iss.to_s)
287
287
 
288
288
  basic = (ni - pd) / w
289
289
  diluted = (ni - pd + cpd + (cdi * (1 - tax))) / (w + cps + cds + iss)
@@ -303,13 +303,13 @@ module Finrb
303
303
  # @example
304
304
  # Finrb::Utils.discount_rate(n=5,pv=0,fv=600,pmt=-100,type=0)
305
305
  def self.discount_rate(n:, pv:, fv:, pmt:, type: 0, lower: 0.0001, upper: 100)
306
- n = DecNum(n.to_s)
307
- pv = DecNum(pv.to_s)
308
- fv = DecNum(fv.to_s)
309
- pmt = DecNum(pmt.to_s)
310
- type = DecNum(type.to_s)
311
- lower = DecNum(lower.to_s)
312
- upper = DecNum(upper.to_s)
306
+ n = Flt::DecNum(n.to_s)
307
+ pv = Flt::DecNum(pv.to_s)
308
+ fv = Flt::DecNum(fv.to_s)
309
+ pmt = Flt::DecNum(pmt.to_s)
310
+ type = Flt::DecNum(type.to_s)
311
+ lower = Flt::DecNum(lower.to_s)
312
+ upper = Flt::DecNum(upper.to_s)
313
313
 
314
314
  nlfunc = NlFunctionStub.new
315
315
  nlfunc.func =
@@ -332,8 +332,8 @@ module Finrb
332
332
  # @example
333
333
  # Finrb::Utils.ear(0.04,365)
334
334
  def self.ear(r:, m:)
335
- r = DecNum(r.to_s)
336
- m = DecNum(m.to_s)
335
+ r = Flt::DecNum(r.to_s)
336
+ m = Flt::DecNum(m.to_s)
337
337
 
338
338
  ((((r / m) + 1)**m) - 1)
339
339
  end
@@ -347,7 +347,7 @@ module Finrb
347
347
  # @example
348
348
  # Finrb::Utils.ear_continuous(0.03)
349
349
  def self.ear_continuous(r:)
350
- r = DecNum(r.to_s)
350
+ r = Flt::DecNum(r.to_s)
351
351
 
352
352
  (r.to_dec.exp - 1)
353
353
  end
@@ -358,7 +358,7 @@ module Finrb
358
358
  # @example
359
359
  # Finrb::Utils.ear2bey(ear=0.08)
360
360
  def self.ear2bey(ear:)
361
- ear = DecNum(ear.to_s)
361
+ ear = Flt::DecNum(ear.to_s)
362
362
 
363
363
  ((((ear + 1)**0.5) - 1) * 2)
364
364
  end
@@ -370,8 +370,8 @@ module Finrb
370
370
  # @example
371
371
  # Finrb::Utils.ear2hpr(ear=0.05039,t=150)
372
372
  def self.ear2hpr(ear:, t:)
373
- ear = DecNum(ear.to_s)
374
- t = DecNum(t.to_s)
373
+ ear = Flt::DecNum(ear.to_s)
374
+ t = Flt::DecNum(t.to_s)
375
375
 
376
376
  (((ear + 1)**(t / 365)) - 1)
377
377
  end
@@ -412,9 +412,9 @@ module Finrb
412
412
  # # monthly proportional interest rate which is equivalent to a simple annual interest
413
413
  # Finrb::Utils.eir(r=0.05,p=12,type='p')
414
414
  def self.eir(r:, n: 1, p: 12, type: 'e')
415
- r = DecNum(r.to_s)
416
- n = DecNum(n.to_s)
417
- p = DecNum(p.to_s)
415
+ r = Flt::DecNum(r.to_s)
416
+ n = Flt::DecNum(n.to_s)
417
+ p = Flt::DecNum(p.to_s)
418
418
  type = type.to_s
419
419
 
420
420
  case type
@@ -436,9 +436,9 @@ module Finrb
436
436
  # @example
437
437
  # Finrb::Utils.eps(ni=10000,pd=1000,w=11000)
438
438
  def self.eps(ni:, pd:, w:)
439
- ni = DecNum(ni.to_s)
440
- pd = DecNum(pd.to_s)
441
- w = DecNum(w.to_s)
439
+ ni = Flt::DecNum(ni.to_s)
440
+ pd = Flt::DecNum(pd.to_s)
441
+ w = Flt::DecNum(w.to_s)
442
442
 
443
443
  ((ni - pd) / w)
444
444
  end
@@ -450,8 +450,8 @@ module Finrb
450
450
  # @example
451
451
  # Finrb::Utils.financial_leverage(te=16000,ta=20000)
452
452
  def self.financial_leverage(te:, ta:)
453
- te = DecNum(te.to_s)
454
- ta = DecNum(ta.to_s)
453
+ te = Flt::DecNum(te.to_s)
454
+ ta = Flt::DecNum(ta.to_s)
455
455
 
456
456
  (ta / te)
457
457
  end
@@ -466,11 +466,11 @@ module Finrb
466
466
  # @example
467
467
  # Finrb::Utils.fv(r=0.07,n=10,pv=1000,pmt=10)
468
468
  def self.fv(r:, n:, pv: 0, pmt: 0, type: 0)
469
- r = DecNum(r.to_s)
470
- n = DecNum(n.to_s)
471
- pv = DecNum(pv.to_s)
472
- pmt = DecNum(pmt.to_s)
473
- type = DecNum(type.to_s)
469
+ r = Flt::DecNum(r.to_s)
470
+ n = Flt::DecNum(n.to_s)
471
+ pv = Flt::DecNum(pv.to_s)
472
+ pmt = Flt::DecNum(pmt.to_s)
473
+ type = Flt::DecNum(type.to_s)
474
474
 
475
475
  if type != 0 && type != 1
476
476
  raise(FinrbError, 'Error: type should be 0 or 1!')
@@ -491,10 +491,10 @@ module Finrb
491
491
  # @example
492
492
  # Finrb::Utils.fv_annuity(r=0.03,n=12,pmt=-1000,type=1)
493
493
  def self.fv_annuity(r:, n:, pmt:, type: 0)
494
- r = DecNum(r.to_s)
495
- n = DecNum(n.to_s)
496
- pmt = DecNum(pmt.to_s)
497
- type = DecNum(type.to_s)
494
+ r = Flt::DecNum(r.to_s)
495
+ n = Flt::DecNum(n.to_s)
496
+ pmt = Flt::DecNum(pmt.to_s)
497
+ type = Flt::DecNum(type.to_s)
498
498
 
499
499
  if type != 0 && type != 1
500
500
  raise(FinrbError, 'Error: type should be 0 or 1!')
@@ -515,9 +515,9 @@ module Finrb
515
515
  # @example
516
516
  # Finrb::Utils.fv_simple(r=0.04,n=20,pv=-50000)
517
517
  def self.fv_simple(r:, n:, pv:)
518
- r = DecNum(r.to_s)
519
- n = DecNum(n.to_s)
520
- pv = DecNum(pv.to_s)
518
+ r = Flt::DecNum(r.to_s)
519
+ n = Flt::DecNum(n.to_s)
520
+ pv = Flt::DecNum(pv.to_s)
521
521
 
522
522
  ((pv * ((r + 1)**n)) * -1)
523
523
  end
@@ -529,8 +529,8 @@ module Finrb
529
529
  # @example
530
530
  # Finrb::Utils.fv_uneven(r=0.1, cf=[-1000, -500, 0, 4000, 3500, 2000])
531
531
  def self.fv_uneven(r:, cf:)
532
- r = DecNum(r.to_s)
533
- cf = Array.wrap(cf).map { |value| DecNum(value.to_s) }
532
+ r = Flt::DecNum(r.to_s)
533
+ cf = Array.wrap(cf).map { |value| Flt::DecNum(value.to_s) }
534
534
 
535
535
  m = cf.size
536
536
  sum = 0
@@ -547,7 +547,7 @@ module Finrb
547
547
  # @example
548
548
  # Finrb::Utils.geometric_mean(r=[-0.0934, 0.2345, 0.0892])
549
549
  def self.geometric_mean(r:)
550
- r = Array.wrap(r).map { |value| DecNum(value.to_s) }
550
+ r = Array.wrap(r).map { |value| Flt::DecNum(value.to_s) }
551
551
 
552
552
  rs = r.map { |value| value + 1 }
553
553
  ((rs.reduce(:*)**(1.to_f / rs.size)) - 1)
@@ -560,8 +560,8 @@ module Finrb
560
560
  # @example
561
561
  # Finrb::Utils.gpm(gp=1000,rv=20000)
562
562
  def self.gpm(gp:, rv:)
563
- gp = DecNum(gp.to_s)
564
- rv = DecNum(rv.to_s)
563
+ gp = Flt::DecNum(gp.to_s)
564
+ rv = Flt::DecNum(rv.to_s)
565
565
 
566
566
  (gp / rv)
567
567
  end
@@ -571,7 +571,7 @@ module Finrb
571
571
  # @example
572
572
  # Finrb::Utils.harmonic_mean(p=[8,9,10])
573
573
  def self.harmonic_mean(p:)
574
- p = Array.wrap(p).map { |value| DecNum(value.to_s) }
574
+ p = Array.wrap(p).map { |value| Flt::DecNum(value.to_s) }
575
575
 
576
576
  (1.to_f / (p.sum { |val| 1.to_f / val } / p.size))
577
577
  end
@@ -584,9 +584,9 @@ module Finrb
584
584
  # @example
585
585
  # Finrb::Utils.hpr(ev=33,bv=30,cfr=0.5)
586
586
  def self.hpr(ev:, bv:, cfr: 0)
587
- ev = DecNum(ev.to_s)
588
- bv = DecNum(bv.to_s)
589
- cfr = DecNum(cfr.to_s)
587
+ ev = Flt::DecNum(ev.to_s)
588
+ bv = Flt::DecNum(bv.to_s)
589
+ cfr = Flt::DecNum(cfr.to_s)
590
590
 
591
591
  ((ev - bv + cfr) / bv)
592
592
  end
@@ -598,8 +598,8 @@ module Finrb
598
598
  # @example
599
599
  # Finrb::Utils.hpr2bey(hpr=0.02,t=3)
600
600
  def self.hpr2bey(hpr:, t:)
601
- hpr = DecNum(hpr.to_s)
602
- t = DecNum(t.to_s)
601
+ hpr = Flt::DecNum(hpr.to_s)
602
+ t = Flt::DecNum(t.to_s)
603
603
 
604
604
  ((((hpr + 1)**(6 / t)) - 1) * 2)
605
605
  end
@@ -611,8 +611,8 @@ module Finrb
611
611
  # @example
612
612
  # Finrb::Utils.hpr2ear(hpr=0.015228,t=120)
613
613
  def self.hpr2ear(hpr:, t:)
614
- hpr = DecNum(hpr.to_s)
615
- t = DecNum(t.to_s)
614
+ hpr = Flt::DecNum(hpr.to_s)
615
+ t = Flt::DecNum(t.to_s)
616
616
 
617
617
  (((hpr + 1)**(365 / t)) - 1)
618
618
  end
@@ -624,8 +624,8 @@ module Finrb
624
624
  # @example
625
625
  # Finrb::Utils.hpr2mmy(hpr=0.01523,t=120)
626
626
  def self.hpr2mmy(hpr:, t:)
627
- hpr = DecNum(hpr.to_s)
628
- t = DecNum(t.to_s)
627
+ hpr = Flt::DecNum(hpr.to_s)
628
+ t = Flt::DecNum(t.to_s)
629
629
 
630
630
  (hpr * 360 / t)
631
631
  end
@@ -636,7 +636,7 @@ module Finrb
636
636
  # @example
637
637
  # Finrb::Utils.irr(cf=[-5, 1.6, 2.4, 2.8])
638
638
  def self.irr(cf:)
639
- cf = Array.wrap(cf).map { |value| DecNum(value.to_s) }
639
+ cf = Array.wrap(cf).map { |value| Flt::DecNum(value.to_s) }
640
640
 
641
641
  subcf = cf.drop(1)
642
642
  nlfunc = NlFunctionStub.new
@@ -658,9 +658,9 @@ module Finrb
658
658
  # @example
659
659
  # Finrb::Utils.iss(amp=20,ep=15,n=10000)
660
660
  def self.iss(amp:, ep:, n:)
661
- amp = DecNum(amp.to_s)
662
- ep = DecNum(ep.to_s)
663
- n = DecNum(n.to_s)
661
+ amp = Flt::DecNum(amp.to_s)
662
+ ep = Flt::DecNum(ep.to_s)
663
+ n = Flt::DecNum(n.to_s)
664
664
 
665
665
  if amp > ep
666
666
  ((amp - ep) * n / amp)
@@ -676,8 +676,8 @@ module Finrb
676
676
  # @example
677
677
  # Finrb::Utils.lt_d2e(ltd=8000,te=20000)
678
678
  def self.lt_d2e(ltd:, te:)
679
- ltd = DecNum(ltd.to_s)
680
- te = DecNum(te.to_s)
679
+ ltd = Flt::DecNum(ltd.to_s)
680
+ te = Flt::DecNum(te.to_s)
681
681
 
682
682
  (ltd / te)
683
683
  end
@@ -689,8 +689,8 @@ module Finrb
689
689
  # @example
690
690
  # Finrb::Utils.mmy2hpr(mmy=0.04898,t=150)
691
691
  def self.mmy2hpr(mmy:, t:)
692
- mmy = DecNum(mmy.to_s)
693
- t = DecNum(t.to_s)
692
+ mmy = Flt::DecNum(mmy.to_s)
693
+ t = Flt::DecNum(t.to_s)
694
694
 
695
695
  (mmy * t / 360)
696
696
  end
@@ -708,11 +708,11 @@ module Finrb
708
708
  # @example
709
709
  # Finrb::Utils.n_period(r=0.1,pv=-10000,fv=60000000,pmt=-50000,type=1)
710
710
  def self.n_period(r:, pv:, fv:, pmt:, type: 0)
711
- r = DecNum(r.to_s)
712
- pv = DecNum(pv.to_s)
713
- fv = DecNum(fv.to_s)
714
- pmt = DecNum(pmt.to_s)
715
- type = DecNum(type.to_s)
711
+ r = Flt::DecNum(r.to_s)
712
+ pv = Flt::DecNum(pv.to_s)
713
+ fv = Flt::DecNum(fv.to_s)
714
+ pmt = Flt::DecNum(pmt.to_s)
715
+ type = Flt::DecNum(type.to_s)
716
716
 
717
717
  if type != 0 && type != 1
718
718
  raise(FinrbError, 'Error: type should be 0 or 1!')
@@ -729,8 +729,8 @@ module Finrb
729
729
  # @example
730
730
  # Finrb::Utils.npm(ni=8000,rv=20000)
731
731
  def self.npm(ni:, rv:)
732
- ni = DecNum(ni.to_s)
733
- rv = DecNum(rv.to_s)
732
+ ni = Flt::DecNum(ni.to_s)
733
+ rv = Flt::DecNum(rv.to_s)
734
734
 
735
735
  (ni / rv)
736
736
  end
@@ -742,8 +742,8 @@ module Finrb
742
742
  # @example
743
743
  # Finrb::Utils.npv(r=0.12, cf=[-5, 1.6, 2.4, 2.8])
744
744
  def self.npv(r:, cf:)
745
- r = DecNum(r.to_s)
746
- cf = Array.wrap(cf).map { |value| DecNum(value.to_s) }
745
+ r = Flt::DecNum(r.to_s)
746
+ cf = Array.wrap(cf).map { |value| Flt::DecNum(value.to_s) }
747
747
 
748
748
  subcf = cf.drop(1)
749
749
  ((Finrb::Utils.pv_uneven(r: r, cf: subcf) * -1) + cf[0])
@@ -765,11 +765,11 @@ module Finrb
765
765
  # @example
766
766
  # Finrb::Utils.pmt(0.08,10,-1000,10,1)
767
767
  def self.pmt(r:, n:, pv:, fv:, type: 0)
768
- r = DecNum(r.to_s)
769
- n = DecNum(n.to_s)
770
- pv = DecNum(pv.to_s)
771
- fv = DecNum(fv.to_s)
772
- type = DecNum(type.to_s)
768
+ r = Flt::DecNum(r.to_s)
769
+ n = Flt::DecNum(n.to_s)
770
+ pv = Flt::DecNum(pv.to_s)
771
+ fv = Flt::DecNum(fv.to_s)
772
+ type = Flt::DecNum(type.to_s)
773
773
 
774
774
  if type != 0 && type != 1
775
775
  raise(FinrbError, 'Error: type should be 0 or 1!')
@@ -791,11 +791,11 @@ module Finrb
791
791
  # @example
792
792
  # Finrb::Utils.pv(r=0.05,n=20,fv=1000,pmt=10,type=1)
793
793
  def self.pv(r:, n:, fv: 0, pmt: 0, type: 0)
794
- r = DecNum(r.to_s)
795
- n = DecNum(n.to_s)
796
- fv = DecNum(fv.to_s)
797
- pmt = DecNum(pmt.to_s)
798
- type = DecNum(type.to_s)
794
+ r = Flt::DecNum(r.to_s)
795
+ n = Flt::DecNum(n.to_s)
796
+ fv = Flt::DecNum(fv.to_s)
797
+ pmt = Flt::DecNum(pmt.to_s)
798
+ type = Flt::DecNum(type.to_s)
799
799
 
800
800
  if type != 0 && type != 1
801
801
  raise(FinrbError, 'Error: type should be 0 or 1!')
@@ -817,10 +817,10 @@ module Finrb
817
817
  # @example
818
818
  # Finrb::Utils.pv_annuity(r=0.0425,n=3,pmt=30000)
819
819
  def self.pv_annuity(r:, n:, pmt:, type: 0)
820
- r = DecNum(r.to_s)
821
- n = DecNum(n.to_s)
822
- pmt = DecNum(pmt.to_s)
823
- type = DecNum(type.to_s)
820
+ r = Flt::DecNum(r.to_s)
821
+ n = Flt::DecNum(n.to_s)
822
+ pmt = Flt::DecNum(pmt.to_s)
823
+ type = Flt::DecNum(type.to_s)
824
824
 
825
825
  if type != 0 && type != 1
826
826
  raise(FinrbError, 'Error: type should be 0 or 1!')
@@ -845,10 +845,10 @@ module Finrb
845
845
  # @example
846
846
  # Finrb::Utils.pv_perpetuity(r=0.1,pmt=1000)
847
847
  def self.pv_perpetuity(r:, pmt:, g: 0, type: 0)
848
- r = DecNum(r.to_s)
849
- pmt = DecNum(pmt.to_s)
850
- g = DecNum(g.to_s)
851
- type = DecNum(type.to_s)
848
+ r = Flt::DecNum(r.to_s)
849
+ pmt = Flt::DecNum(pmt.to_s)
850
+ g = Flt::DecNum(g.to_s)
851
+ type = Flt::DecNum(type.to_s)
852
852
 
853
853
  if type != 0 && type != 1
854
854
  raise(FinrbError, 'Error: type should be 0 or 1!')
@@ -871,9 +871,9 @@ module Finrb
871
871
  # @example
872
872
  # Finrb::Utils.pv_simple(r=0.03,n=3,fv=1000)
873
873
  def self.pv_simple(r:, n:, fv:)
874
- r = DecNum(r.to_s)
875
- n = DecNum(n.to_s)
876
- fv = DecNum(fv.to_s)
874
+ r = Flt::DecNum(r.to_s)
875
+ n = Flt::DecNum(n.to_s)
876
+ fv = Flt::DecNum(fv.to_s)
877
877
 
878
878
  ((fv / ((r + 1)**n)) * -1)
879
879
  end
@@ -885,8 +885,8 @@ module Finrb
885
885
  # @example
886
886
  # Finrb::Utils.pv_uneven(r=0.1, cf=[-1000, -500, 0, 4000, 3500, 2000])
887
887
  def self.pv_uneven(r:, cf:)
888
- r = DecNum(r.to_s)
889
- cf = Array.wrap(cf).map { |value| DecNum(value.to_s) }
888
+ r = Flt::DecNum(r.to_s)
889
+ cf = Array.wrap(cf).map { |value| Flt::DecNum(value.to_s) }
890
890
 
891
891
  n = cf.size
892
892
  sum = 0
@@ -905,10 +905,10 @@ module Finrb
905
905
  # @example
906
906
  # Finrb::Utils.quick_ratio(cash=3000,ms=2000,rc=1000,cl=2000)
907
907
  def self.quick_ratio(cash:, ms:, rc:, cl:)
908
- cash = DecNum(cash.to_s)
909
- ms = DecNum(ms.to_s)
910
- rc = DecNum(rc.to_s)
911
- cl = DecNum(cl.to_s)
908
+ cash = Flt::DecNum(cash.to_s)
909
+ ms = Flt::DecNum(ms.to_s)
910
+ rc = Flt::DecNum(rc.to_s)
911
+ cl = Flt::DecNum(cl.to_s)
912
912
 
913
913
  ((cash + ms + rc) / cl)
914
914
  end
@@ -920,8 +920,8 @@ module Finrb
920
920
  # @example
921
921
  # Finrb::Utils.r_continuous(r=0.03,m=4)
922
922
  def self.r_continuous(r:, m:)
923
- r = DecNum(r.to_s)
924
- m = DecNum(m.to_s)
923
+ r = Flt::DecNum(r.to_s)
924
+ m = Flt::DecNum(m.to_s)
925
925
 
926
926
  (m * ((r / m) + 1).to_dec.log)
927
927
  end
@@ -936,8 +936,8 @@ module Finrb
936
936
  # @example
937
937
  # Finrb::Utils.r_norminal(rc=0.03,m=4)
938
938
  def self.r_norminal(rc:, m:)
939
- rc = DecNum(rc.to_s)
940
- m = DecNum(m.to_s)
939
+ rc = Flt::DecNum(rc.to_s)
940
+ m = Flt::DecNum(m.to_s)
941
941
 
942
942
  (m * ((rc / m).to_dec.exp - 1))
943
943
  end
@@ -949,8 +949,8 @@ module Finrb
949
949
  # @example
950
950
  # Finrb::Utils.r_perpetuity(pmt=4.5,pv=-75)
951
951
  def self.r_perpetuity(pmt:, pv:)
952
- pmt = DecNum(pmt.to_s)
953
- pv = DecNum(pv.to_s)
952
+ pmt = Flt::DecNum(pmt.to_s)
953
+ pv = Flt::DecNum(pv.to_s)
954
954
 
955
955
  (pmt * -1 / pv)
956
956
  end
@@ -962,8 +962,8 @@ module Finrb
962
962
  # @example
963
963
  # Finrb::Utils.sampling_error(sm=0.45, mu=0.5)
964
964
  def self.sampling_error(sm:, mu:)
965
- sm = DecNum(sm.to_s)
966
- mu = DecNum(mu.to_s)
965
+ sm = Flt::DecNum(sm.to_s)
966
+ mu = Flt::DecNum(mu.to_s)
967
967
 
968
968
  (sm - mu)
969
969
  end
@@ -976,9 +976,9 @@ module Finrb
976
976
  # @example
977
977
  # Finrb::Utils.sf_ratio(rp=0.09,rl=0.03,sd=0.12)
978
978
  def self.sf_ratio(rp:, rl:, sd:)
979
- rp = DecNum(rp.to_s)
980
- rl = DecNum(rl.to_s)
981
- sd = DecNum(sd.to_s)
979
+ rp = Flt::DecNum(rp.to_s)
980
+ rl = Flt::DecNum(rl.to_s)
981
+ sd = Flt::DecNum(sd.to_s)
982
982
 
983
983
  ((rp - rl) / sd)
984
984
  end
@@ -991,9 +991,9 @@ module Finrb
991
991
  # @example
992
992
  # Finrb::Utils.sharpe_ratio(rp=0.038,rf=0.015,sd=0.07)
993
993
  def self.sharpe_ratio(rp:, rf:, sd:)
994
- rp = DecNum(rp.to_s)
995
- rf = DecNum(rf.to_s)
996
- sd = DecNum(sd.to_s)
994
+ rp = Flt::DecNum(rp.to_s)
995
+ rf = Flt::DecNum(rf.to_s)
996
+ sd = Flt::DecNum(sd.to_s)
997
997
 
998
998
  ((rp - rf) / sd)
999
999
  end
@@ -1006,9 +1006,9 @@ module Finrb
1006
1006
  # @example
1007
1007
  # Finrb::Utils.slde(cost=1200,rv=200,t=5)
1008
1008
  def self.slde(cost:, rv:, t:)
1009
- cost = DecNum(cost.to_s)
1010
- rv = DecNum(rv.to_s)
1011
- t = DecNum(t.to_s)
1009
+ cost = Flt::DecNum(cost.to_s)
1010
+ rv = Flt::DecNum(rv.to_s)
1011
+ t = Flt::DecNum(t.to_s)
1012
1012
 
1013
1013
  ((cost - rv) / t)
1014
1014
  end
@@ -1020,8 +1020,8 @@ module Finrb
1020
1020
  # @example
1021
1021
  # Finrb::Utils.total_d2e(td=6000,te=20000)
1022
1022
  def self.total_d2e(td:, te:)
1023
- td = DecNum(td.to_s)
1024
- te = DecNum(te.to_s)
1023
+ td = Flt::DecNum(td.to_s)
1024
+ te = Flt::DecNum(te.to_s)
1025
1025
 
1026
1026
  (td / te)
1027
1027
  end
@@ -1034,9 +1034,9 @@ module Finrb
1034
1034
  # @example
1035
1035
  # Finrb::Utils.twrr(ev=[120,260],bv=[100,240],cfr=[2,4])
1036
1036
  def self.twrr(ev:, bv:, cfr:)
1037
- ev = Array.wrap(ev).map { |value| DecNum(value.to_s) }
1038
- bv = Array.wrap(bv).map { |value| DecNum(value.to_s) }
1039
- cfr = Array.wrap(cfr).map { |value| DecNum(value.to_s) }
1037
+ ev = Array.wrap(ev).map { |value| Flt::DecNum(value.to_s) }
1038
+ bv = Array.wrap(bv).map { |value| Flt::DecNum(value.to_s) }
1039
+ cfr = Array.wrap(cfr).map { |value| Flt::DecNum(value.to_s) }
1040
1040
 
1041
1041
  r = ev.size
1042
1042
  s = bv.size
@@ -1062,8 +1062,8 @@ module Finrb
1062
1062
  # @example
1063
1063
  # s=[11000,4400,-3000];m=[12,9,4];Finrb::Utils.was(ns=s,nm=m)
1064
1064
  def self.was(ns:, nm:)
1065
- ns = Array.wrap(ns).map { |value| DecNum(value.to_s) }
1066
- nm = Array.wrap(nm).map { |value| DecNum(value.to_s) }
1065
+ ns = Array.wrap(ns).map { |value| Flt::DecNum(value.to_s) }
1066
+ nm = Array.wrap(nm).map { |value| Flt::DecNum(value.to_s) }
1067
1067
 
1068
1068
  m = ns.size
1069
1069
  n = nm.size
@@ -1086,12 +1086,12 @@ module Finrb
1086
1086
  # @example
1087
1087
  # Finrb::Utils.wpr(r=[0.12, 0.07, 0.03],w=[0.5,0.4,0.1])
1088
1088
  def self.wpr(r:, w:)
1089
- r = Array.wrap(r).map { |value| DecNum(value.to_s) }
1090
- w = Array.wrap(w).map { |value| DecNum(value.to_s) }
1089
+ r = Array.wrap(r).map { |value| Flt::DecNum(value.to_s) }
1090
+ w = Array.wrap(w).map { |value| Flt::DecNum(value.to_s) }
1091
+
1092
+ # TODO: need to change
1093
+ puts('sum of weights is NOT equal to 1!') if w.sum != 1
1091
1094
 
1092
- if w.sum != 1
1093
- puts('sum of weights is NOT equal to 1!') # TODO: need to change
1094
- end
1095
1095
  r.zip(w).sum { |arr| arr.reduce(:*) }
1096
1096
  end
1097
1097
  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.1
4
+ version: 0.1.3
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-01-21 00:00:00.000000000 Z
11
+ date: 2023-10-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -237,7 +237,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
237
237
  - !ruby/object:Gem::Version
238
238
  version: '0'
239
239
  requirements: []
240
- rubygems_version: 3.4.1
240
+ rubygems_version: 3.4.21
241
241
  signing_key:
242
242
  specification_version: 4
243
243
  summary: Ruby gem for financial calculations/modeling