finrb 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/COPYING.LESSER ADDED
@@ -0,0 +1,165 @@
1
+ GNU LESSER GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+
9
+ This version of the GNU Lesser General Public License incorporates
10
+ the terms and conditions of version 3 of the GNU General Public
11
+ License, supplemented by the additional permissions listed below.
12
+
13
+ 0. Additional Definitions.
14
+
15
+ As used herein, "this License" refers to version 3 of the GNU Lesser
16
+ General Public License, and the "GNU GPL" refers to version 3 of the GNU
17
+ General Public License.
18
+
19
+ "The Library" refers to a covered work governed by this License,
20
+ other than an Application or a Combined Work as defined below.
21
+
22
+ An "Application" is any work that makes use of an interface provided
23
+ by the Library, but which is not otherwise based on the Library.
24
+ Defining a subclass of a class defined by the Library is deemed a mode
25
+ of using an interface provided by the Library.
26
+
27
+ A "Combined Work" is a work produced by combining or linking an
28
+ Application with the Library. The particular version of the Library
29
+ with which the Combined Work was made is also called the "Linked
30
+ Version".
31
+
32
+ The "Minimal Corresponding Source" for a Combined Work means the
33
+ Corresponding Source for the Combined Work, excluding any source code
34
+ for portions of the Combined Work that, considered in isolation, are
35
+ based on the Application, and not on the Linked Version.
36
+
37
+ The "Corresponding Application Code" for a Combined Work means the
38
+ object code and/or source code for the Application, including any data
39
+ and utility programs needed for reproducing the Combined Work from the
40
+ Application, but excluding the System Libraries of the Combined Work.
41
+
42
+ 1. Exception to Section 3 of the GNU GPL.
43
+
44
+ You may convey a covered work under sections 3 and 4 of this License
45
+ without being bound by section 3 of the GNU GPL.
46
+
47
+ 2. Conveying Modified Versions.
48
+
49
+ If you modify a copy of the Library, and, in your modifications, a
50
+ facility refers to a function or data to be supplied by an Application
51
+ that uses the facility (other than as an argument passed when the
52
+ facility is invoked), then you may convey a copy of the modified
53
+ version:
54
+
55
+ a) under this License, provided that you make a good faith effort to
56
+ ensure that, in the event an Application does not supply the
57
+ function or data, the facility still operates, and performs
58
+ whatever part of its purpose remains meaningful, or
59
+
60
+ b) under the GNU GPL, with none of the additional permissions of
61
+ this License applicable to that copy.
62
+
63
+ 3. Object Code Incorporating Material from Library Header Files.
64
+
65
+ The object code form of an Application may incorporate material from
66
+ a header file that is part of the Library. You may convey such object
67
+ code under terms of your choice, provided that, if the incorporated
68
+ material is not limited to numerical parameters, data structure
69
+ layouts and accessors, or small macros, inline functions and templates
70
+ (ten or fewer lines in length), you do both of the following:
71
+
72
+ a) Give prominent notice with each copy of the object code that the
73
+ Library is used in it and that the Library and its use are
74
+ covered by this License.
75
+
76
+ b) Accompany the object code with a copy of the GNU GPL and this license
77
+ document.
78
+
79
+ 4. Combined Works.
80
+
81
+ You may convey a Combined Work under terms of your choice that,
82
+ taken together, effectively do not restrict modification of the
83
+ portions of the Library contained in the Combined Work and reverse
84
+ engineering for debugging such modifications, if you also do each of
85
+ the following:
86
+
87
+ a) Give prominent notice with each copy of the Combined Work that
88
+ the Library is used in it and that the Library and its use are
89
+ covered by this License.
90
+
91
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
92
+ document.
93
+
94
+ c) For a Combined Work that displays copyright notices during
95
+ execution, include the copyright notice for the Library among
96
+ these notices, as well as a reference directing the user to the
97
+ copies of the GNU GPL and this license document.
98
+
99
+ d) Do one of the following:
100
+
101
+ 0) Convey the Minimal Corresponding Source under the terms of this
102
+ License, and the Corresponding Application Code in a form
103
+ suitable for, and under terms that permit, the user to
104
+ recombine or relink the Application with a modified version of
105
+ the Linked Version to produce a modified Combined Work, in the
106
+ manner specified by section 6 of the GNU GPL for conveying
107
+ Corresponding Source.
108
+
109
+ 1) Use a suitable shared library mechanism for linking with the
110
+ Library. A suitable mechanism is one that (a) uses at run time
111
+ a copy of the Library already present on the user's computer
112
+ system, and (b) will operate properly with a modified version
113
+ of the Library that is interface-compatible with the Linked
114
+ Version.
115
+
116
+ e) Provide Installation Information, but only if you would otherwise
117
+ be required to provide such information under section 6 of the
118
+ GNU GPL, and only to the extent that such information is
119
+ necessary to install and execute a modified version of the
120
+ Combined Work produced by recombining or relinking the
121
+ Application with a modified version of the Linked Version. (If
122
+ you use option 4d0, the Installation Information must accompany
123
+ the Minimal Corresponding Source and Corresponding Application
124
+ Code. If you use option 4d1, you must provide the Installation
125
+ Information in the manner specified by section 6 of the GNU GPL
126
+ for conveying Corresponding Source.)
127
+
128
+ 5. Combined Libraries.
129
+
130
+ You may place library facilities that are a work based on the
131
+ Library side by side in a single library together with other library
132
+ facilities that are not Applications and are not covered by this
133
+ License, and convey such a combined library under terms of your
134
+ choice, if you do both of the following:
135
+
136
+ a) Accompany the combined library with a copy of the same work based
137
+ on the Library, uncombined with any other library facilities,
138
+ conveyed under the terms of this License.
139
+
140
+ b) Give prominent notice with the combined library that part of it
141
+ is a work based on the Library, and explaining where to find the
142
+ accompanying uncombined form of the same work.
143
+
144
+ 6. Revised Versions of the GNU Lesser General Public License.
145
+
146
+ The Free Software Foundation may publish revised and/or new versions
147
+ of the GNU Lesser General Public License from time to time. Such new
148
+ versions will be similar in spirit to the present version, but may
149
+ differ in detail to address new problems or concerns.
150
+
151
+ Each version is given a distinguishing version number. If the
152
+ Library as you received it specifies that a certain numbered version
153
+ of the GNU Lesser General Public License "or any later version"
154
+ applies to it, you have the option of following the terms and
155
+ conditions either of that published version or of any later version
156
+ published by the Free Software Foundation. If the Library as you
157
+ received it does not specify a version number of the GNU Lesser
158
+ General Public License, you may choose any version of the GNU Lesser
159
+ General Public License ever published by the Free Software Foundation.
160
+
161
+ If the Library as you received it specifies that a proxy can decide
162
+ whether future versions of the GNU Lesser General Public License shall
163
+ apply, that proxy's public statement of acceptance of any version is
164
+ permanent authorization for you to choose that version for the
165
+ Library.
data/Dockerfile ADDED
@@ -0,0 +1,35 @@
1
+ FROM ruby:3.1.2 AS development
2
+
3
+ LABEL maintainer="nadircs11@gmail.co.il"
4
+
5
+ RUN dpkg --add-architecture i386
6
+
7
+ SHELL [ "/bin/bash", "-c" ]
8
+
9
+ RUN apt update -yqq && \
10
+ apt install --no-install-recommends -yqq nano apt-utils locales && \
11
+ apt clean && \
12
+ rm -rf /var/lib/apt/lists/*
13
+
14
+ RUN gem install bundler
15
+ RUN bundle config --global jobs 16
16
+
17
+ RUN mkdir -pv /app
18
+ WORKDIR /app
19
+
20
+ RUN mkdir -pv ./lib/
21
+ COPY *.gemspec ./
22
+ COPY Gemfile* ./
23
+ RUN bundle install
24
+
25
+ WORKDIR /app
26
+
27
+ COPY . .
28
+
29
+ ENTRYPOINT ["/bin/bash", "-c", "/bin/bash"]
30
+
31
+ FROM development AS testing
32
+
33
+ RUN bundle exec rake test_units || exit 0
34
+
35
+ ENTRYPOINT ["/bin/bash", "-c", "/bin/bash"]
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'http://rubygems.org'
4
+
5
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,116 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ finrb (0.0.1)
5
+ activesupport
6
+ business_time
7
+ flt
8
+
9
+ GEM
10
+ remote: http://rubygems.org/
11
+ specs:
12
+ activesupport (7.0.3.1)
13
+ concurrent-ruby (~> 1.0, >= 1.0.2)
14
+ i18n (>= 1.6, < 2)
15
+ minitest (>= 5.1)
16
+ tzinfo (~> 2.0)
17
+ ast (2.4.2)
18
+ backport (1.2.0)
19
+ benchmark (0.2.0)
20
+ business_time (0.13.0)
21
+ activesupport (>= 3.2.0)
22
+ tzinfo
23
+ coderay (1.1.3)
24
+ concurrent-ruby (1.1.10)
25
+ diff-lcs (1.5.0)
26
+ e2mmap (0.1.0)
27
+ flt (1.5.4)
28
+ i18n (1.12.0)
29
+ concurrent-ruby (~> 1.0)
30
+ jaro_winkler (1.5.4)
31
+ json (2.6.2)
32
+ kramdown (2.4.0)
33
+ rexml
34
+ kramdown-parser-gfm (1.1.0)
35
+ kramdown (~> 2.0)
36
+ method_source (1.0.0)
37
+ mini_portile2 (2.8.0)
38
+ minitest (5.16.2)
39
+ nokogiri (1.13.8)
40
+ mini_portile2 (~> 2.8.0)
41
+ racc (~> 1.4)
42
+ parallel (1.22.1)
43
+ parser (3.1.2.0)
44
+ ast (~> 2.4.1)
45
+ pry (0.14.1)
46
+ coderay (~> 1.1)
47
+ method_source (~> 1.0)
48
+ racc (1.6.0)
49
+ rainbow (3.1.1)
50
+ rake (13.0.6)
51
+ regexp_parser (2.5.0)
52
+ reverse_markdown (2.1.1)
53
+ nokogiri
54
+ rexml (3.2.5)
55
+ rubocop (1.33.0)
56
+ json (~> 2.3)
57
+ parallel (~> 1.10)
58
+ parser (>= 3.1.0.0)
59
+ rainbow (>= 2.2.2, < 4.0)
60
+ regexp_parser (>= 1.8, < 3.0)
61
+ rexml (>= 3.2.5, < 4.0)
62
+ rubocop-ast (>= 1.19.1, < 2.0)
63
+ ruby-progressbar (~> 1.7)
64
+ unicode-display_width (>= 1.4.0, < 3.0)
65
+ rubocop-ast (1.19.1)
66
+ parser (>= 3.1.1.0)
67
+ rubocop-minitest (0.21.0)
68
+ rubocop (>= 0.90, < 2.0)
69
+ rubocop-performance (1.14.3)
70
+ rubocop (>= 1.7.0, < 2.0)
71
+ rubocop-ast (>= 0.4.0)
72
+ rubocop-rake (0.6.0)
73
+ rubocop (~> 1.0)
74
+ ruby-progressbar (1.11.0)
75
+ semver (1.0.1)
76
+ solargraph (0.45.0)
77
+ backport (~> 1.2)
78
+ benchmark
79
+ bundler (>= 1.17.2)
80
+ diff-lcs (~> 1.4)
81
+ e2mmap
82
+ jaro_winkler (~> 1.5)
83
+ kramdown (~> 2.3)
84
+ kramdown-parser-gfm (~> 1.1)
85
+ parser (~> 3.0)
86
+ reverse_markdown (>= 1.0.5, < 3)
87
+ rubocop (>= 0.52)
88
+ thor (~> 1.0)
89
+ tilt (~> 2.0)
90
+ yard (~> 0.9, >= 0.9.24)
91
+ thor (1.2.1)
92
+ tilt (2.0.11)
93
+ tzinfo (2.0.5)
94
+ concurrent-ruby (~> 1.0)
95
+ unicode-display_width (2.2.0)
96
+ webrick (1.7.0)
97
+ yard (0.9.28)
98
+ webrick (~> 1.7.0)
99
+
100
+ PLATFORMS
101
+ ruby
102
+
103
+ DEPENDENCIES
104
+ finrb!
105
+ minitest
106
+ pry
107
+ rake
108
+ rubocop
109
+ rubocop-minitest
110
+ rubocop-performance
111
+ rubocop-rake
112
+ semver
113
+ solargraph
114
+
115
+ BUNDLED WITH
116
+ 1.17.2
data/README.md ADDED
@@ -0,0 +1,99 @@
1
+ # finrb
2
+
3
+ Ruby gem for financial calculations/modeling.
4
+
5
+ finrb forked from the ruby [finance](https://github.com/Edward-Intelligence/finance) gem.
6
+
7
+ ## Overview
8
+
9
+ ### Features
10
+
11
+ Currently implemented features include:
12
+
13
+ * Uses the [flt](https://github.com/jgoizueta/flt) gem to ensure precision decimal arithmetic in all calculations.
14
+ * Fixed-rate mortgage amortization (30/360).
15
+ * Interest rates
16
+ * Various cash flow computations, such as NPV and IRR.
17
+ * Adjustable rate mortgage amortization.
18
+ * Payment modifications (i.e., how does paying an additional $75 per month affect the amortization?)
19
+ * Utils class provides basic financial calculation utilities (ported from R's [FinCal](https://github.com/felixfan/FinCal) library):
20
+ * Computing bank discount yield (BDY) for a T-bill
21
+ * Computing money market yield (MMY) for a T-bill
22
+ * Cash ratio - Liquidity ratios measure the firm's ability to satisfy its short-term obligations as they come due.
23
+ * Computing Coefficient of variation
24
+ * Cost of goods sold and ending inventory under three methods (FIFO,LIFO,Weighted average)
25
+ * Current ratio - Liquidity ratios measure the firm's ability to satisfy its short-term obligations as they come due.
26
+ * 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.
27
+ * Debt ratio - Solvency ratios measure the firm's ability to satisfy its long-term obligations.
28
+ * Diluted Earnings Per Share
29
+ * Computing the rate of return for each period
30
+ * Convert stated annual rate to the effective annual rate
31
+ * Convert stated annual rate to the effective annual rate with continuous compounding
32
+ * Bond-equivalent yield (BEY), 2 x the semiannual discount rate
33
+ * Computing HPR, the holding period return
34
+ * Equivalent/proportional Interest Rates
35
+ * Basic Earnings Per Share
36
+ * Financial leverage - Solvency ratios measure the firm's ability to satisfy its long-term obligations.
37
+ * Estimate future value (fv)
38
+ * Estimate future value of an annuity
39
+ * Estimate future value (fv) of a single sum
40
+ * Computing the future value of an uneven cash flow series
41
+ * Geometric mean return
42
+ * Gross profit margin - Evaluate a company's financial performance
43
+ * Harmonic mean, average price
44
+ * Computing HPR, the holding period return
45
+ * Bond-equivalent yield (BEY), 2 x the semiannual discount rate
46
+ * Convert holding period return to the effective annual rate
47
+ * Computing money market yield (MMY) for a T-bill
48
+ * Computing IRR, the internal rate of return
49
+ * Calculate the net increase in common shares from the potential exercise of stock options or warrants
50
+ * Long-term debt-to-equity - Solvency ratios measure the firm's ability to satisfy its long-term obligations.
51
+ * Computing HPR, the holding period return
52
+ * Estimate the number of periods
53
+ * Net profit margin - Evaluate a company's financial performance
54
+ * Computing NPV, the PV of the cash flows less the initial (time = 0) outlay
55
+ * Estimate period payment
56
+ * Estimate present value (pv)
57
+ * Estimate present value (pv) of an annuity
58
+ * Estimate present value of a perpetuity
59
+ * Estimate present value (pv) of a single sum
60
+ * Computing the present value of an uneven cash flow series
61
+ * Quick ratio - Liquidity ratios measure the firm's ability to satisfy its short-term obligations as they come due.
62
+ * Convert a given norminal rate to a continuous compounded rate
63
+ * Convert a given continuous compounded rate to a norminal rate
64
+ * Rate of return for a perpetuity
65
+ * Computing Sampling error
66
+ * Computing Roy's safety-first ratio
67
+ * Computing Sharpe Ratio
68
+ * Depreciation Expense Recognition - Straight-line depreciation (SL) allocates an equal amount of depreciation each year over the asset's useful life
69
+ * Total debt-to-equity - Solvency ratios measure the firm's ability to satisfy its long-term obligations.
70
+ * Computing TWRR, the time-weighted rate of return
71
+ * Calculate weighted average shares - weighted average number of common shares
72
+ * Weighted mean as a portfolio return
73
+
74
+ ### Configuration
75
+
76
+ In `config/initializers/finrb.rb` Finrb allows to set tolerance (eps) and default guess for IRR and XIRR calculations, such as:
77
+
78
+ ```ruby
79
+ Finrb.configure do |config|
80
+ config.eps = '1.0e-12'
81
+ config.guess = 0.5
82
+ config.business_days = false # only relevant when using Transaction object, skips weekends
83
+ config.periodic_compound = false # only relevant when using Transaction object
84
+ end
85
+ ```
86
+
87
+ ### API and examples
88
+
89
+ See [api.md](docs/api.md)
90
+
91
+ ## Resources
92
+
93
+ * [RubyGems Page](https://rubygems.org/gems/finrb)
94
+ * [Source Code](http://github.com/ncs1/finrb)
95
+ * [Bug Tracker](https://github.com/ncs1/finrb/issues)
96
+
97
+ ## License
98
+
99
+ See [COPYING](./COPYING) and [COPYING.LESSER](./COPYING.LESSER)
data/Rakefile ADDED
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rake'
4
+ require 'rake/testtask'
5
+
6
+ task default: [:test_units]
7
+
8
+ Rake::TestTask.new('test_units') do |t|
9
+ t.pattern = 'test/*.rb'
10
+ t.verbose = true
11
+ t.warning = true
12
+ end
13
+
14
+ namespace :docker do
15
+ desc 'Build docker instance'
16
+ task :build do
17
+ Dir.chdir(__dir__.to_s) do
18
+ system 'docker build --target development -t finrb:1.0 -f Dockerfile .'
19
+ end
20
+ end
21
+
22
+ desc 'Run test docker build'
23
+ task :test do
24
+ Dir.chdir(__dir__.to_s) do
25
+ system 'docker build --target testing -t finrb:1.0 -f Dockerfile .'
26
+ end
27
+ end
28
+
29
+ desc 'Run dev docker instance'
30
+ task :run do
31
+ system 'docker run --init -it --rm finrb:1.0'
32
+ end
33
+ end
data/docs/.gitkeep ADDED
File without changes