finance_math 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f49354650ef84948e84ed7c9b779c7ccc14caa14
4
+ data.tar.gz: 84b0ecbe335d4dbe1473e8042b8b54cfa1e1dbaa
5
+ SHA512:
6
+ metadata.gz: 1acd89e12dbb9083724014b867385f04723a07266274e5c0a6dd2716488a53b143594f6c5646f6b8d604f7638ab49f1f01024f97f4e27701d3e0b4f0f01a0ad2
7
+ data.tar.gz: ee94a8f06ee93ca2d47f7363a6294e02cfd4b85cd7fdb29b01c00112c2cbeb878e10a2bc86d1bfae7940fd3d7cc721545e212ef941eda0a9d598090de29ba254
data/.gitignore ADDED
@@ -0,0 +1,23 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ /vendor/bundle
20
+ *.so
21
+ *.o
22
+ *.a
23
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in finance_math.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Nebojsa Zoric
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,62 @@
1
+ ![Gem Version](https://img.shields.io/badge/finance_math-0.2-blue.svg)
2
+ ![Build Status](https://img.shields.io/badge/build-passing-green.svg)
3
+
4
+
5
+ ## What is FinanceMath?
6
+
7
+ FinanceMath is a Ruby library for mapping Exel functions. Due to lack such libraries to handle every day need, this library is created.
8
+
9
+ ## Installation
10
+
11
+ FinanceMath is available as a gem, to install it just install the gem:
12
+
13
+ gem install finance_math
14
+
15
+ If you're using Bundler, add the gem to Gemfile.
16
+
17
+ gem 'finance_math'
18
+
19
+ Run `bundle install`.
20
+
21
+ ## Basic Usage
22
+
23
+ Create an instance, and pass parameters for nominal annual rate, duration (in months), and amount of loan.
24
+
25
+ ```ruby
26
+
27
+ Loan.new(10.5, 12, 15000)
28
+ ```
29
+
30
+ ## Functions
31
+
32
+ This is the list of available functions.
33
+
34
+ ## PMT
35
+
36
+ Calculates the periodic payment for an annuity investment based on constant-amount periodic payments and a constant interest rate.
37
+
38
+ ```ruby
39
+
40
+ loan = Loan.new(10.5, 12, 15000)
41
+ loan.pmt
42
+ ```
43
+
44
+ ## Contributing
45
+
46
+ 1. Fork it ( https://github.com/kolosek/finance_math/fork )
47
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
48
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
49
+ 4. Push to the branch (`git push origin my-new-feature`)
50
+ 5. Create a new Pull Request
51
+
52
+ ## Tests
53
+
54
+ Please cover with tests your pull requests
55
+
56
+ ## License
57
+
58
+ MIT License. See LICENSE for details.
59
+
60
+ ## Copyright
61
+
62
+ Copyright (c) 2014-2015 Nebojsa Zoric, and Kolosek, Inc. (http://kolosek.com)
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new
5
+
6
+ task :default => :spec
7
+ task :test => :spec
@@ -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 'finance_math/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "finance_math"
8
+ spec.version = FinanceMath::VERSION
9
+ spec.authors = ["Nebojsa Zoric"]
10
+ spec.email = ["office@kolosek.com"]
11
+ spec.summary = %q{Finance library for Ruby.}
12
+ spec.description = %q{Implementation of Excel functions in Ruby language}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency 'rspec'
24
+ end
@@ -0,0 +1,5 @@
1
+ require "finance_math/version"
2
+
3
+ module FinanceMath
4
+ autoload :Loan, 'finance_math/loan'
5
+ end
@@ -0,0 +1,60 @@
1
+ module FinanceMath
2
+ # the Loan class provides an interface for working with interest rates.
3
+ # @api public
4
+ class Loan
5
+ # @return [Integer] the duration for which the rate is valid, in months
6
+ # @api public
7
+ attr_accessor :duration
8
+
9
+ # @return [Float] the amount of loan request
10
+ # @api public
11
+ attr_accessor :amount
12
+
13
+ # @return [Float] the nominal annual rate
14
+ # @api public
15
+ attr_accessor :nominal_rate
16
+
17
+ # @return [DecNum] the monthly rate
18
+ # @api public
19
+ attr_reader :monthly_rate
20
+
21
+
22
+
23
+ # create a new Loan instance
24
+ # @return [Loan]
25
+ # @param [Numeric] decimal value of the interest rate
26
+ # @param [Integer] Duration of the loan period
27
+ # @param [Float] Loan amount
28
+ # @example create a 10.5% Nominal rate
29
+ # Loan.new(10.5, 12, 1000)
30
+ # @see http://en.wikipedia.org/wiki/Nominal_interest_rate
31
+ # @api public
32
+
33
+ def initialize(nominal_rate, duration, amount)
34
+ @nominal_rate, @amount, @duration = nominal_rate.to_f, amount, duration
35
+ @monthly_rate = @nominal_rate / 100 / 12
36
+ end
37
+
38
+ def pmt(future_value=0, type=0)
39
+ ((@amount * interest(@monthly_rate, @duration) - future_value ) / ((1.0 + @monthly_rate * type) * fvifa(@monthly_rate, duration)))
40
+ end
41
+
42
+ protected
43
+
44
+ def pow1pm1(x, y)
45
+ (x <= -1) ? ((1 + x) ** y) - 1 : Math.exp(y * Math.log(1.0 + x)) - 1
46
+ end
47
+
48
+ def pow1p(x, y)
49
+ (x.abs > 0.5) ? ((1 + x) ** y) : Math.exp(y * Math.log(1.0 + x))
50
+ end
51
+
52
+ def interest(monthly_rate, duration)
53
+ pow1p(monthly_rate, duration)
54
+ end
55
+
56
+ def fvifa(monthly_rate, duration)
57
+ (monthly_rate == 0) ? duration : pow1pm1(monthly_rate, duration) / monthly_rate
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,3 @@
1
+ module FinanceMath
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+
3
+ describe Loan do
4
+ it "should return initial set nominal rate" do
5
+ loan = Loan.new(10, 12, 1000)
6
+ expect(loan.nominal_rate).to eq(10)
7
+ end
8
+
9
+ it "should return initial set duration period" do
10
+ loan = Loan.new(10, 12, 1000)
11
+ expect(loan.duration).to eq(12)
12
+ end
13
+
14
+ it "should return initial set amount loaned" do
15
+ loan = Loan.new(10, 12, 1000)
16
+ expect(loan.amount).to eq(1000)
17
+ end
18
+
19
+ context ".pmt" do
20
+
21
+ it "should return correct pmt value" do
22
+ loan = Loan.new(10, 12, 1000)
23
+ expect(loan.pmt).to eq(87.9158872300099)
24
+ end
25
+
26
+ it "should return correct pmt value" do
27
+ loan = Loan.new(0, 12, 1200)
28
+ expect(loan.pmt).to eq(100)
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,4 @@
1
+ require_relative '../lib/finance_math/loan.rb'
2
+ require 'finance_math'
3
+
4
+ include FinanceMath
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: finance_math
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Nebojsa Zoric
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-02-25 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.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '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: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Implementation of Excel functions in Ruby language
56
+ email:
57
+ - office@kolosek.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .gitignore
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - finance_math.gemspec
68
+ - lib/finance_math.rb
69
+ - lib/finance_math/loan.rb
70
+ - lib/finance_math/version.rb
71
+ - spec/lib/loan_spec.rb
72
+ - spec/spec_helper.rb
73
+ homepage: ''
74
+ licenses:
75
+ - MIT
76
+ metadata: {}
77
+ post_install_message:
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - '>='
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ requirements: []
92
+ rubyforge_project:
93
+ rubygems_version: 2.2.2
94
+ signing_key:
95
+ specification_version: 4
96
+ summary: Finance library for Ruby.
97
+ test_files:
98
+ - spec/lib/loan_spec.rb
99
+ - spec/spec_helper.rb