finance_math 1.0.2 → 1.0.6

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: fadca1b8a2a0ba505f0e0ba580d771ae5f9956df
4
- data.tar.gz: f8184187b70e375f2585e107d74af672f3fa09e9
2
+ SHA256:
3
+ metadata.gz: 96f21dff1ebfa8772bbe2a251e2c24d55c6430ec8e9fc39ca6175aced2aa0e8e
4
+ data.tar.gz: 5e45af7a4f350de830406dd7caa762c5590cbf7e2f4d70e859a810926acd5429
5
5
  SHA512:
6
- metadata.gz: d76b7216a8f7133c212f712437f15348f9d985331282e80ee8982767e265e05b546f04d1a16d8e8d103200abe4ff829f59884000c4d32232d7a907e88d12eaf1
7
- data.tar.gz: ac4b8cd68df8f2c6721cc0c78883a8aafa9d034b53fe410a40a67d878d5256fbd9923996d37e763a6d366686cb5cf5465587002442575d57580c1abcdb159e9e
6
+ metadata.gz: 305a7493c91b7a463d8d6543e4607f14dd403082fc044418f5ceac7b25ef9b911f643ac345e734f7b5ce58461ae6a46c5662209d62ba9a6052c1e48f0bfa3db4
7
+ data.tar.gz: 1e3fbdba12205a00495cdc030c8907afbdc57092b1b0be2b6c5ebbe5cead0091c3b93f16e01fa65ded5e6a7c21930e463d660fe2dc931971115c13f47f5ce4ec
@@ -0,0 +1,61 @@
1
+ # Ruby CircleCI 2.0 configuration file
2
+ #
3
+ # Check https://circleci.com/docs/2.0/language-ruby/ for more details
4
+ #
5
+ version: 2
6
+ jobs:
7
+ build:
8
+ docker:
9
+ # specify the version you desire here
10
+ - image: circleci/ruby:2.4.1-node-browsers
11
+
12
+ # Specify service dependencies here if necessary
13
+ # CircleCI maintains a library of pre-built images
14
+ # documented at https://circleci.com/docs/2.0/circleci-images/
15
+ # - image: circleci/postgres:9.4
16
+
17
+ working_directory: ~/repo
18
+
19
+ steps:
20
+ - checkout
21
+
22
+ # Download and cache dependencies
23
+ - restore_cache:
24
+ keys:
25
+ - v1-dependencies-{{ checksum "Gemfile.lock" }}
26
+ # fallback to using the latest cache if no exact match is found
27
+ - v1-dependencies-
28
+
29
+ - run:
30
+ name: install dependencies
31
+ command: |
32
+ bundle install --jobs=4 --retry=3 --path vendor/bundle
33
+
34
+ - save_cache:
35
+ paths:
36
+ - ./vendor/bundle
37
+ key: v1-dependencies-{{ checksum "Gemfile.lock" }}
38
+
39
+ # Database setup
40
+ - run: bundle exec rake db:create
41
+ - run: bundle exec rake db:schema:load
42
+
43
+ # run tests!
44
+ - run:
45
+ name: run tests
46
+ command: |
47
+ mkdir /tmp/test-results
48
+ TEST_FILES="$(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings)"
49
+
50
+ bundle exec rspec --format progress \
51
+ --format RspecJunitFormatter \
52
+ --out /tmp/test-results/rspec.xml \
53
+ --format progress \
54
+ $TEST_FILES
55
+
56
+ # collect reports
57
+ - store_test_results:
58
+ path: /tmp/test-results
59
+ - store_artifacts:
60
+ path: /tmp/test-results
61
+ destination: test-results
data/.gitlab-ci.yml ADDED
@@ -0,0 +1,15 @@
1
+ before_script:
2
+ - apt-get update -qq && apt-get install -y -qq sqlite3 libsqlite3-dev nodejs
3
+ - ruby -v
4
+ - which ruby
5
+ - gem install bundler --no-ri --no-rdoc
6
+ - bundle install --jobs $(nproc) "${FLAGS[@]}"
7
+
8
+ rspec:
9
+ script:
10
+ - bundle exec rspec
11
+
12
+ rubocop:
13
+ script:
14
+ - bundle exec rubocop
15
+
data/.tool-versions ADDED
@@ -0,0 +1 @@
1
+ ruby 3.3.0
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2015 Nebojsa Zoric
1
+ Copyright (c) 2015 Nebojsa Zoric/Kolosek
2
2
 
3
3
  MIT License
4
4
 
data/README.md CHANGED
@@ -1,11 +1,10 @@
1
1
  [![Gem Version](https://badge.fury.io/rb/finance_math.svg)](http://badge.fury.io/rb/finance_math)
2
- [![Build Status](https://semaphoreapp.com/api/v1/projects/869d7630-55d3-46e5-9dc2-03d0d1cfecfe/363108/shields_badge.svg)](https://semaphoreapp.com/kolosek/finance_math)
3
2
  [![Code Climate](https://codeclimate.com/github/kolosek/finance_math/badges/gpa.svg)](https://codeclimate.com/github/kolosek/finance_math)
4
3
 
5
4
 
6
5
  ## What is FinanceMath?
7
6
 
8
- FinanceMath is a Ruby library for mapping Loan based Exel functions. It deals with problem of calculating the PMT and APR functions. It implements advanced usage, taking into account bank fees, fee for for each payment and currency protection (if currency other than $ USD). Highly precise with high speed of execution.
7
+ FinanceMath is a Ruby library for mapping Loan based Exel functions. It deals with problem of calculating the PMT and APR functions. It implements advanced usage, taking into account bank fees, fee for for each payment and currency protection (if currency other than $ USD). Highly precise with high speed of execution.
9
8
 
10
9
  ## Installation
11
10
 
@@ -19,6 +18,10 @@ If you're using Bundler, add the gem to Gemfile.
19
18
 
20
19
  Run `bundle install`.
21
20
 
21
+ ## Running tests
22
+
23
+ bundle exec rspec spec/
24
+
22
25
  ## Basic Usage
23
26
 
24
27
  Create an instance, and pass parameters for nominal annual rate, duration (in months), and amount of loan.
@@ -26,47 +29,47 @@ Defaults are structure_fee = 5, currency protection = 3, so please update if you
26
29
 
27
30
  ```ruby
28
31
 
29
- Loan.new(nominal_rate: 10.5, duration: 12, amount: 15000)
32
+ FinanceMath::Loan.new(nominal_rate: 10.5, duration: 12, amount: 15000)
30
33
  ```
31
34
 
32
35
  ## Advanced Usage
33
36
 
34
- Create an instance, and pass parameters for nominal annual rate, duration (in months), and amount of loan, and additional values such as bank fee, currency protection, and fee for each monthly payment.
37
+ Create an instance, and pass parameters for nominal annual rate, duration (in months), and amount of loan, and additional values such as bank fee, currency protection, and fee for each monthly payment.
35
38
 
36
39
  Defaults are structure_fee = 5, currency protection = 3, so please update if you need other values.
37
40
 
38
41
  ```ruby
39
42
 
40
- Loan.new(nominal_rate: 10.5, duration: 12, amount: 15000, structure_fee: 5.1, currency_protection: 2.75, fee: 25)
43
+ FinanceMath::Loan.new(nominal_rate: 10.5, duration: 12, amount: 15000, structure_fee: 5.1, currency_protection: 2.75, fee: 25)
41
44
  ```
42
45
 
43
- ## Functions
46
+ ## Functions
44
47
 
45
48
  This is the list of available functions.
46
49
 
47
- ### Loan.pmt
50
+ ### FinanceMath::Loan.pmt
48
51
 
49
52
  Calculates the periodic payment for an annuity investment based on constant-amount periodic payments and a constant interest rate.
50
53
 
51
54
  ```ruby
52
55
 
53
- loan = Loan.new(nominal_rate: 10, duration: 12, amount: 1000)
56
+ loan = FinanceMath::Loan.new(nominal_rate: 10, duration: 12, amount: 1000)
54
57
  loan.pmt
55
58
  # 87.9158872300099
56
59
 
57
60
  ```
58
61
 
59
- ### Loan.apr
62
+ ### FinanceMath::Loan.apr
60
63
 
61
64
  Calculates the Annual Percentage Rate.
62
65
 
63
66
  ```ruby
64
67
 
65
- loan = Loan.new(nominal_rate: 13, duration: 12, amount: 10000)
68
+ loan = FinanceMath::Loan.new(nominal_rate: 13, duration: 12, amount: 10000)
66
69
  loan.apr
67
70
  #29.179538647635006
68
71
 
69
- loan = Loan.new(nominal_rate: 15, duration: 36, amount: 10000, structure_fee: 5, currency_protection: 3, fee: 10)
72
+ loan = FinanceMath::Loan.new(nominal_rate: 15, duration: 36, amount: 10000, structure_fee: 5, currency_protection: 3, fee: 10)
70
73
  loan.apr
71
74
  #23.964418264624054
72
75
 
@@ -84,11 +87,20 @@ loan.apr
84
87
 
85
88
  Please cover with tests your pull requests
86
89
 
87
- ## Copyright
90
+ ## Ruby versions
91
+
92
+ Currently supported version of 2.x and 3.x
93
+
94
+ ## Credits
95
+
96
+ Finance Math is maintained and sponsored by
97
+ [Kolosek] (http://kolosek.com).
98
+
99
+ ![Kolosek](http://kolosek.com/logo.png)
88
100
 
89
- Copyright (c) 2014-2015 Nebojsa Zoric, and Kolosek, Inc. (http://kolosek.com)
101
+ Initially developed by Nesha Zoric
90
102
 
91
- ###Follow up @nebojsaz and @kolosek
103
+ ###Follow up @kolosek
92
104
 
93
105
 
94
106
  ## License
data/finance_math.gemspec CHANGED
@@ -6,9 +6,9 @@ require 'version'
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "finance_math"
8
8
  spec.version = FinanceMath::VERSION
9
- spec.authors = ["Nebojsa Zoric"]
10
- spec.email = ["office@kolosek.com"]
11
- spec.summary = %q{Finance and mortgage library for Ruby.}
9
+ spec.authors = ["Nesha Zoric"]
10
+ spec.email = ["nesha@kolosek.com"]
11
+ spec.summary = %q{Most accurate APR and PMT caluclator for Ruby.}
12
12
  spec.description = %q{Implementation of Loan/Mortgage functions in Ruby language. APR function and PMT function. In calculations it includes implementation of bank fee, marketplace fee, fees for each payment to provide the most precise calculation at very high speed. }
13
13
  spec.homepage = "http://kolosek.com"
14
14
  spec.license = "MIT"
@@ -19,6 +19,6 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ["lib"]
20
20
 
21
21
  spec.add_development_dependency "bundler", "~> 1.6"
22
- spec.add_development_dependency "rake"
23
- spec.add_development_dependency 'rspec'
22
+ spec.add_development_dependency "rake", "~> 2.0"
23
+ spec.add_development_dependency 'rspec', "~> 2.0"
24
24
  end
@@ -13,18 +13,18 @@ module FinanceMath
13
13
  # @return [Float] the nominal annual rate
14
14
  # @api public
15
15
  attr_accessor :nominal_rate
16
-
16
+
17
17
  # @return [DecNum] the monthly rate
18
18
  # @api public
19
19
  attr_reader :monthly_rate
20
20
 
21
21
  # @return [DecNum] the currency protection
22
22
  # @api public
23
- attr_reader :currency_protection
23
+ attr_reader :currency_protection
24
24
 
25
25
  # @return [DecNum] the fee for the bank/market
26
26
  # @api public
27
- attr_reader :structure_fee
27
+ attr_reader :structure_fee
28
28
 
29
29
  # @return [DecNum] P principal
30
30
  # @api public
@@ -42,18 +42,11 @@ module FinanceMath
42
42
  # @param [Float] structure fee - fee for the market in percentages
43
43
  # @param [Float] currency protection - Protection for currency changes - usually 3%, default to 0%
44
44
  # @example create a 10.5% Nominal rate
45
- # Loan.new(10.5, 12, 1000)
46
45
  # @see http://en.wikipedia.org/wiki/Nominal_interest_rate
47
46
  # @api public
48
47
 
49
48
  def initialize(options = {})
50
- @nominal_rate = options.fetch(:nominal_rate).to_f
51
- @duration = options.fetch(:duration).to_f
52
- @amount = options.fetch(:amount).to_f
53
- @structure_fee = options.fetch(:structure_fee, 5).to_f
54
- @currency_protection = options.fetch(:currency_protection, 3).to_f
55
- @fee = options.fetch(:fee, 0).to_f
56
- @nominal_rate, @amount, @duration, @structure_fee, @currency_protection, @fee = nominal_rate.to_f, amount, duration, structure_fee.to_f, currency_protection.to_f, fee.to_f
49
+ initialize_options(options)
57
50
  @principal = principal_calculation
58
51
  @monthly_rate = @nominal_rate / 100 / 12
59
52
  end
@@ -73,21 +66,30 @@ module FinanceMath
73
66
  def pow1pm1(x, y)
74
67
  (x <= -1) ? ((1 + x) ** y) - 1 : Math.exp(y * Math.log(1.0 + x)) - 1
75
68
  end
76
-
69
+
77
70
  def pow1p(x, y)
78
71
  (x.abs > 0.5) ? ((1 + x) ** y) : Math.exp(y * Math.log(1.0 + x))
79
72
  end
80
-
73
+
81
74
  def interest(monthly_rate, duration)
82
75
  pow1p(monthly_rate, duration)
83
76
  end
84
-
77
+
85
78
  def fvifa(monthly_rate, duration)
86
79
  (monthly_rate == 0) ? duration : pow1pm1(monthly_rate, duration) / monthly_rate
87
80
  end
88
81
 
89
82
  private
90
83
 
84
+ def initialize_options(options)
85
+ @nominal_rate = options.fetch(:nominal_rate).to_f
86
+ @duration = options.fetch(:duration).to_f
87
+ @amount = options.fetch(:amount).to_f
88
+ @structure_fee = options.fetch(:structure_fee, 5).to_f
89
+ @currency_protection = options.fetch(:currency_protection, 3).to_f
90
+ @fee = options.fetch(:fee, 0).to_f
91
+ end
92
+
91
93
  def principal_calculation
92
94
  amount * (1 - currency_protection/100 - structure_fee / 100 ) - fee * duration
93
95
  end
@@ -97,8 +99,8 @@ module FinanceMath
97
99
  # where a = APR/1200, N = duration, P = monthly payment, C = loan_amount
98
100
  # Newton-Raphson finds root (the value for 'a' that makes f(a) = 0)
99
101
  def calculate_apr
100
- payment_ratio = pmt / principal_calculation
101
- duration = @duration
102
+ payment_ratio = pmt / principal_calculation
103
+ duration = @duration
102
104
  f = lambda {|k| (k**(duration + 1) - (k**duration * (payment_ratio + 1)) + payment_ratio)}
103
105
  f_deriv = lambda { |k| ((duration + 1) * k**duration) - (duration * (payment_ratio + 1) * k**(duration - 1))}
104
106
 
@@ -121,4 +123,4 @@ module FinanceMath
121
123
  k_plus_one
122
124
  end
123
125
  end
124
- end
126
+ end
data/lib/finance_math.rb CHANGED
@@ -2,5 +2,4 @@ require "version"
2
2
 
3
3
  module FinanceMath
4
4
  autoload :Loan, 'finance_math/loan'
5
- autoload :Mortgage, 'finance_math/mortgage'
6
5
  end
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module FinanceMath
2
- VERSION = "1.0.2"
2
+ VERSION = "1.0.6"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: finance_math
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.6
5
5
  platform: ruby
6
6
  authors:
7
- - Nebojsa Zoric
7
+ - Nesha Zoric
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-06 00:00:00.000000000 Z
11
+ date: 2024-07-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -28,41 +28,44 @@ dependencies:
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: '2.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: '0'
40
+ version: '2.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
47
+ version: '2.0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '0'
54
+ version: '2.0'
55
55
  description: 'Implementation of Loan/Mortgage functions in Ruby language. APR function
56
56
  and PMT function. In calculations it includes implementation of bank fee, marketplace
57
57
  fee, fees for each payment to provide the most precise calculation at very high
58
58
  speed. '
59
59
  email:
60
- - office@kolosek.com
60
+ - nesha@kolosek.com
61
61
  executables: []
62
62
  extensions: []
63
63
  extra_rdoc_files: []
64
64
  files:
65
+ - ".circleci/config.yml"
65
66
  - ".gitignore"
67
+ - ".gitlab-ci.yml"
68
+ - ".tool-versions"
66
69
  - Gemfile
67
70
  - LICENSE.txt
68
71
  - README.md
@@ -92,11 +95,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
92
95
  - !ruby/object:Gem::Version
93
96
  version: '0'
94
97
  requirements: []
95
- rubyforge_project:
96
- rubygems_version: 2.2.2
98
+ rubygems_version: 3.5.3
97
99
  signing_key:
98
100
  specification_version: 4
99
- summary: Finance and mortgage library for Ruby.
101
+ summary: Most accurate APR and PMT caluclator for Ruby.
100
102
  test_files:
101
103
  - spec/lib/loan_spec.rb
102
104
  - spec/spec_helper.rb