finance_math 1.0.2 → 1.0.5

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
2
  SHA1:
3
- metadata.gz: fadca1b8a2a0ba505f0e0ba580d771ae5f9956df
4
- data.tar.gz: f8184187b70e375f2585e107d74af672f3fa09e9
3
+ metadata.gz: e0dbd1b8673be65abee43145026f4aaf8b93ca33
4
+ data.tar.gz: f7dc075d28a331f0cbad6075151524e0110790b5
5
5
  SHA512:
6
- metadata.gz: d76b7216a8f7133c212f712437f15348f9d985331282e80ee8982767e265e05b546f04d1a16d8e8d103200abe4ff829f59884000c4d32232d7a907e88d12eaf1
7
- data.tar.gz: ac4b8cd68df8f2c6721cc0c78883a8aafa9d034b53fe410a40a67d878d5256fbd9923996d37e763a6d366686cb5cf5465587002442575d57580c1abcdb159e9e
6
+ metadata.gz: 569f17be14ee3fd2c11f2df6aa3bc3a700680f19c871a9a77314026dda99ca321612a5925d170b2b00584b09aed782463c266c16b0ddc85897dc657f1c64541f
7
+ data.tar.gz: 36a525578e90f6aaf2eb37d8b3d65efc5ee7b04b79a21eae87c09722fd175bcb70e0e0f4fd0fc5354c7a9b1ba5a5561a3d984c0287f5009362033ed6a8325a51
@@ -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
@@ -5,7 +5,7 @@
5
5
 
6
6
  ## What is FinanceMath?
7
7
 
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.
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.
9
9
 
10
10
  ## Installation
11
11
 
@@ -19,6 +19,10 @@ If you're using Bundler, add the gem to Gemfile.
19
19
 
20
20
  Run `bundle install`.
21
21
 
22
+ ## Running tests
23
+
24
+ bundle exec rspec spec/
25
+
22
26
  ## Basic Usage
23
27
 
24
28
  Create an instance, and pass parameters for nominal annual rate, duration (in months), and amount of loan.
@@ -31,7 +35,7 @@ Loan.new(nominal_rate: 10.5, duration: 12, amount: 15000)
31
35
 
32
36
  ## Advanced Usage
33
37
 
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.
38
+ 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
39
 
36
40
  Defaults are structure_fee = 5, currency protection = 3, so please update if you need other values.
37
41
 
@@ -40,7 +44,7 @@ Defaults are structure_fee = 5, currency protection = 3, so please update if you
40
44
  Loan.new(nominal_rate: 10.5, duration: 12, amount: 15000, structure_fee: 5.1, currency_protection: 2.75, fee: 25)
41
45
  ```
42
46
 
43
- ## Functions
47
+ ## Functions
44
48
 
45
49
  This is the list of available functions.
46
50
 
@@ -84,9 +88,18 @@ loan.apr
84
88
 
85
89
  Please cover with tests your pull requests
86
90
 
87
- ## Copyright
91
+ ## Ruby versions
92
+
93
+ Currently supported up to 2.4.1
94
+
95
+ ## Credits
96
+
97
+ Finance Math is maintained and sponsored by
98
+ [Kolosek] (http://kolosek.com).
99
+
100
+ ![Kolosek](http://kolosek.com/logo.png)
88
101
 
89
- Copyright (c) 2014-2015 Nebojsa Zoric, and Kolosek, Inc. (http://kolosek.com)
102
+ Initially developed by Nebojsa Zoric
90
103
 
91
104
  ###Follow up @nebojsaz and @kolosek
92
105
 
@@ -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"
@@ -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
@@ -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
@@ -1,3 +1,3 @@
1
1
  module FinanceMath
2
- VERSION = "1.0.2"
2
+ VERSION = "1.0.5"
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.5
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: 2017-08-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -57,7 +57,7 @@ description: 'Implementation of Loan/Mortgage functions in Ruby language. APR fu
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: []
@@ -93,10 +93,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
93
93
  version: '0'
94
94
  requirements: []
95
95
  rubyforge_project:
96
- rubygems_version: 2.2.2
96
+ rubygems_version: 2.6.11
97
97
  signing_key:
98
98
  specification_version: 4
99
- summary: Finance and mortgage library for Ruby.
99
+ summary: Most accurate APR and PMT caluclator for Ruby.
100
100
  test_files:
101
101
  - spec/lib/loan_spec.rb
102
102
  - spec/spec_helper.rb