exonio 0.5.2 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 0f03859cf7c728a214f19e108e7a346635c5b419
4
- data.tar.gz: e9d6b0f50cfe6d1b3cc7ba0c9f4c61d5fd438aea
2
+ SHA256:
3
+ metadata.gz: 4c634f17bc1a7424b3be9e782fb72a8e226c4dd09a7b37d0dc71f026c2909b71
4
+ data.tar.gz: aa306d1c5dd6de8e32c06916057986291e551779293ceeed832100eacddf7c5b
5
5
  SHA512:
6
- metadata.gz: 69ea29ea9f2f79ff0f37754f3d9f3863f8923c35561911cdfbe909a158e80be56fa7aeb142050bb6da6fe58d6080667dc432512491b196d1258d59115bb74275
7
- data.tar.gz: 52172d1ba501744a5cc5d789f4ecc7f8acb6e2f5ad0a2271c2ec9d3c7f5a82c5b5659553cd5a39652daccc4fdef437b1a827ec43acdb4f31f6790b84637e325d
6
+ metadata.gz: 33ae1525fa62badfdc56d8203f4eab2d762f5284e4b4996b25b8a447c16f70c8beae9946137a03104e8c68c4c0c7131a70fc673fb26328faf9b74e2a42cc8035
7
+ data.tar.gz: e6b5907b0f28a7d235d462bbe3861398669d7339e0d77d0b3700cd906628a9d53660c51d5341915206bd6a32bc7dbbeec656e2ddfe4eb78d977914f3e8191496
@@ -0,0 +1,18 @@
1
+ version: 2
2
+
3
+ updates:
4
+ - open-pull-requests-limit: 10
5
+ package-ecosystem: "bundler"
6
+ directory: "/"
7
+ schedule:
8
+ interval: "monthly"
9
+ reviewers:
10
+ - "noverde/developers"
11
+
12
+ - open-pull-requests-limit: 10
13
+ package-ecosystem: "github-actions"
14
+ directory: "/"
15
+ schedule:
16
+ interval: "monthly"
17
+ reviewers:
18
+ - "noverde/developers"
@@ -0,0 +1,26 @@
1
+ name: RubyGem
2
+
3
+ on:
4
+ push:
5
+ tags:
6
+ - v*
7
+
8
+ jobs:
9
+ publish:
10
+ runs-on: ubuntu-latest
11
+
12
+ steps:
13
+ - uses: actions/checkout@v3
14
+
15
+ - name: Set up Ruby
16
+ uses: ruby/setup-ruby@v1
17
+ with:
18
+ ruby-version: "3.1"
19
+
20
+ - name: Install dependencies
21
+ run: bundle install
22
+
23
+ - name: Publish to RubyGems
24
+ uses: noverde/github-actions/push-rubygems@main
25
+ with:
26
+ rubygems_api_key: ${{ secrets.RUBYGEMS_TOKEN }}
@@ -0,0 +1,30 @@
1
+ name: Tests
2
+
3
+ on:
4
+ pull_request:
5
+ branches:
6
+ - main
7
+
8
+ jobs:
9
+ test:
10
+ strategy:
11
+ matrix:
12
+ os: [ubuntu-latest, macos-latest]
13
+ ruby: ["2.3.1", "2.7", "3.0", "3.1"]
14
+
15
+ runs-on: ${{ matrix.os }}
16
+
17
+ steps:
18
+ - uses: actions/checkout@v3
19
+
20
+ - name: Set up Ruby
21
+ uses: ruby/setup-ruby@v1
22
+ with:
23
+ ruby-version: ${{ matrix.ruby }}
24
+ bundler-cache: true
25
+
26
+ - name: Install dependencies
27
+ run: bundle install
28
+
29
+ - name: Run tests
30
+ run: bundle exec rake spec
data/.gitignore CHANGED
@@ -1,5 +1,6 @@
1
1
  *.gem
2
2
  *.rbc
3
+ bin/
3
4
  /.config
4
5
  /coverage/
5
6
  /InstalledFiles
@@ -29,8 +30,8 @@ build/
29
30
  # for a library or gem, you might want to ignore these files since the code is
30
31
  # intended to run in multiple environments; otherwise, check them in:
31
32
  # Gemfile.lock
32
- # .ruby-version
33
33
  # .ruby-gemset
34
+ .ruby-version
34
35
 
35
36
  # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
36
37
  .rvmrc
data/CHANGELOG.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 0.6.1
4
+
5
+ * Update dependencies (#25)
6
+
7
+ ## 0.6.0
8
+
9
+ * Implements `effect` method (#21)
10
+
11
+ ## 0.5.4
12
+
13
+ * Fix zero interest rate (#18)
14
+ * Remove BigDecimal.new deprecation warning (#17)
15
+
16
+ ## 0.5.3
17
+
18
+ * Fix error on IRR function
19
+
3
20
  ## 0.5.2
4
21
 
5
22
  * Fix the IRR method
data/Gemfile.lock CHANGED
@@ -1,37 +1,35 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- exonio (0.5.2)
4
+ exonio (0.6.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
- byebug (8.2.1)
10
- coderay (1.1.0)
11
- diff-lcs (1.2.5)
12
- method_source (0.8.2)
13
- pry (0.10.3)
14
- coderay (~> 1.1.0)
15
- method_source (~> 0.8.1)
16
- slop (~> 3.4)
9
+ byebug (8.2.5)
10
+ coderay (1.1.3)
11
+ diff-lcs (1.5.0)
12
+ method_source (1.0.0)
13
+ pry (0.14.1)
14
+ coderay (~> 1.1)
15
+ method_source (~> 1.0)
17
16
  pry-byebug (3.3.0)
18
17
  byebug (~> 8.0)
19
18
  pry (~> 0.10)
20
- rake (10.5.0)
21
- rspec (3.4.0)
22
- rspec-core (~> 3.4.0)
23
- rspec-expectations (~> 3.4.0)
24
- rspec-mocks (~> 3.4.0)
25
- rspec-core (3.4.1)
26
- rspec-support (~> 3.4.0)
27
- rspec-expectations (3.4.0)
19
+ rake (13.0.6)
20
+ rspec (3.11.0)
21
+ rspec-core (~> 3.11.0)
22
+ rspec-expectations (~> 3.11.0)
23
+ rspec-mocks (~> 3.11.0)
24
+ rspec-core (3.11.0)
25
+ rspec-support (~> 3.11.0)
26
+ rspec-expectations (3.11.0)
28
27
  diff-lcs (>= 1.2.0, < 2.0)
29
- rspec-support (~> 3.4.0)
30
- rspec-mocks (3.4.1)
28
+ rspec-support (~> 3.11.0)
29
+ rspec-mocks (3.11.1)
31
30
  diff-lcs (>= 1.2.0, < 2.0)
32
- rspec-support (~> 3.4.0)
33
- rspec-support (3.4.1)
34
- slop (3.6.0)
31
+ rspec-support (~> 3.11.0)
32
+ rspec-support (3.11.0)
35
33
 
36
34
  PLATFORMS
37
35
  ruby
@@ -40,8 +38,8 @@ DEPENDENCIES
40
38
  bundler (~> 1.11)
41
39
  exonio!
42
40
  pry-byebug (~> 3.3.0)
43
- rake (~> 10.0)
41
+ rake (~> 13.0)
44
42
  rspec (~> 3.0)
45
43
 
46
44
  BUNDLED WITH
47
- 1.11.2
45
+ 1.17.2
data/README.md CHANGED
@@ -3,6 +3,9 @@
3
3
  This gem brings some useful Excel formulas to Ruby. For now, it just has
4
4
  financial formulas, but could have more (like statistical formulas) in the future.
5
5
 
6
+ [![Gem Version](https://badge.fury.io/rb/exonio.svg)](https://badge.fury.io/rb/exonio)
7
+ [![Tests](https://github.com/noverde/exonio/actions/workflows/tests.yml/badge.svg)](https://github.com/noverde/exonio/actions)
8
+
6
9
  ## Installation
7
10
 
8
11
  Add this line to your application's Gemfile:
@@ -29,6 +32,16 @@ To use Exonio you just have to call the method you like to use. Example:
29
32
 
30
33
  ## Available Formulas
31
34
 
35
+ ### EFFECT
36
+
37
+ The Excel EFFECT function returns the effective annual interest rate, given a nominal interest rate and the number of compounding periods per year.
38
+ Effective annual interest rate is the interest rate actually earned due to compounding.
39
+ More about this function [EFFECT](https://exceljet.net/excel-functions/excel-effect-function)
40
+
41
+ ```ruby
42
+ Exonio.effect(0.05, 10 * 12) # ==> 0.05126014873337037
43
+ ```
44
+
32
45
  ### FV
33
46
 
34
47
  What is the future value after 10 years of saving $100 now, with
@@ -124,6 +137,20 @@ Exonio.rate(12 * 3, 2_500, -50_000) # ==> 0.036006853458478955
124
137
 
125
138
  So, the rate applied is 3.60%.
126
139
 
140
+ ## Statistical formulas
141
+
142
+ ### Sum
143
+ ```ruby
144
+ Exonio.sum([1, 2, 3, 4, 5]) # ==> 15
145
+ ```
146
+ ### Mean
147
+ ```ruby
148
+ Exonio.mean([1, 2, 3, 4, 5]) # ==> 3.0
149
+ ```
150
+ ### Median
151
+ ```ruby
152
+ Exonio.median([1, 2, 3, 6, 5, 4]) # ==> 3.5
153
+ ```
127
154
  ## TODO
128
155
 
129
156
  There's a lot of formulas to be implemented, including:
@@ -158,3 +185,4 @@ Exonio is released under the MIT License.
158
185
  A special thanks goes to the python [NumPy project](http://www.numpy.org/), which was the source for most
159
186
  of the formulas.
160
187
 
188
+
data/exonio.gemspec CHANGED
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ["lib"]
20
20
 
21
21
  spec.add_development_dependency "bundler", "~> 1.11"
22
- spec.add_development_dependency "rake", "~> 10.0"
22
+ spec.add_development_dependency "rake", "~> 13.0"
23
23
  spec.add_development_dependency "rspec", "~> 3.0"
24
24
  spec.add_development_dependency "pry-byebug", "~> 3.3.0"
25
25
  end
@@ -1,5 +1,22 @@
1
1
  module Exonio
2
2
  module Financial
3
+ # Calculates the effective annual interest rate, given a nominal interest rate and the number of
4
+ # compounding periods. Nominal interest rate is the stated rate on the financial product.
5
+ # Effective annual interest rate is the interest rate actually earned due to compounding.
6
+ # constant-amount periodic payments and a constant interest rate.
7
+ #
8
+ # @param rate [Float] The nominal interest rate as decimal (not per cent) per period
9
+ # @param nper [Integer] The number of compounding periods
10
+ #
11
+ # @return [Float]
12
+ #
13
+ # @example
14
+ # Exonio.effect(0.05, 12 * 10) # ==> 0.05126014873337037
15
+ #
16
+ def effect(rate, nper)
17
+ (1 + rate / nper) ** nper - 1
18
+ end
19
+
3
20
  # Calculates the future value of an annuity investment based on
4
21
  # constant-amount periodic payments and a constant interest rate.
5
22
  #
@@ -50,8 +67,8 @@ module Exonio
50
67
  # constant-amount periodic payments and a constant interest rate.
51
68
  #
52
69
  # @param rate [Float] The interest rate as decimal (not per cent) per period
53
- # @param pmt [Float] The number of payments to be made
54
- # @param pv [Float] The present value
70
+ # @param pmt [Float] The payment amount made each period
71
+ # @param pv [Float] The present value of the payments
55
72
  # @param fv [Float] The future value remaining after the final payment has been made
56
73
  # @param end_or_begining [Integer] Whether payments are due at the end (0) or
57
74
  # beggining (1) of each period
@@ -62,6 +79,8 @@ module Exonio
62
79
  # Exonio.nper(0.07 / 12, -150, 8000) # ==> 64.07334877066185
63
80
  #
64
81
  def nper(rate, pmt, pv, fv = 0, end_or_beginning = 0)
82
+ return (-pv - fv) / pmt if rate.zero?
83
+
65
84
  z = pmt * (1 + rate * end_or_beginning) / rate
66
85
  temp = Math.log((-fv + z) / (pv + z))
67
86
 
@@ -11,7 +11,7 @@ module Exonio
11
11
 
12
12
  values.each do |key, value|
13
13
  define_method key do
14
- BigDecimal.new(value)
14
+ BigDecimal(value)
15
15
  end
16
16
  end
17
17
 
@@ -21,7 +21,7 @@ module Exonio
21
21
 
22
22
  def values(x)
23
23
  value = Exonio.npv(x[0].to_f, @transactions)
24
- [ value ]
24
+ [ value.to_d ]
25
25
  end
26
26
  end
27
27
  end
@@ -0,0 +1,41 @@
1
+ module Exonio
2
+ module Statistical
3
+
4
+ # Sum of all numbers
5
+ #
6
+ # @param numbers_ary [array] and array of numbers to sum all elements
7
+ #
8
+ # @return [float]
9
+ #
10
+ # @example
11
+ # Exonio.sum([1,2,3,4,5]) # => 15
12
+ def sum(numbers_ary)
13
+ numbers_ary.inject(0, :+)
14
+ end
15
+
16
+ # Simple mean formula: sum elements and / by length
17
+ #
18
+ # @param numbers_ary [array] an array of numbers to calculate the mean
19
+ #
20
+ # @return [float]
21
+ #
22
+ # @example
23
+ # Exonio.mean([1,2,3,4,5]) # => 3.0
24
+ def mean(numbers_ary)
25
+ numbers_ary.inject(0) { |sum, i| sum + i }.to_f / numbers_ary.size
26
+ end
27
+
28
+ # Median formula
29
+ # @param numbers_ary [array] an array of numbers
30
+ #
31
+ # @return [float]
32
+ #
33
+ # @example
34
+ # Exonio.median([1,2,3,4,5]) # => 3.0
35
+ def median(numbers_ary)
36
+ numbers_ary.sort!
37
+ len = numbers_ary.length
38
+ (numbers_ary[(len - 1) / 2] + numbers_ary[len / 2]) / 2.0
39
+ end
40
+ end
41
+ end
@@ -1,3 +1,3 @@
1
1
  module Exonio
2
- VERSION = "0.5.2"
2
+ VERSION = "0.6.1"
3
3
  end
data/lib/exonio.rb CHANGED
@@ -1,11 +1,14 @@
1
1
  require 'bigdecimal'
2
2
  require 'bigdecimal/newton'
3
+ require "bigdecimal/util"
3
4
 
4
5
  require 'exonio/version'
5
6
  require 'exonio/financial'
6
- require 'exonio/helpers'
7
+ require 'exonio/statistical'
8
+ require 'exonio/helpers/irr_helper'
7
9
 
8
10
  module Exonio
9
11
  extend Newton
10
12
  extend Financial
13
+ extend Statistical
11
14
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: exonio
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rafael Izidoro
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-04-28 00:00:00.000000000 Z
11
+ date: 2022-08-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '10.0'
33
+ version: '13.0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '10.0'
40
+ version: '13.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -74,21 +74,22 @@ executables: []
74
74
  extensions: []
75
75
  extra_rdoc_files: []
76
76
  files:
77
+ - ".github/dependabot.yml"
78
+ - ".github/workflows/gem-push.yml"
79
+ - ".github/workflows/tests.yml"
77
80
  - ".gitignore"
78
81
  - ".rspec"
79
- - ".travis.yml"
80
82
  - CHANGELOG.md
81
83
  - Gemfile
82
84
  - Gemfile.lock
83
85
  - LICENSE.md
84
86
  - README.md
85
87
  - Rakefile
86
- - bin/console
87
- - bin/setup
88
88
  - exonio.gemspec
89
89
  - lib/exonio.rb
90
90
  - lib/exonio/financial.rb
91
- - lib/exonio/helpers.rb
91
+ - lib/exonio/helpers/irr_helper.rb
92
+ - lib/exonio/statistical.rb
92
93
  - lib/exonio/version.rb
93
94
  homepage: http://github.com/noverde/exonio
94
95
  licenses: []
@@ -108,8 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
108
109
  - !ruby/object:Gem::Version
109
110
  version: '0'
110
111
  requirements: []
111
- rubyforge_project:
112
- rubygems_version: 2.5.1
112
+ rubygems_version: 3.3.7
113
113
  signing_key:
114
114
  specification_version: 4
115
115
  summary: Excel usefull formulas written in Ruby
data/.travis.yml DELETED
@@ -1,4 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 2.3.0
4
- before_install: gem install bundler -v 1.11.2
data/bin/console DELETED
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "bundler/setup"
4
- require "exonio"
5
-
6
- # You can add fixtures and/or initialization code here to make experimenting
7
- # with your gem easier. You can also use a different console, if you like.
8
-
9
- # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require "pry"
11
- # Pry.start
12
-
13
- require "irb"
14
- IRB.start
data/bin/setup DELETED
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
7
-
8
- # Do any other automated setup that you need to do here