exonio 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 869b6fadbc67f60c0e2f8b0e895729937d81fc4f
4
+ data.tar.gz: 130a055e7462d062ef80c08bb4047b290cbd9e1e
5
+ SHA512:
6
+ metadata.gz: 0e5a2f45443ff975165c2101ea57fc5397d8a3e3ee7c1cc93ede9119ab2d050d865a16a439e5c306ba26c3b898220a90a6385ed97176f8378c5dbaea1ba9782e
7
+ data.tar.gz: c0065bced80d07a240ca0c2a57a0a958207e300093dd09bbdea781dae432794e89d1705a116fb5a996326e1f47f755dbb39d03c237ae18800b65d009b89eca5f
@@ -0,0 +1,36 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+
13
+ ## Specific to RubyMotion:
14
+ .dat*
15
+ .repl_history
16
+ build/
17
+
18
+ ## Documentation cache and generated files:
19
+ /.yardoc/
20
+ /_yardoc/
21
+ /doc/
22
+ /rdoc/
23
+
24
+ ## Environment normalization:
25
+ /.bundle/
26
+ /vendor/bundle
27
+ /lib/bundler/man/
28
+
29
+ # for a library or gem, you might want to ignore these files since the code is
30
+ # intended to run in multiple environments; otherwise, check them in:
31
+ # Gemfile.lock
32
+ # .ruby-version
33
+ # .ruby-gemset
34
+
35
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
36
+ .rvmrc
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3.0
4
+ before_install: gem install bundler -v 1.11.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in exonio.gemspec
4
+ gemspec
@@ -0,0 +1,35 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ exonio (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.2.5)
10
+ rake (10.5.0)
11
+ rspec (3.4.0)
12
+ rspec-core (~> 3.4.0)
13
+ rspec-expectations (~> 3.4.0)
14
+ rspec-mocks (~> 3.4.0)
15
+ rspec-core (3.4.1)
16
+ rspec-support (~> 3.4.0)
17
+ rspec-expectations (3.4.0)
18
+ diff-lcs (>= 1.2.0, < 2.0)
19
+ rspec-support (~> 3.4.0)
20
+ rspec-mocks (3.4.1)
21
+ diff-lcs (>= 1.2.0, < 2.0)
22
+ rspec-support (~> 3.4.0)
23
+ rspec-support (3.4.1)
24
+
25
+ PLATFORMS
26
+ ruby
27
+
28
+ DEPENDENCIES
29
+ bundler (~> 1.11)
30
+ exonio!
31
+ rake (~> 10.0)
32
+ rspec (~> 3.0)
33
+
34
+ BUNDLED WITH
35
+ 1.11.2
@@ -0,0 +1,10 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Noverde Team.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
10
+
@@ -0,0 +1,108 @@
1
+ # Exonio
2
+
3
+ This gem brings some useful Excel formulas to Ruby. For now, it just has
4
+ financial formulas, but could have more (like statistical formulas) in the future.
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'exonio'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install exonio
21
+
22
+ ## Usage
23
+
24
+ To use Exonio you just have to call the method you like to use. Example:
25
+
26
+ ```ruby
27
+ Exonio.pmt(0.075 / 12, 12 * 15, 200_000) # ==> -1854.02
28
+ ```
29
+
30
+ ## Available Formulas
31
+
32
+ ### FV
33
+
34
+ What is the future value after 10 years of saving $100 now, with
35
+ an additional monthly savings of $100 with the interest rate at
36
+ 5% (annually) compounded monthly?
37
+
38
+ ```ruby
39
+ Exonio.fv(0.05 / 12, 10 * 12, -100, -100) # ==> 15692.93
40
+ ```
41
+
42
+ By convention, the negative sign represents cash flow out (i.e. money not
43
+ available today). Thus, saving $100 a month at 5% annual interest leads
44
+ to $15,692.93 available to spend in 10 years.
45
+
46
+ ### NPER
47
+
48
+ If you only had $150/month to pay towards the loan, how long would it take
49
+ to pay-off a loan of $8,000 at 7% annual interest?
50
+
51
+ ```ruby
52
+ Exonio.nper(0.07 / 12, -150, 8000) # ==> 64.07334877066185
53
+ ```
54
+
55
+ So, over 64 months would be required to pay off the loan.
56
+
57
+ ### PMT
58
+
59
+ What is the monthly payment needed to pay off a $200,000 loan in 15
60
+ years at an annual interest rate of 7.5%?
61
+
62
+ ```ruby
63
+ Exonio.nper(0.075 / 12, 12 * 15, 200_000) # ==> -1854.02
64
+ ```
65
+
66
+ In order to pay-off (i.e., have a future-value of 0) the $200,000 obtained
67
+ today, a monthly payment of $1,854.02 would be required. Note that this
68
+ example illustrates usage of `fv` (future value) having a default value of 0.
69
+
70
+ ## TODO
71
+
72
+ There's a lot of formulas to be implemented, including:
73
+
74
+ * ACCRINT
75
+ * ACCRINTM
76
+ * AMORDEGRC
77
+ * AMORLINC
78
+ * DB
79
+ * DDB
80
+ * IPMT
81
+ * IRR
82
+ * MIRR
83
+ * NPV
84
+ * PPMT
85
+ * PV
86
+ * RATE
87
+ * SLN
88
+ * SYD
89
+ * VDB
90
+
91
+ So feel free to pick one of those and open a pull request \o/.
92
+
93
+ ## Contributing
94
+ 1. Fork the repository
95
+ 2. Create a branch
96
+ 3. Hack hack hack...
97
+ 4. Create a spec
98
+ 5. Open a Pull Request ;)
99
+
100
+ ## License
101
+
102
+ Exonio is released under the MIT License.
103
+
104
+ ## Special Thanks
105
+
106
+ A special thanks goes to the python [NumPy project](http://www.numpy.org/), which was the source for most
107
+ of the formulas.
108
+
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
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
@@ -0,0 +1,8 @@
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
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'exonio/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "exonio"
8
+ spec.version = Exonio::VERSION
9
+ spec.authors = ["Rafael Izidoro"]
10
+ spec.email = ["izidoro.rafa@gmail.com"]
11
+
12
+ spec.summary = %q{Excel usefull formulas written in Ruby}
13
+ spec.description = %q{This gem implements some useful Excel formulas like PMT, IPMT, NPER, PV, etc...}
14
+ spec.homepage = "http://github.com/noverde/exonio"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.11"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rspec", "~> 3.0"
24
+ end
@@ -0,0 +1,6 @@
1
+ require "exonio/version"
2
+ require "exonio/financial"
3
+
4
+ module Exonio
5
+ extend Financial
6
+ end
@@ -0,0 +1,72 @@
1
+ module Exonio
2
+ module Financial
3
+ # Calculates the future value of an annuity investment based on
4
+ # constant-amount periodic payments and a constant interest rate.
5
+ #
6
+ # @param rate [Float] The interest rate as decimal (not per cent) per period
7
+ # @param nper [Integer] The number of compounding periods
8
+ # @param pmt [Float] The number of payments to be made
9
+ # @param pv [Float] The present value
10
+ # @param end_or_begining [Integer] Whether payments are due at the end (0) or
11
+ # beggining (1) of each period
12
+ #
13
+ # @return [Float]
14
+ #
15
+ # @example
16
+ # Exonio.fv(0.05 / 12, 12 * 10, -100, -100) # ==> 15692.93
17
+ #
18
+ def fv(rate, nper, pmt, pv, end_or_beginning = 0)
19
+ temp = (1 + rate) ** nper
20
+ fact = (1 + rate* end_or_beginning) * (temp - 1) / rate
21
+ result = -(pv * temp + pmt * fact)
22
+
23
+ result.round(2)
24
+ end
25
+
26
+
27
+ # Calculates the number of payment periods for an investment based on
28
+ # constant-amount periodic payments and a constant interest rate.
29
+ #
30
+ # @param rate [Float] The interest rate as decimal (not per cent) per period
31
+ # @param pmt [Float] The number of payments to be made
32
+ # @param pv [Float] The present value
33
+ # @param fv [Float] The future value remaining after the final payment has been made
34
+ # @param end_or_begining [Integer] Whether payments are due at the end (0) or
35
+ # beggining (1) of each period
36
+ #
37
+ # @return [Float]
38
+ #
39
+ # @example
40
+ # Exonio.nper(0.07 / 12, -150, 8000) # ==> 64.07334877066185
41
+ #
42
+ def nper(rate, pmt, pv, fv = 0, end_or_beginning = 0)
43
+ z = pmt * (1 + rate * end_or_beginning) / rate
44
+ temp = Math.log((-fv + z) / (pv + z))
45
+
46
+ temp / Math.log(1 + rate)
47
+ end
48
+
49
+ # Calculates the periodic payment for an annuity investment based on
50
+ # constant-amount periodic payments and a constant interest rate.
51
+ #
52
+ # @param rate [Float] The interest rate as decimal (not per cent) per period
53
+ # @param nper [Integer] The number of payments to be made (number of periods)
54
+ # @param pv [Float] The present value of the annuity
55
+ # @param fv [Float] The future value remaining after the final payment has been made
56
+ # @param end_or_begining [Integer] Whether payments are due at the end (0) or
57
+ # beggining (1) of each period
58
+ #
59
+ # @return [Float]
60
+ #
61
+ # @example
62
+ # Exonio.pmt(0.075/12, 12*15, 200_000) # ==> -1854.02
63
+ #
64
+ def pmt(rate, nper, pv, fv = 0, end_or_beginning = 0)
65
+ temp = (1 + rate) ** nper
66
+ fact = (1 + rate * end_or_beginning) * (temp - 1) / rate
67
+ result = -(fv + pv * temp) / fact
68
+
69
+ result.round(2)
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,3 @@
1
+ module Exonio
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: exonio
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Rafael Izidoro
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-01-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description: This gem implements some useful Excel formulas like PMT, IPMT, NPER,
56
+ PV, etc...
57
+ email:
58
+ - izidoro.rafa@gmail.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - ".rspec"
65
+ - ".travis.yml"
66
+ - Gemfile
67
+ - Gemfile.lock
68
+ - LICENSE.md
69
+ - README.md
70
+ - Rakefile
71
+ - bin/console
72
+ - bin/setup
73
+ - exonio.gemspec
74
+ - lib/exonio.rb
75
+ - lib/exonio/financial.rb
76
+ - lib/exonio/version.rb
77
+ homepage: http://github.com/noverde/exonio
78
+ licenses: []
79
+ metadata: {}
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ requirements: []
95
+ rubyforge_project:
96
+ rubygems_version: 2.5.1
97
+ signing_key:
98
+ specification_version: 4
99
+ summary: Excel usefull formulas written in Ruby
100
+ test_files: []