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 +4 -4
- data/CHANGELOG.md +5 -0
- data/lib/finrb/amortization.rb +1 -1
- data/lib/finrb/cashflows.rb +8 -8
- data/lib/finrb/config.rb +1 -1
- data/lib/finrb/rates.rb +2 -2
- data/lib/finrb/transaction.rb +1 -1
- data/lib/finrb/utils.rb +14 -14
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e895ab637979af1754b20e1c661adfcaafaadda5537628a3df5ea15dc5fe79fc
|
4
|
+
data.tar.gz: 68a533652b9864f327be58882817926b7abff6ebc25787dc53508bc59db4720c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a845b6f3b83b733a5d881f1374f31d56a2719d1efc85d9ca7b76e3bbf31668bf576e3fc8e1a444a601efd42184f6cf95d015da60c1367a2a7c30d8580848875c
|
7
|
+
data.tar.gz: 90c2dd4e4af0e74a120498950a9b8111d31ab0d159bb35588e54353345e9216651e88ff257cddb3a09bc294e344fba66e006be81df9deadf6819e52688058ee8
|
data/CHANGELOG.md
CHANGED
data/lib/finrb/amortization.rb
CHANGED
data/lib/finrb/cashflows.rb
CHANGED
@@ -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
|
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
|
58
|
+
rate.first
|
59
59
|
end
|
60
60
|
|
61
|
-
def method_missing(name, *args, &
|
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
|
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 ||=
|
152
|
+
@start ||= first.date
|
153
153
|
end
|
154
154
|
|
155
155
|
def stop
|
156
|
-
@stop ||=
|
156
|
+
@stop ||= last.date.to_date
|
157
157
|
end
|
158
158
|
|
159
159
|
def valid(guess)
|
data/lib/finrb/config.rb
CHANGED
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
|
data/lib/finrb/transaction.rb
CHANGED
data/lib/finrb/utils.rb
CHANGED
@@ -188,8 +188,8 @@ module Finrb
|
|
188
188
|
end
|
189
189
|
|
190
190
|
{
|
191
|
-
cost_of_goods
|
192
|
-
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
|
225
|
+
if cost - ddb.first <= rv
|
226
226
|
ddb[0] = cost - rv
|
227
227
|
else
|
228
|
-
cost -= ddb
|
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:
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
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.
|
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:
|
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.
|
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.
|
240
|
+
rubygems_version: 3.5.7
|
241
241
|
signing_key:
|
242
242
|
specification_version: 4
|
243
243
|
summary: Ruby gem for financial calculations/modeling
|