finance 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/COPYING +674 -0
- data/COPYING.LESSER +165 -0
- data/README +57 -13
- data/lib/amortization.rb +91 -0
- data/lib/cashflows.rb +33 -0
- data/lib/finance.rb +5 -35
- data/lib/rates.rb +89 -0
- data/lib/timespan.rb +10 -0
- data/test/test_amortization.rb +38 -0
- data/test/test_cashflows.rb +14 -0
- data/test/test_rates.rb +31 -0
- data/test/test_timespan.rb +12 -0
- metadata +36 -11
data/lib/timespan.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'finance'
|
3
|
+
require 'flt/d'
|
4
|
+
require 'test/unit'
|
5
|
+
|
6
|
+
class TestBasicAmortization < Test::Unit::TestCase
|
7
|
+
def setup
|
8
|
+
@rate = Rate.new(0.0375, :apr, :duration => 30.years)
|
9
|
+
@amortization = Amortization.new(D(200000), @rate)
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_balance
|
13
|
+
assert_equal D(0), @amortization.balance
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_interest_sum
|
17
|
+
assert_equal D('133443.53'), @amortization.interest.sum
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_payment
|
21
|
+
assert_equal D('-926.23'), @amortization.payment
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_payments
|
25
|
+
payments = [ D('-926.23') ] * @rate.duration
|
26
|
+
# Account for rounding errors in last payment.
|
27
|
+
payments[-1] = D('-926.96')
|
28
|
+
assert_equal payments, @amortization.payments
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_payments_sum
|
32
|
+
assert_equal D('-333443.53'), @amortization.payments.sum
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_principal
|
36
|
+
assert_equal D(200000), @amortization.principal
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'cashflows'
|
2
|
+
require 'test/unit'
|
3
|
+
|
4
|
+
class TestIRR < Test::Unit::TestCase
|
5
|
+
def test_simple
|
6
|
+
assert_in_delta(0.143, [-4000,1200,1410,1875,1050].irr, 0.001)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
class TestNPV < Test::Unit::TestCase
|
11
|
+
def test_simple
|
12
|
+
assert_in_delta(49.211, [-100.0, 60, 60, 60].npv(0.1), 0.001)
|
13
|
+
end
|
14
|
+
end
|
data/test/test_rates.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'finance'
|
3
|
+
require 'flt/d'
|
4
|
+
require 'test/unit'
|
5
|
+
|
6
|
+
class TestRates < Test::Unit::TestCase
|
7
|
+
def test_apr
|
8
|
+
rate = Rate.new(0.0375, :apr)
|
9
|
+
assert_equal D('0.03687'), rate.nominal.round(5)
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_duration
|
13
|
+
rate = Rate.new(0.0375, :effective, :duration => 30.years)
|
14
|
+
assert_equal 360, rate.duration
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_effective
|
18
|
+
rate = Rate.new(0.03687, :nominal)
|
19
|
+
assert_equal D('0.0375'), rate.effective.round(4)
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_monthly
|
23
|
+
rate = Rate.new(0.0375, :effective)
|
24
|
+
assert_equal D('0.003125'), rate.monthly
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_nominal
|
28
|
+
rate = Rate.new(0.0375, :effective)
|
29
|
+
assert_equal D('0.03687'), rate.nominal.round(5)
|
30
|
+
end
|
31
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: finance
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
- 0
|
9
8
|
- 1
|
10
|
-
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Bill Kranec
|
@@ -15,10 +15,25 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-06-
|
19
|
-
dependencies:
|
20
|
-
|
21
|
-
|
18
|
+
date: 2011-06-21 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: flt
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 27
|
29
|
+
segments:
|
30
|
+
- 1
|
31
|
+
- 3
|
32
|
+
- 0
|
33
|
+
version: 1.3.0
|
34
|
+
type: :runtime
|
35
|
+
version_requirements: *id001
|
36
|
+
description: The finance library provides a Ruby interface for working with interest rates, mortgage amortization, and cashflows (NPV, IRR, etc.).
|
22
37
|
email: wkranec@gmail.com
|
23
38
|
executables: []
|
24
39
|
|
@@ -27,9 +42,19 @@ extensions: []
|
|
27
42
|
extra_rdoc_files:
|
28
43
|
- README
|
29
44
|
files:
|
30
|
-
- lib/finance.rb
|
31
45
|
- README
|
32
|
-
|
46
|
+
- COPYING
|
47
|
+
- COPYING.LESSER
|
48
|
+
- lib/amortization.rb
|
49
|
+
- lib/cashflows.rb
|
50
|
+
- lib/finance.rb
|
51
|
+
- lib/rates.rb
|
52
|
+
- lib/timespan.rb
|
53
|
+
- test/test_amortization.rb
|
54
|
+
- test/test_cashflows.rb
|
55
|
+
- test/test_rates.rb
|
56
|
+
- test/test_timespan.rb
|
57
|
+
homepage: https://rubygems.org/gems/finance
|
33
58
|
licenses: []
|
34
59
|
|
35
60
|
post_install_message:
|
@@ -57,10 +82,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
57
82
|
version: "0"
|
58
83
|
requirements: []
|
59
84
|
|
60
|
-
rubyforge_project:
|
85
|
+
rubyforge_project:
|
61
86
|
rubygems_version: 1.8.5
|
62
87
|
signing_key:
|
63
88
|
specification_version: 3
|
64
|
-
summary:
|
89
|
+
summary: a library for financial calculations in Ruby.
|
65
90
|
test_files: []
|
66
91
|
|