finance_math 1.0.1 → 1.0.2

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: d4ad290f93c61538088a542df817d1d3b527f287
4
- data.tar.gz: 1dcd17731cd9f09023fbf667358d4e01ecca95fd
3
+ metadata.gz: fadca1b8a2a0ba505f0e0ba580d771ae5f9956df
4
+ data.tar.gz: f8184187b70e375f2585e107d74af672f3fa09e9
5
5
  SHA512:
6
- metadata.gz: 4ac4c610dfb82ff5afce7e6361a04bd7e3e3c09a1e14d61bc3822278b7bc9d2857f1f8283f78484355313283068841da0595353e246aba1216e52ed8e1d15c2b
7
- data.tar.gz: 3be42c6b204dd638fdccac9fb13235429fd162ec10d33dd9d94e918722e9d13eed503b70019d6decf1dfb290856247f52f1ca63231e0243e969b19850c4b6fbe
6
+ metadata.gz: d76b7216a8f7133c212f712437f15348f9d985331282e80ee8982767e265e05b546f04d1a16d8e8d103200abe4ff829f59884000c4d32232d7a907e88d12eaf1
7
+ data.tar.gz: ac4b8cd68df8f2c6721cc0c78883a8aafa9d034b53fe410a40a67d878d5256fbd9923996d37e763a6d366686cb5cf5465587002442575d57580c1abcdb159e9e
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- ![Gem Version](https://img.shields.io/badge/finance_math-1.0-blue.svg)
1
+ [![Gem Version](https://badge.fury.io/rb/finance_math.svg)](http://badge.fury.io/rb/finance_math)
2
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
3
  [![Code Climate](https://codeclimate.com/github/kolosek/finance_math/badges/gpa.svg)](https://codeclimate.com/github/kolosek/finance_math)
4
4
 
@@ -22,21 +22,22 @@ Run `bundle install`.
22
22
  ## Basic Usage
23
23
 
24
24
  Create an instance, and pass parameters for nominal annual rate, duration (in months), and amount of loan.
25
+ Defaults are structure_fee = 5, currency protection = 3, so please update if you need other values.
25
26
 
26
27
  ```ruby
27
28
 
28
- Loan.new(10.5, 12, 15000)
29
+ Loan.new(nominal_rate: 10.5, duration: 12, amount: 15000)
29
30
  ```
30
31
 
31
32
  ## Advanced Usage
32
33
 
33
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.
34
35
 
35
- Defaults are bank fee = 5, currency protection = 3, so please update if you need other values.
36
+ Defaults are structure_fee = 5, currency protection = 3, so please update if you need other values.
36
37
 
37
38
  ```ruby
38
39
 
39
- Loan.new(10.5, 12, 15000, 5.1, 2.75, 25)
40
+ Loan.new(nominal_rate: 10.5, duration: 12, amount: 15000, structure_fee: 5.1, currency_protection: 2.75, fee: 25)
40
41
  ```
41
42
 
42
43
  ## Functions
@@ -49,7 +50,7 @@ Calculates the periodic payment for an annuity investment based on constant-amou
49
50
 
50
51
  ```ruby
51
52
 
52
- loan = Loan.new(10, 12, 1000)
53
+ loan = Loan.new(nominal_rate: 10, duration: 12, amount: 1000)
53
54
  loan.pmt
54
55
  # 87.9158872300099
55
56
 
@@ -61,11 +62,11 @@ Calculates the Annual Percentage Rate.
61
62
 
62
63
  ```ruby
63
64
 
64
- loan = Loan.new(13, 12, 10000)
65
+ loan = Loan.new(nominal_rate: 13, duration: 12, amount: 10000)
65
66
  loan.apr
66
67
  #29.179538647635006
67
68
 
68
- loan = Loan.new(15, 36, 10000, 5, 3, 10)
69
+ loan = Loan.new(nominal_rate: 15, duration: 36, amount: 10000, structure_fee: 5, currency_protection: 3, fee: 10)
69
70
  loan.apr
70
71
  #23.964418264624054
71
72
 
@@ -46,13 +46,21 @@ module FinanceMath
46
46
  # @see http://en.wikipedia.org/wiki/Nominal_interest_rate
47
47
  # @api public
48
48
 
49
- def initialize(nominal_rate, duration, amount, structure_fee=5, currency_protection=3, fee=0)
49
+ 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
50
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
51
57
  @principal = principal_calculation
52
58
  @monthly_rate = @nominal_rate / 100 / 12
53
59
  end
54
60
 
55
- def pmt(future_value=0, type=0)
61
+ def pmt(options = {})
62
+ future_value = options.fetch(:future_value, 0)
63
+ type = options.fetch(:type, 0)
56
64
  ((@amount * interest(@monthly_rate, @duration) - future_value ) / ((1.0 + @monthly_rate * type) * fvifa(@monthly_rate, duration)))
57
65
  end
58
66
 
@@ -1,3 +1,3 @@
1
1
  module FinanceMath
2
- VERSION = "1.0.1"
2
+ VERSION = "1.0.2"
3
3
  end
@@ -2,44 +2,44 @@ require 'spec_helper'
2
2
 
3
3
  describe Loan do
4
4
  it "should return initial set nominal rate" do
5
- loan = Loan.new(10, 12, 1000)
5
+ loan = Loan.new(nominal_rate: 10, duration: 12, amount: 1000)
6
6
  expect(loan.nominal_rate).to eq(10)
7
7
  end
8
8
 
9
9
  it "should return initial set duration period" do
10
- loan = Loan.new(10, 12, 1000)
10
+ loan = Loan.new(nominal_rate: 10, duration: 12, amount: 1000)
11
11
  expect(loan.duration).to eq(12)
12
12
  end
13
13
 
14
14
  it "should return initial set amount loaned" do
15
- loan = Loan.new(10, 12, 1000)
15
+ loan = Loan.new(nominal_rate: 10, duration: 12, amount: 1000)
16
16
  expect(loan.amount).to eq(1000)
17
17
  end
18
18
 
19
19
  context ".pmt" do
20
20
 
21
21
  it "should return correct pmt value" do
22
- loan = Loan.new(10, 12, 1000)
22
+ loan = Loan.new(nominal_rate: 10, duration: 12, amount: 1000)
23
23
  expect(loan.pmt).to eq(87.9158872300099)
24
24
  end
25
25
 
26
26
  it "should return correct pmt value" do
27
- loan = Loan.new(0, 12, 1200)
27
+ loan = Loan.new(nominal_rate: 0, duration: 12, amount: 1200)
28
28
  expect(loan.pmt).to eq(100)
29
29
  end
30
30
 
31
31
  it "should return correct pmt value" do
32
- loan = Loan.new(0, 36, 10000)
32
+ loan = Loan.new(nominal_rate: 0, duration: 36, amount: 10000)
33
33
  expect(loan.pmt).to eq(277.77777777777777)
34
34
  end
35
35
 
36
36
  it "should return correct pmt value" do
37
- loan = Loan.new(0, 6, 10000)
37
+ loan = Loan.new(nominal_rate: 0, duration: 6, amount: 10000)
38
38
  expect(loan.pmt).to eq(1666.6666666666667)
39
39
  end
40
40
 
41
41
  it "should return correct pmt value" do
42
- loan = Loan.new(13, 90, 1000000)
42
+ loan = Loan.new(nominal_rate: 13, duration: 90, amount: 1000000)
43
43
  expect(loan.pmt).to eq(17449.90775727763)
44
44
  end
45
45
  end
@@ -47,62 +47,62 @@ describe Loan do
47
47
  context ".apr, edge cases" do
48
48
 
49
49
  it "should return correct apr value" do
50
- loan = Loan.new(16, 24, 9200)
50
+ loan = Loan.new(nominal_rate: 16, duration: 24, amount: 9200)
51
51
  expect(loan.apr).to eq(24.699310868498614)
52
52
  end
53
53
 
54
54
  it "should return correct apr value" do
55
- loan = Loan.new(13, 24, 10000)
55
+ loan = Loan.new(nominal_rate: 13, duration: 24, amount: 10000)
56
56
  expect(loan.apr).to eq(21.589972932434698)
57
57
  end
58
58
 
59
59
  it "should return correct apr value" do
60
- loan = Loan.new(13, 18, 10000)
60
+ loan = Loan.new(nominal_rate: 13, duration: 18, amount: 10000)
61
61
  expect(loan.apr).to eq(24.1815502466296)
62
62
  end
63
63
 
64
64
  it "should return correct apr value" do
65
- loan = Loan.new(13, 12, 10000)
65
+ loan = Loan.new(nominal_rate: 13, duration: 12, amount: 10000)
66
66
  expect(loan.apr).to eq(29.179538647635006)
67
67
  end
68
68
 
69
69
  it "should return correct apr value" do
70
- loan = Loan.new(13, 6, 10000)
70
+ loan = Loan.new(nominal_rate: 13, duration: 6, amount: 10000)
71
71
  expect(loan.apr).to eq(42.82076503747119)
72
72
  end
73
73
 
74
74
  it "should return correct apr value" do
75
- loan = Loan.new(13, 36, 10000)
75
+ loan = Loan.new(nominal_rate: 13, duration: 36, amount: 10000)
76
76
  expect(loan.apr).to eq(18.93638316167774)
77
77
  end
78
78
 
79
79
  it "should return correct apr value" do
80
- loan = Loan.new(13, 90, 10000000)
80
+ loan = Loan.new(nominal_rate: 13, duration: 90, amount: 10000000)
81
81
  expect(loan.apr).to eq(15.690778147507167)
82
82
  end
83
83
 
84
84
  it "should return correct apr value" do
85
- loan = Loan.new(13, 90, 50000000)
85
+ loan = Loan.new(nominal_rate: 13, duration: 90, amount: 50000000)
86
86
  expect(loan.apr).to eq(15.690778147507167)
87
87
  end
88
88
 
89
89
  it "should return correct apr value" do
90
- loan = Loan.new(13, 1, 50000000)
90
+ loan = Loan.new(nominal_rate: 13, duration: 1, amount: 50000000)
91
91
  expect(loan.apr).to eq(118.47826151517138)
92
92
  end
93
93
 
94
94
  it "should return correct apr value" do
95
- loan = Loan.new(80, 1, 1000)
95
+ loan = Loan.new(nominal_rate: 80, duration: 1, amount: 1000)
96
96
  expect(loan.apr).to eq(191.30434783476406)
97
97
  end
98
98
 
99
99
  it "should return correct apr value" do
100
- loan = Loan.new(36, 200, 500)
100
+ loan = Loan.new(nominal_rate: 36, duration: 200, amount: 500)
101
101
  expect(loan.apr).to eq(39.173057290003044)
102
102
  end
103
103
 
104
104
  it "should return correct apr value" do
105
- loan = Loan.new(15, 36, 10000, 5, 3, 10)
105
+ loan = Loan.new(nominal_rate: 15, duration: 36, amount: 10000, structure_fee: 5, currency_protection: 3, fee: 10)
106
106
  expect(loan.apr).to eq(23.964418264624054)
107
107
  end
108
108
  end
metadata CHANGED
@@ -1,55 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: finance_math
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nebojsa Zoric
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-05 00:00:00.000000000 Z
11
+ date: 2015-03-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.6'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.6'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '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
40
  version: '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
47
  version: '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
54
  version: '0'
55
55
  description: 'Implementation of Loan/Mortgage functions in Ruby language. APR function
@@ -62,7 +62,7 @@ executables: []
62
62
  extensions: []
63
63
  extra_rdoc_files: []
64
64
  files:
65
- - .gitignore
65
+ - ".gitignore"
66
66
  - Gemfile
67
67
  - LICENSE.txt
68
68
  - README.md
@@ -83,12 +83,12 @@ require_paths:
83
83
  - lib
84
84
  required_ruby_version: !ruby/object:Gem::Requirement
85
85
  requirements:
86
- - - '>='
86
+ - - ">="
87
87
  - !ruby/object:Gem::Version
88
88
  version: '0'
89
89
  required_rubygems_version: !ruby/object:Gem::Requirement
90
90
  requirements:
91
- - - '>='
91
+ - - ">="
92
92
  - !ruby/object:Gem::Version
93
93
  version: '0'
94
94
  requirements: []