finrb 0.0.1 → 0.1.0
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/.github/dependabot.yml +7 -0
- data/.github/issue_template.md +15 -0
- data/.github/pull_request_template.md +17 -0
- data/.github/workflows/ci.yml +21 -0
- data/.github/workflows/codeql.yml +72 -0
- data/.github/workflows/rubocop.yml +24 -0
- data/.rubocop.yml +270 -5
- data/.semver +2 -2
- data/CHANGELOG.md +35 -26
- data/Gemfile +1 -1
- data/Gemfile.lock +5 -2
- data/README.md +5 -1
- data/Rakefile +10 -10
- data/docs/api.md +238 -256
- data/finrb.gemspec +24 -80
- data/lib/finrb/amortization.rb +7 -7
- data/lib/finrb/cashflows.rb +40 -41
- data/lib/finrb/config.rb +1 -1
- data/lib/finrb/decimal.rb +2 -2
- data/lib/finrb/rates.rb +5 -5
- data/lib/finrb/transaction.rb +1 -1
- data/lib/finrb/utils.rb +78 -77
- data/lib/finrb.rb +9 -9
- metadata +25 -63
- data/.travis.yml +0 -7
data/lib/finrb/utils.rb
CHANGED
@@ -33,7 +33,7 @@ module Finrb
|
|
33
33
|
# @export
|
34
34
|
# @examples
|
35
35
|
# bdy(d=1500,f=100000,t=120)
|
36
|
-
def self.bdy(d
|
36
|
+
def self.bdy(d:, f:, t:)
|
37
37
|
d = d.to_d
|
38
38
|
f = f.to_d
|
39
39
|
t = t.to_d
|
@@ -48,7 +48,7 @@ module Finrb
|
|
48
48
|
# @export
|
49
49
|
# @examples
|
50
50
|
# bdy2mmy(bdy=0.045,t=120)
|
51
|
-
def self.bdy2mmy(bdy
|
51
|
+
def self.bdy2mmy(bdy:, t:)
|
52
52
|
bdy = bdy.to_d
|
53
53
|
t = t.to_d
|
54
54
|
|
@@ -63,7 +63,7 @@ module Finrb
|
|
63
63
|
# @export
|
64
64
|
# @examples
|
65
65
|
# Finrb::Utils.cash_ratio(cash=3000,ms=2000,cl=2000)
|
66
|
-
def self.cash_ratio(cash
|
66
|
+
def self.cash_ratio(cash:, ms:, cl:)
|
67
67
|
cash = cash.to_d
|
68
68
|
ms = ms.to_d
|
69
69
|
cl = cl.to_d
|
@@ -78,7 +78,7 @@ module Finrb
|
|
78
78
|
# @export
|
79
79
|
# @examples
|
80
80
|
# Finrb::Utils.coefficient_variation(sd=0.15,avg=0.39)
|
81
|
-
def self.coefficient_variation(sd
|
81
|
+
def self.coefficient_variation(sd:, avg:)
|
82
82
|
sd = sd.to_d
|
83
83
|
avg = avg.to_d
|
84
84
|
|
@@ -95,12 +95,12 @@ module Finrb
|
|
95
95
|
# @param method inventory methods: FIFO (first in first out, permitted under both US and IFRS), LIFO (late in first out, US only), WAC (weighted average cost,US and IFRS)
|
96
96
|
# @export
|
97
97
|
# @examples
|
98
|
-
# cogs(uinv=2,pinv=2,units=
|
98
|
+
# cogs(uinv=2,pinv=2,units=[3,5],price=[3,5],sinv=7,method="FIFO")
|
99
99
|
#
|
100
|
-
# cogs(uinv=2,pinv=2,units=
|
100
|
+
# cogs(uinv=2,pinv=2,units=[3,5],price=[3,5],sinv=7,method="LIFO")
|
101
101
|
#
|
102
|
-
# cogs(uinv=2,pinv=2,units=
|
103
|
-
def self.cogs(uinv
|
102
|
+
# cogs(uinv=2,pinv=2,units=[3,5],price=[3,5],sinv=7,method="WAC")
|
103
|
+
def self.cogs(uinv:, pinv:, units:, price:, sinv:, method: 'FIFO')
|
104
104
|
uinv = uinv.to_d
|
105
105
|
pinv = pinv.to_d
|
106
106
|
units = Array.wrap(units).map(&:to_d)
|
@@ -164,7 +164,7 @@ module Finrb
|
|
164
164
|
endingInventory = (units[i] - sinv) * price[i]
|
165
165
|
if i > 1
|
166
166
|
temp = i - 1
|
167
|
-
|
167
|
+
temp.downto(0).each do |j|
|
168
168
|
endingInventory += (units[j] * price[j])
|
169
169
|
end
|
170
170
|
end
|
@@ -200,7 +200,7 @@ module Finrb
|
|
200
200
|
# @export
|
201
201
|
# @examples
|
202
202
|
# Finrb::Utils.current_ratio(ca=8000,cl=2000)
|
203
|
-
def self.current_ratio(ca
|
203
|
+
def self.current_ratio(ca:, cl:)
|
204
204
|
ca = ca.to_d
|
205
205
|
cl = cl.to_d
|
206
206
|
|
@@ -215,7 +215,7 @@ module Finrb
|
|
215
215
|
# @export
|
216
216
|
# @examples
|
217
217
|
# ddb(cost=1200,rv=200,t=5)
|
218
|
-
def self.ddb(cost
|
218
|
+
def self.ddb(cost:, rv:, t:)
|
219
219
|
cost = cost.to_d
|
220
220
|
rv = rv.to_d
|
221
221
|
t = t.to_d
|
@@ -248,7 +248,7 @@ module Finrb
|
|
248
248
|
# @export
|
249
249
|
# @examples
|
250
250
|
# Finrb::Utils.debt_ratio(td=6000,ta=20000)
|
251
|
-
def self.debt_ratio(td
|
251
|
+
def self.debt_ratio(td:, ta:)
|
252
252
|
td = td.to_d
|
253
253
|
ta = ta.to_d
|
254
254
|
|
@@ -275,7 +275,7 @@ module Finrb
|
|
275
275
|
# Finrb::Utils.diluted_eps(ni=115600,pd=10000,w=200000,iss=2500)
|
276
276
|
#
|
277
277
|
# Finrb::Utils.diluted_eps(ni=115600,pd=10000,cpd=10000,cdi=42000,tax=0.4,w=200000,cps=40000,cds=60000,iss=2500)
|
278
|
-
def self.diluted_eps(ni
|
278
|
+
def self.diluted_eps(ni:, pd:, w:, cpd: 0, cdi: 0, tax: 0, cps: 0, cds: 0, iss: 0)
|
279
279
|
ni = ni.to_d
|
280
280
|
pd = pd.to_d
|
281
281
|
w = w.to_d
|
@@ -305,7 +305,7 @@ module Finrb
|
|
305
305
|
# @export
|
306
306
|
# @examples
|
307
307
|
# Finrb::Utils.discount_rate(n=5,pv=0,fv=600,pmt=-100,type=0)
|
308
|
-
def self.discount_rate(n
|
308
|
+
def self.discount_rate(n:, pv:, fv:, pmt:, type: 0, lower: 0.0001, upper: 100)
|
309
309
|
n = n.to_d
|
310
310
|
pv = pv.to_d
|
311
311
|
fv = fv.to_d
|
@@ -315,9 +315,10 @@ module Finrb
|
|
315
315
|
upper = upper.to_d
|
316
316
|
|
317
317
|
nlfunc = NlFunctionStub.new
|
318
|
-
nlfunc.func =
|
319
|
-
|
320
|
-
|
318
|
+
nlfunc.func =
|
319
|
+
lambda do |x|
|
320
|
+
BigDecimal((Finrb::Utils.fv_simple(x[0], n, pv) + Finrb::Utils.fv_annuity(x[0], n, pmt, type) - fv).to_s)
|
321
|
+
end
|
321
322
|
|
322
323
|
root = [(upper - lower) / 2]
|
323
324
|
nlsolve(nlfunc, root)
|
@@ -333,7 +334,7 @@ module Finrb
|
|
333
334
|
# ear(r=0.12,m=12)
|
334
335
|
#
|
335
336
|
# ear(0.04,365)
|
336
|
-
def self.ear(r
|
337
|
+
def self.ear(r:, m:)
|
337
338
|
r = r.to_d
|
338
339
|
m = m.to_d
|
339
340
|
|
@@ -348,7 +349,7 @@ module Finrb
|
|
348
349
|
# Finrb::Utils.ear_continuous(r=0.1)
|
349
350
|
#
|
350
351
|
# Finrb::Utils.ear_continuous(0.03)
|
351
|
-
def self.ear_continuous(r)
|
352
|
+
def self.ear_continuous(r:)
|
352
353
|
r = r.to_d
|
353
354
|
|
354
355
|
(r.to_d.exp - 1)
|
@@ -360,7 +361,7 @@ module Finrb
|
|
360
361
|
# @export
|
361
362
|
# @examples
|
362
363
|
# ear2bey(ear=0.08)
|
363
|
-
def self.ear2bey(ear)
|
364
|
+
def self.ear2bey(ear:)
|
364
365
|
ear = ear.to_d
|
365
366
|
|
366
367
|
((((1 + ear)**0.5) - 1) * 2)
|
@@ -373,7 +374,7 @@ module Finrb
|
|
373
374
|
# @export
|
374
375
|
# @examples
|
375
376
|
# ear2hpr(ear=0.05039,t=150)
|
376
|
-
def self.ear2hpr(ear
|
377
|
+
def self.ear2hpr(ear:, t:)
|
377
378
|
ear = ear.to_d
|
378
379
|
t = t.to_d
|
379
380
|
|
@@ -410,7 +411,7 @@ module Finrb
|
|
410
411
|
#
|
411
412
|
# # monthly proportional interest rate which is equivalent to a simple annual interest
|
412
413
|
# Finrb::Utils.eir(r=0.05,p=12,type='p')
|
413
|
-
def self.eir(r
|
414
|
+
def self.eir(r:, n: 1, p: 12, type: 'e')
|
414
415
|
r = r.to_d
|
415
416
|
n = n.to_d
|
416
417
|
p = p.to_d
|
@@ -435,7 +436,7 @@ module Finrb
|
|
435
436
|
# @export
|
436
437
|
# @examples
|
437
438
|
# Finrb::Utils.eps(ni=10000,pd=1000,w=11000)
|
438
|
-
def self.eps(ni
|
439
|
+
def self.eps(ni:, pd:, w:)
|
439
440
|
ni = ni.to_d
|
440
441
|
pd = pd.to_d
|
441
442
|
w = w.to_d
|
@@ -450,7 +451,7 @@ module Finrb
|
|
450
451
|
# @export
|
451
452
|
# @examples
|
452
453
|
# Finrb::Utils.financial_leverage(te=16000,ta=20000)
|
453
|
-
def self.financial_leverage(te
|
454
|
+
def self.financial_leverage(te:, ta:)
|
454
455
|
te = te.to_d
|
455
456
|
ta = ta.to_d
|
456
457
|
|
@@ -467,7 +468,7 @@ module Finrb
|
|
467
468
|
# @export
|
468
469
|
# @examples
|
469
470
|
# fv(r=0.07,n=10,pv=1000,pmt=10)
|
470
|
-
def self.fv(r
|
471
|
+
def self.fv(r:, n:, pv: 0, pmt: 0, type: 0)
|
471
472
|
r = r.to_d
|
472
473
|
n = n.to_d
|
473
474
|
pv = pv.to_d
|
@@ -492,7 +493,7 @@ module Finrb
|
|
492
493
|
# Finrb::Utils.fv_annuity(0.03,12,-1000)
|
493
494
|
#
|
494
495
|
# Finrb::Utils.fv_annuity(r=0.03,n=12,pmt=-1000,type=1)
|
495
|
-
def self.fv_annuity(r
|
496
|
+
def self.fv_annuity(r:, n:, pmt:, type: 0)
|
496
497
|
r = r.to_d
|
497
498
|
n = n.to_d
|
498
499
|
pmt = pmt.to_d
|
@@ -516,7 +517,7 @@ module Finrb
|
|
516
517
|
# Finrb::Utils.fv_simple(0.08,10,-300)
|
517
518
|
#
|
518
519
|
# Finrb::Utils.fv_simple(r=0.04,n=20,pv=-50000)
|
519
|
-
def self.fv_simple(r
|
520
|
+
def self.fv_simple(r:, n:, pv:)
|
520
521
|
r = r.to_d
|
521
522
|
n = n.to_d
|
522
523
|
pv = pv.to_d
|
@@ -530,8 +531,8 @@ module Finrb
|
|
530
531
|
# @param cf uneven cash flow
|
531
532
|
# @export
|
532
533
|
# @examples
|
533
|
-
# Finrb::Utils.fv_uneven(r=0.1, cf=
|
534
|
-
def self.fv_uneven(r
|
534
|
+
# Finrb::Utils.fv_uneven(r=0.1, cf=[-1000, -500, 0, 4000, 3500, 2000])
|
535
|
+
def self.fv_uneven(r:, cf:)
|
535
536
|
r = r.to_d
|
536
537
|
cf = Array.wrap(cf).map(&:to_d)
|
537
538
|
|
@@ -549,8 +550,8 @@ module Finrb
|
|
549
550
|
# @param r returns over multiple periods
|
550
551
|
# @export
|
551
552
|
# @examples
|
552
|
-
# Finrb::Utils.geometric_mean(r=
|
553
|
-
def self.geometric_mean(r)
|
553
|
+
# Finrb::Utils.geometric_mean(r=[-0.0934, 0.2345, 0.0892])
|
554
|
+
def self.geometric_mean(r:)
|
554
555
|
r = Array.wrap(r).map(&:to_d)
|
555
556
|
|
556
557
|
rs = r + 1
|
@@ -564,7 +565,7 @@ module Finrb
|
|
564
565
|
# @export
|
565
566
|
# @examples
|
566
567
|
# gpm(gp=1000,rv=20000)
|
567
|
-
def self.gpm(gp
|
568
|
+
def self.gpm(gp:, rv:)
|
568
569
|
gp = gp.to_d
|
569
570
|
rv = rv.to_d
|
570
571
|
|
@@ -575,8 +576,8 @@ module Finrb
|
|
575
576
|
# @param p price over multiple periods
|
576
577
|
# @export
|
577
578
|
# @examples
|
578
|
-
# Finrb::Utils.harmonic_mean(p=
|
579
|
-
def self.harmonic_mean(p)
|
579
|
+
# Finrb::Utils.harmonic_mean(p=[8,9,10])
|
580
|
+
def self.harmonic_mean(p:)
|
580
581
|
p = Array.wrap(p).map(&:to_d)
|
581
582
|
|
582
583
|
(1 / (p.sum { |val| 1 / val } / p.size))
|
@@ -590,7 +591,7 @@ module Finrb
|
|
590
591
|
# @export
|
591
592
|
# @examples
|
592
593
|
# hpr(ev=33,bv=30,cfr=0.5)
|
593
|
-
def self.hpr(ev
|
594
|
+
def self.hpr(ev:, bv:, cfr: 0)
|
594
595
|
ev = ev.to_d
|
595
596
|
bv = bv.to_d
|
596
597
|
cfr = cfr.to_d
|
@@ -605,7 +606,7 @@ module Finrb
|
|
605
606
|
# @export
|
606
607
|
# @examples
|
607
608
|
# hpr2bey(hpr=0.02,t=3)
|
608
|
-
def self.hpr2bey(hpr
|
609
|
+
def self.hpr2bey(hpr:, t:)
|
609
610
|
hpr = hpr.to_d
|
610
611
|
t = t.to_d
|
611
612
|
|
@@ -619,7 +620,7 @@ module Finrb
|
|
619
620
|
# @export
|
620
621
|
# @examples
|
621
622
|
# hpr2ear(hpr=0.015228,t=120)
|
622
|
-
def self.hpr2ear(hpr
|
623
|
+
def self.hpr2ear(hpr:, t:)
|
623
624
|
hpr = hpr.to_d
|
624
625
|
t = t.to_d
|
625
626
|
|
@@ -633,7 +634,7 @@ module Finrb
|
|
633
634
|
# @export
|
634
635
|
# @examples
|
635
636
|
# hpr2mmy(hpr=0.01523,t=120)
|
636
|
-
def self.hpr2mmy(hpr
|
637
|
+
def self.hpr2mmy(hpr:, t:)
|
637
638
|
hpr = hpr.to_d
|
638
639
|
t = t.to_d
|
639
640
|
|
@@ -646,17 +647,17 @@ module Finrb
|
|
646
647
|
# @importFrom stats uniroot
|
647
648
|
# @export
|
648
649
|
# @examples
|
649
|
-
# irr(cf=
|
650
|
-
def self.irr(cf)
|
650
|
+
# irr(cf=[-5, 1.6, 2.4, 2.8])
|
651
|
+
def self.irr(cf:)
|
651
652
|
cf = Array.wrap(cf).map(&:to_d)
|
652
653
|
|
653
654
|
n = cf.size
|
654
655
|
subcf = cf.drop(1)
|
655
|
-
|
656
656
|
nlfunc = NlFunctionStub.new
|
657
|
-
nlfunc.func =
|
658
|
-
|
659
|
-
|
657
|
+
nlfunc.func =
|
658
|
+
lambda do |x|
|
659
|
+
BigDecimal(((-1 * Finrb::Utils.pv_uneven(x[0], subcf)) + cf[0]).to_s)
|
660
|
+
end
|
660
661
|
|
661
662
|
root = [0]
|
662
663
|
nlsolve(nlfunc, root)
|
@@ -672,9 +673,9 @@ module Finrb
|
|
672
673
|
# @param step increment of the irr
|
673
674
|
# @export
|
674
675
|
# @examples
|
675
|
-
# irr2(cf=
|
676
|
-
# irr2(cf=
|
677
|
-
def self.irr2(cf
|
676
|
+
# irr2(cf=[-5, 1.6, 2.4, 2.8])
|
677
|
+
# irr2(cf=[-200, 50, 60, -70, 30, 20])
|
678
|
+
def self.irr2(cf:, cutoff: 0.1, from: -1, to: 10, step: 0.000001)
|
678
679
|
cf = Array.wrap(cf).map(&:to_d)
|
679
680
|
cutoff = cutoff.to_d
|
680
681
|
from = from.to_d
|
@@ -714,7 +715,7 @@ module Finrb
|
|
714
715
|
# @export
|
715
716
|
# @examples
|
716
717
|
# iss(amp=20,ep=15,n=10000)
|
717
|
-
def self.iss(amp
|
718
|
+
def self.iss(amp:, ep:, n:)
|
718
719
|
amp = amp.to_d
|
719
720
|
ep = ep.to_d
|
720
721
|
n = n.to_d
|
@@ -733,7 +734,7 @@ module Finrb
|
|
733
734
|
# @export
|
734
735
|
# @examples
|
735
736
|
# Finrb::Utils.lt_d2e(ltd=8000,te=20000)
|
736
|
-
def self.lt_d2e(ltd
|
737
|
+
def self.lt_d2e(ltd:, te:)
|
737
738
|
ltd = ltd.to_d
|
738
739
|
te = te.to_d
|
739
740
|
|
@@ -747,7 +748,7 @@ module Finrb
|
|
747
748
|
# @export
|
748
749
|
# @examples
|
749
750
|
# mmy2hpr(mmy=0.04898,t=150)
|
750
|
-
def self.mmy2hpr(mmy
|
751
|
+
def self.mmy2hpr(mmy:, t:)
|
751
752
|
mmy = mmy.to_d
|
752
753
|
t = t.to_d
|
753
754
|
|
@@ -766,7 +767,7 @@ module Finrb
|
|
766
767
|
# Finrb::Utils.n_period(0.1,-10000,60000000,-50000,0)
|
767
768
|
#
|
768
769
|
# Finrb::Utils.n_period(r=0.1,pv=-10000,fv=60000000,pmt=-50000,type=1)
|
769
|
-
def self.n_period(r
|
770
|
+
def self.n_period(r:, pv:, fv:, pmt:, type: 0)
|
770
771
|
r = r.to_d
|
771
772
|
pv = pv.to_d
|
772
773
|
fv = fv.to_d
|
@@ -788,7 +789,7 @@ module Finrb
|
|
788
789
|
# @export
|
789
790
|
# @examples
|
790
791
|
# npm(ni=8000,rv=20000)
|
791
|
-
def self.npm(ni
|
792
|
+
def self.npm(ni:, rv:)
|
792
793
|
ni = ni.to_d
|
793
794
|
rv = rv.to_d
|
794
795
|
|
@@ -801,8 +802,8 @@ module Finrb
|
|
801
802
|
# @param cf cash flow,the first cash flow is the initial outlay
|
802
803
|
# @export
|
803
804
|
# @examples
|
804
|
-
# npv(r=0.12, cf=
|
805
|
-
def self.npv(r
|
805
|
+
# npv(r=0.12, cf=[-5, 1.6, 2.4, 2.8])
|
806
|
+
def self.npv(r:, cf:)
|
806
807
|
r = r.to_d
|
807
808
|
cf = Array.wrap(cf).map(&:to_d)
|
808
809
|
|
@@ -825,7 +826,7 @@ module Finrb
|
|
825
826
|
# pmt(r=0.08,n=10,pv=-1000,fv=0)
|
826
827
|
#
|
827
828
|
# pmt(0.08,10,-1000,10,1)
|
828
|
-
def self.pmt(r
|
829
|
+
def self.pmt(r:, n:, pv:, fv:, type: 0)
|
829
830
|
r = r.to_d
|
830
831
|
n = n.to_d
|
831
832
|
pv = pv.to_d
|
@@ -852,7 +853,7 @@ module Finrb
|
|
852
853
|
# pv(0.07,10,1000,10)
|
853
854
|
#
|
854
855
|
# pv(r=0.05,n=20,fv=1000,pmt=10,type=1)
|
855
|
-
def self.pv(r
|
856
|
+
def self.pv(r:, n:, fv: 0, pmt: 0, type: 0)
|
856
857
|
r = r.to_d
|
857
858
|
n = n.to_d
|
858
859
|
fv = fv.to_d
|
@@ -878,7 +879,7 @@ module Finrb
|
|
878
879
|
# Finrb::Utils.pv_annuity(0.03,12,1000)
|
879
880
|
#
|
880
881
|
# Finrb::Utils.pv_annuity(r=0.0425,n=3,pmt=30000)
|
881
|
-
def self.pv_annuity(r
|
882
|
+
def self.pv_annuity(r:, n:, pmt:, type: 0)
|
882
883
|
r = r.to_d
|
883
884
|
n = n.to_d
|
884
885
|
pmt = pmt.to_d
|
@@ -905,7 +906,7 @@ module Finrb
|
|
905
906
|
# Finrb::Utils.pv_perpetuity(r=0.1,pmt=1000,type=1)
|
906
907
|
#
|
907
908
|
# Finrb::Utils.pv_perpetuity(r=0.1,pmt=1000)
|
908
|
-
def self.pv_perpetuity(r
|
909
|
+
def self.pv_perpetuity(r:, pmt:, g: 0, type: 0)
|
909
910
|
r = r.to_d
|
910
911
|
pmt = pmt.to_d
|
911
912
|
g = g.to_d
|
@@ -931,7 +932,7 @@ module Finrb
|
|
931
932
|
# Finrb::Utils.pv_simple(0.07,10,100)
|
932
933
|
#
|
933
934
|
# Finrb::Utils.pv_simple(r=0.03,n=3,fv=1000)
|
934
|
-
def self.pv_simple(r
|
935
|
+
def self.pv_simple(r:, n:, fv:)
|
935
936
|
r = r.to_d
|
936
937
|
n = n.to_d
|
937
938
|
fv = fv.to_d
|
@@ -945,8 +946,8 @@ module Finrb
|
|
945
946
|
# @param cf uneven cash flow
|
946
947
|
# @export
|
947
948
|
# @examples
|
948
|
-
# Finrb::Utils.pv_uneven(r=0.1, cf=
|
949
|
-
def self.pv_uneven(r
|
949
|
+
# Finrb::Utils.pv_uneven(r=0.1, cf=[-1000, -500, 0, 4000, 3500, 2000])
|
950
|
+
def self.pv_uneven(r:, cf:)
|
950
951
|
r = r.to_d
|
951
952
|
cf = Array.wrap(cf).map(&:to_d)
|
952
953
|
|
@@ -967,7 +968,7 @@ module Finrb
|
|
967
968
|
# @export
|
968
969
|
# @examples
|
969
970
|
# Finrb::Utils.quick_ratio(cash=3000,ms=2000,rc=1000,cl=2000)
|
970
|
-
def self.quick_ratio(cash
|
971
|
+
def self.quick_ratio(cash:, ms:, rc:, cl:)
|
971
972
|
cash = cash.to_d
|
972
973
|
ms = ms.to_d
|
973
974
|
rc = rc.to_d
|
@@ -983,7 +984,7 @@ module Finrb
|
|
983
984
|
# @export
|
984
985
|
# @examples
|
985
986
|
# Finrb::Utils.r_continuous(r=0.03,m=4)
|
986
|
-
def self.r_continuous(r
|
987
|
+
def self.r_continuous(r:, m:)
|
987
988
|
r = r.to_d
|
988
989
|
m = m.to_d
|
989
990
|
|
@@ -999,7 +1000,7 @@ module Finrb
|
|
999
1000
|
# Finrb::Utils.r_norminal(0.03,1)
|
1000
1001
|
#
|
1001
1002
|
# Finrb::Utils.r_norminal(rc=0.03,m=4)
|
1002
|
-
def self.r_norminal(rc
|
1003
|
+
def self.r_norminal(rc:, m:)
|
1003
1004
|
rc = rc.to_d
|
1004
1005
|
m = m.to_d
|
1005
1006
|
|
@@ -1013,7 +1014,7 @@ module Finrb
|
|
1013
1014
|
# @export
|
1014
1015
|
# @examples
|
1015
1016
|
# Finrb::Utils.r_perpetuity(pmt=4.5,pv=-75)
|
1016
|
-
def self.r_perpetuity(pmt
|
1017
|
+
def self.r_perpetuity(pmt:, pv:)
|
1017
1018
|
pmt = pmt.to_d
|
1018
1019
|
pv = pv.to_d
|
1019
1020
|
|
@@ -1027,7 +1028,7 @@ module Finrb
|
|
1027
1028
|
# @export
|
1028
1029
|
# @examples
|
1029
1030
|
# Finrb::Utils.sampling_error(sm=0.45, mu=0.5)
|
1030
|
-
def self.sampling_error(sm
|
1031
|
+
def self.sampling_error(sm:, mu:)
|
1031
1032
|
sm = sm.to_d
|
1032
1033
|
mu = mu.to_d
|
1033
1034
|
|
@@ -1042,7 +1043,7 @@ module Finrb
|
|
1042
1043
|
# @export
|
1043
1044
|
# @examples
|
1044
1045
|
# Finrb::Utils.sf_ratio(rp=0.09,rl=0.03,sd=0.12)
|
1045
|
-
def self.sf_ratio(rp
|
1046
|
+
def self.sf_ratio(rp:, rl:, sd:)
|
1046
1047
|
rp = rp.to_d
|
1047
1048
|
rl = rl.to_d
|
1048
1049
|
sd = sd.to_d
|
@@ -1058,7 +1059,7 @@ module Finrb
|
|
1058
1059
|
# @export
|
1059
1060
|
# @examples
|
1060
1061
|
# Finrb::Utils.sharpe_ratio(rp=0.038,rf=0.015,sd=0.07)
|
1061
|
-
def self.sharpe_ratio(rp
|
1062
|
+
def self.sharpe_ratio(rp:, rf:, sd:)
|
1062
1063
|
rp = rp.to_d
|
1063
1064
|
rf = rf.to_d
|
1064
1065
|
sd = sd.to_d
|
@@ -1074,7 +1075,7 @@ module Finrb
|
|
1074
1075
|
# @export
|
1075
1076
|
# @examples
|
1076
1077
|
# slde(cost=1200,rv=200,t=5)
|
1077
|
-
def self.slde(cost
|
1078
|
+
def self.slde(cost:, rv:, t:)
|
1078
1079
|
cost = cost.to_d
|
1079
1080
|
rv = rv.to_d
|
1080
1081
|
t = t.to_d
|
@@ -1089,7 +1090,7 @@ module Finrb
|
|
1089
1090
|
# @export
|
1090
1091
|
# @examples
|
1091
1092
|
# Finrb::Utils.total_d2e(td=6000,te=20000)
|
1092
|
-
def self.total_d2e(td
|
1093
|
+
def self.total_d2e(td:, te:)
|
1093
1094
|
td = td.to_d
|
1094
1095
|
te = te.to_d
|
1095
1096
|
|
@@ -1103,8 +1104,8 @@ module Finrb
|
|
1103
1104
|
# @param cfr ordered cash flow received list
|
1104
1105
|
# @export
|
1105
1106
|
# @examples
|
1106
|
-
# twrr(ev=
|
1107
|
-
def self.twrr(ev
|
1107
|
+
# twrr(ev=[120,260],bv=[100,240],cfr=[2,4])
|
1108
|
+
def self.twrr(ev:, bv:, cfr:)
|
1108
1109
|
ev = Array.wrap(ev).map(&:to_d)
|
1109
1110
|
bv = Array.wrap(bv).map(&:to_d)
|
1110
1111
|
cfr = Array.wrap(cfr).map(&:to_d)
|
@@ -1129,10 +1130,10 @@ module Finrb
|
|
1129
1130
|
# @param nm n x 1 vector vector of number of months relate to ns
|
1130
1131
|
# @export
|
1131
1132
|
# @examples
|
1132
|
-
# s=
|
1133
|
+
# s=[10000,2000];m=[12,6];was(ns=s,nm=m)
|
1133
1134
|
#
|
1134
|
-
# s=
|
1135
|
-
def self.was(ns
|
1135
|
+
# s=[11000,4400,-3000];m=[12,9,4];was(ns=s,nm=m)
|
1136
|
+
def self.was(ns:, nm:)
|
1136
1137
|
ns = Array.wrap(ns).map(&:to_d)
|
1137
1138
|
nm = Array.wrap(nm).map(&:to_d)
|
1138
1139
|
|
@@ -1156,8 +1157,8 @@ module Finrb
|
|
1156
1157
|
# @param w corresponding weights associated with each of the individual assets
|
1157
1158
|
# @export
|
1158
1159
|
# @examples
|
1159
|
-
# wpr(r=
|
1160
|
-
def self.wpr(r
|
1160
|
+
# wpr(r=[0.12, 0.07, 0.03],w=[0.5,0.4,0.1])
|
1161
|
+
def self.wpr(r:, w:)
|
1161
1162
|
r = Array.wrap(r).map(&:to_d)
|
1162
1163
|
w = Array.wrap(w).map(&:to_d)
|
1163
1164
|
|
data/lib/finrb.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
3
|
+
require "active_support/configurable"
|
4
|
+
require "finrb/config"
|
5
|
+
require "finrb/decimal"
|
6
|
+
require "finrb/cashflows"
|
7
|
+
require "finrb/utils"
|
8
8
|
|
9
9
|
class FinrbError < StandardError; end
|
10
10
|
|
@@ -16,8 +16,8 @@ class FinrbError < StandardError; end
|
|
16
16
|
# * *principal* represents the outstanding balance of a loan or annuity.
|
17
17
|
# * *rate* represents the interest rate _per period_.
|
18
18
|
module Finrb
|
19
|
-
autoload :Amortization,
|
20
|
-
autoload :Rate,
|
21
|
-
autoload :Transaction,
|
22
|
-
autoload :Utils,
|
19
|
+
autoload :Amortization, "finrb/amortization"
|
20
|
+
autoload :Rate, "finrb/rates"
|
21
|
+
autoload :Transaction, "finrb/transaction"
|
22
|
+
autoload :Utils, "finrb/utils"
|
23
23
|
end
|
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.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nadir Cohen
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2022-08-
|
13
|
+
date: 2022-08-09 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activesupport
|
@@ -138,6 +138,20 @@ dependencies:
|
|
138
138
|
- - ">="
|
139
139
|
- !ruby/object:Gem::Version
|
140
140
|
version: '0'
|
141
|
+
- !ruby/object:Gem::Dependency
|
142
|
+
name: rubocop-packaging
|
143
|
+
requirement: !ruby/object:Gem::Requirement
|
144
|
+
requirements:
|
145
|
+
- - ">="
|
146
|
+
- !ruby/object:Gem::Version
|
147
|
+
version: '0'
|
148
|
+
type: :development
|
149
|
+
prerelease: false
|
150
|
+
version_requirements: !ruby/object:Gem::Requirement
|
151
|
+
requirements:
|
152
|
+
- - ">="
|
153
|
+
- !ruby/object:Gem::Version
|
154
|
+
version: '0'
|
141
155
|
- !ruby/object:Gem::Dependency
|
142
156
|
name: rubocop-rake
|
143
157
|
requirement: !ruby/object:Gem::Requirement
|
@@ -180,66 +194,9 @@ dependencies:
|
|
180
194
|
- - ">="
|
181
195
|
- !ruby/object:Gem::Version
|
182
196
|
version: '0'
|
183
|
-
description:
|
184
|
-
|
185
|
-
|
186
|
-
- Working with interest rates
|
187
|
-
- Mortgage amortization
|
188
|
-
- Cashflows (NPV, IRR, etc.)
|
189
|
-
- Computing bank discount yield (BDY) for a T-bill
|
190
|
-
- Computing money market yield (MMY) for a T-bill
|
191
|
-
- Cash ratio - Liquidity ratios measure the firm's ability to satisfy its short-term obligations as they come due.
|
192
|
-
- Computing Coefficient of variation
|
193
|
-
- Cost of goods sold and ending inventory under three methods (FIFO,LIFO,Weighted average)
|
194
|
-
- Current ratio - Liquidity ratios measure the firm's ability to satisfy its short-term obligations as they come due.
|
195
|
-
- Depreciation Expense Recognition - double-declining balance (DDB), the most common declining balance method, which applies two times the straight-line rate to the declining balance.
|
196
|
-
- Debt ratio - Solvency ratios measure the firm's ability to satisfy its long-term obligations.
|
197
|
-
- Diluted Earnings Per Share
|
198
|
-
- Computing the rate of return for each period
|
199
|
-
- Convert stated annual rate to the effective annual rate
|
200
|
-
- Convert stated annual rate to the effective annual rate with continuous compounding
|
201
|
-
- Bond-equivalent yield (BEY), 2 x the semiannual discount rate
|
202
|
-
- Computing HPR, the holding period return
|
203
|
-
- Equivalent/proportional Interest Rates
|
204
|
-
- Basic Earnings Per Share
|
205
|
-
- Financial leverage - Solvency ratios measure the firm's ability to satisfy its long-term obligations.
|
206
|
-
- Estimate future value (fv)
|
207
|
-
- Estimate future value of an annuity
|
208
|
-
- Estimate future value (fv) of a single sum
|
209
|
-
- Computing the future value of an uneven cash flow series
|
210
|
-
- Geometric mean return
|
211
|
-
- Gross profit margin - Evaluate a company's financial performance
|
212
|
-
- Harmonic mean, average price
|
213
|
-
- Computing HPR, the holding period return
|
214
|
-
- Bond-equivalent yield (BEY), 2 x the semiannual discount rate
|
215
|
-
- Convert holding period return to the effective annual rate
|
216
|
-
- Computing money market yield (MMY) for a T-bill
|
217
|
-
- Computing IRR, the internal rate of return
|
218
|
-
- Calculate the net increase in common shares from the potential exercise of stock options or warrants
|
219
|
-
- Long-term debt-to-equity - Solvency ratios measure the firm's ability to satisfy its long-term obligations.
|
220
|
-
- Computing HPR, the holding period return
|
221
|
-
- Estimate the number of periods
|
222
|
-
- Net profit margin - Evaluate a company's financial performance
|
223
|
-
- Computing NPV, the PV of the cash flows less the initial (time = 0) outlay
|
224
|
-
- Estimate period payment
|
225
|
-
- Estimate present value (pv)
|
226
|
-
- Estimate present value (pv) of an annuity
|
227
|
-
- Estimate present value of a perpetuity
|
228
|
-
- Estimate present value (pv) of a single sum
|
229
|
-
- Computing the present value of an uneven cash flow series
|
230
|
-
- Quick ratio - Liquidity ratios measure the firm's ability to satisfy its short-term obligations as they come due.
|
231
|
-
- Convert a given norminal rate to a continuous compounded rate
|
232
|
-
- Convert a given continuous compounded rate to a norminal rate
|
233
|
-
- Rate of return for a perpetuity
|
234
|
-
- Computing Sampling error
|
235
|
-
- Computing Roy's safety-first ratio
|
236
|
-
- Computing Sharpe Ratio
|
237
|
-
- Depreciation Expense Recognition - Straight-line depreciation (SL) allocates an equal amount of depreciation each year over the asset's useful life
|
238
|
-
- Total debt-to-equity - Solvency ratios measure the firm's ability to satisfy its long-term obligations.
|
239
|
-
- Computing TWRR, the time-weighted rate of return
|
240
|
-
- Calculate weighted average shares - weighted average number of common shares
|
241
|
-
- Weighted mean as a portfolio return
|
242
|
-
|
197
|
+
description: "The finrb library (forked from the finance gem) provides a Ruby interface
|
198
|
+
for financial calculations/modeling. Working with interest rates, Mortgage amortization,
|
199
|
+
Cashflows (NPV, IRR, etc.) and other basic utilities.\n\n"
|
243
200
|
email:
|
244
201
|
- nadircs11@gmail.com
|
245
202
|
- me@martinbjeldbak.com
|
@@ -254,11 +211,16 @@ extra_rdoc_files:
|
|
254
211
|
files:
|
255
212
|
- ".dockerignore"
|
256
213
|
- ".gitattributes"
|
214
|
+
- ".github/dependabot.yml"
|
215
|
+
- ".github/issue_template.md"
|
216
|
+
- ".github/pull_request_template.md"
|
217
|
+
- ".github/workflows/ci.yml"
|
218
|
+
- ".github/workflows/codeql.yml"
|
219
|
+
- ".github/workflows/rubocop.yml"
|
257
220
|
- ".gitignore"
|
258
221
|
- ".rubocop.yml"
|
259
222
|
- ".ruby-version"
|
260
223
|
- ".semver"
|
261
|
-
- ".travis.yml"
|
262
224
|
- ".yardopts"
|
263
225
|
- CHANGELOG.md
|
264
226
|
- COPYING
|