mortgage_calculations 0.2.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION +1 -1
- data/lib/mortgage_calc/mortgage_util.rb +11 -9
- data/mortgage_calculations.gemspec +3 -4
- data/spec/mortgage_calc/mortgage_util_spec.rb +12 -0
- metadata +27 -27
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.0
|
@@ -1,12 +1,13 @@
|
|
1
1
|
module MortgageCalc
|
2
2
|
class MortgageUtil
|
3
|
-
attr_accessor :loan_amount, :interest_rate, :period, :fee
|
3
|
+
attr_accessor :loan_amount, :borrowed_fees, :interest_rate, :period, :fee
|
4
4
|
|
5
|
-
def initialize(loan_amount, interest_rate, fee, period=360)
|
5
|
+
def initialize(loan_amount, interest_rate, fee, period=360, borrowed_fees=0)
|
6
6
|
self.loan_amount = Float(loan_amount.to_s)
|
7
7
|
self.interest_rate = Float(interest_rate.to_s)
|
8
8
|
self.period = Integer(period.to_s)
|
9
9
|
self.fee = Float(fee.to_s)
|
10
|
+
self.borrowed_fees = Float(borrowed_fees.to_s)
|
10
11
|
end
|
11
12
|
|
12
13
|
def apr
|
@@ -14,14 +15,11 @@ module MortgageCalc
|
|
14
15
|
end
|
15
16
|
|
16
17
|
def monthly_payment
|
17
|
-
@monthly_payment ||= calculate_monthly_payment(self.loan_amount, monthly_interest_rate, self.period)
|
18
|
+
@monthly_payment ||= calculate_monthly_payment(self.loan_amount + self.borrowed_fees, monthly_interest_rate, self.period)
|
18
19
|
end
|
19
20
|
|
20
|
-
|
21
|
-
|
22
|
-
end
|
23
|
-
|
24
|
-
private
|
21
|
+
private
|
22
|
+
|
25
23
|
def monthly_interest_rate
|
26
24
|
self.interest_rate / 100 / 12
|
27
25
|
end
|
@@ -29,7 +27,11 @@ module MortgageCalc
|
|
29
27
|
def calculate_monthly_payment(amount, monthly_rate, period)
|
30
28
|
amount * (monthly_rate/(1 - (1 + monthly_rate)**(-period)))
|
31
29
|
end
|
32
|
-
|
30
|
+
|
31
|
+
def monthly_payment_with_fees
|
32
|
+
@monthly_payment_with_fees ||= calculate_monthly_payment(self.loan_amount + fee, monthly_interest_rate, self.period)
|
33
|
+
end
|
34
|
+
|
33
35
|
# solves APR
|
34
36
|
# [a (1 + a)^N] / [(1 + a)^N - 1] - P/C = 0
|
35
37
|
# where a = APR/1200, N = period, P = monthly payment, C = loan_amount
|
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{mortgage_calculations}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.3.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Perry Hertler"]
|
12
|
-
s.date = %q{2011-
|
12
|
+
s.date = %q{2011-03-17}
|
13
13
|
s.description = %q{Utilities for Mortgage related calculations (APR and Monthly Payments)}
|
14
14
|
s.email = %q{perry@hertler.org}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -35,7 +35,7 @@ Gem::Specification.new do |s|
|
|
35
35
|
s.homepage = %q{http://www.pathf.com/blogs/2010/02/mortcalc-gem/}
|
36
36
|
s.licenses = ["MORExchange"]
|
37
37
|
s.require_paths = ["lib"]
|
38
|
-
s.rubygems_version = %q{1.
|
38
|
+
s.rubygems_version = %q{1.6.0}
|
39
39
|
s.summary = %q{Utilities for Mortgage related calculations (APR and Monthly Payments)}
|
40
40
|
s.test_files = [
|
41
41
|
"spec/mortgage_calc/mortgage_util_spec.rb",
|
@@ -43,7 +43,6 @@ Gem::Specification.new do |s|
|
|
43
43
|
]
|
44
44
|
|
45
45
|
if s.respond_to? :specification_version then
|
46
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
47
46
|
s.specification_version = 3
|
48
47
|
|
49
48
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
@@ -69,6 +69,18 @@ module MortgageCalc
|
|
69
69
|
@mortgage_util.period.class.should == Fixnum
|
70
70
|
end
|
71
71
|
end
|
72
|
+
|
73
|
+
context "when borrowed_fees is specified" do
|
74
|
+
before(:all) do
|
75
|
+
@mortgage_util = MortgageUtil.new(100_000, 6.0, 2_000, 360, 2_000)
|
76
|
+
end
|
77
|
+
it "should not use the borrowed_fees in APR calculation" do
|
78
|
+
@mortgage_util.apr.should be_within(0.00001).of(6.1857)
|
79
|
+
end
|
80
|
+
it "should use the borrowed_fees in monthly payment calculation" do
|
81
|
+
@mortgage_util.monthly_payment.should be_within(0.002).of(611.54)
|
82
|
+
end
|
83
|
+
end
|
72
84
|
end
|
73
85
|
|
74
86
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mortgage_calculations
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 19
|
5
|
+
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 3
|
9
|
+
- 0
|
10
|
+
version: 0.3.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Perry Hertler
|
@@ -15,14 +15,12 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-03-17 00:00:00 -05:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
|
-
prerelease: false
|
23
22
|
type: :development
|
24
|
-
|
25
|
-
version_requirements: &id001 !ruby/object:Gem::Requirement
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
26
24
|
none: false
|
27
25
|
requirements:
|
28
26
|
- - ~>
|
@@ -33,12 +31,12 @@ dependencies:
|
|
33
31
|
- 1
|
34
32
|
- 0
|
35
33
|
version: 2.1.0
|
36
|
-
|
37
|
-
|
34
|
+
version_requirements: *id001
|
35
|
+
name: rspec
|
38
36
|
prerelease: false
|
37
|
+
- !ruby/object:Gem::Dependency
|
39
38
|
type: :development
|
40
|
-
|
41
|
-
version_requirements: &id002 !ruby/object:Gem::Requirement
|
39
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
42
40
|
none: false
|
43
41
|
requirements:
|
44
42
|
- - ">="
|
@@ -47,12 +45,12 @@ dependencies:
|
|
47
45
|
segments:
|
48
46
|
- 0
|
49
47
|
version: "0"
|
50
|
-
|
51
|
-
|
48
|
+
version_requirements: *id002
|
49
|
+
name: cucumber
|
52
50
|
prerelease: false
|
51
|
+
- !ruby/object:Gem::Dependency
|
53
52
|
type: :development
|
54
|
-
|
55
|
-
version_requirements: &id003 !ruby/object:Gem::Requirement
|
53
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
56
54
|
none: false
|
57
55
|
requirements:
|
58
56
|
- - ~>
|
@@ -63,12 +61,12 @@ dependencies:
|
|
63
61
|
- 0
|
64
62
|
- 0
|
65
63
|
version: 1.0.0
|
66
|
-
|
67
|
-
|
64
|
+
version_requirements: *id003
|
65
|
+
name: bundler
|
68
66
|
prerelease: false
|
67
|
+
- !ruby/object:Gem::Dependency
|
69
68
|
type: :development
|
70
|
-
|
71
|
-
version_requirements: &id004 !ruby/object:Gem::Requirement
|
69
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
72
70
|
none: false
|
73
71
|
requirements:
|
74
72
|
- - ~>
|
@@ -79,12 +77,12 @@ dependencies:
|
|
79
77
|
- 5
|
80
78
|
- 1
|
81
79
|
version: 1.5.1
|
82
|
-
|
83
|
-
|
80
|
+
version_requirements: *id004
|
81
|
+
name: jeweler
|
84
82
|
prerelease: false
|
83
|
+
- !ruby/object:Gem::Dependency
|
85
84
|
type: :development
|
86
|
-
|
87
|
-
version_requirements: &id005 !ruby/object:Gem::Requirement
|
85
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
88
86
|
none: false
|
89
87
|
requirements:
|
90
88
|
- - ">="
|
@@ -93,7 +91,9 @@ dependencies:
|
|
93
91
|
segments:
|
94
92
|
- 0
|
95
93
|
version: "0"
|
96
|
-
|
94
|
+
version_requirements: *id005
|
95
|
+
name: rcov
|
96
|
+
prerelease: false
|
97
97
|
description: Utilities for Mortgage related calculations (APR and Monthly Payments)
|
98
98
|
email: perry@hertler.org
|
99
99
|
executables: []
|
@@ -148,7 +148,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
148
148
|
requirements: []
|
149
149
|
|
150
150
|
rubyforge_project:
|
151
|
-
rubygems_version: 1.
|
151
|
+
rubygems_version: 1.6.0
|
152
152
|
signing_key:
|
153
153
|
specification_version: 3
|
154
154
|
summary: Utilities for Mortgage related calculations (APR and Monthly Payments)
|