finance_velocity 2.0.3

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.
@@ -0,0 +1,72 @@
1
+ require_relative 'test_helper'
2
+
3
+ describe "Rates" do
4
+ describe "an interest rate" do
5
+ describe "can compound with different periods" do
6
+ it "should compound monthly by default" do
7
+ rate = Rate.new(0.15, :nominal)
8
+ assert_equal D('0.16075'), rate.effective.round(5)
9
+ end
10
+
11
+ it "should compound annually" do
12
+ rate = Rate.new(0.15, :nominal, :compounds => :annually)
13
+ assert_equal D('0.15'), rate.effective
14
+ end
15
+
16
+ it "should compound continuously" do
17
+ rate = Rate.new(0.15, :nominal, :compounds => :continuously)
18
+ assert_equal D('0.16183'), rate.effective.round(5)
19
+ end
20
+
21
+ it "should compound daily" do
22
+ rate = Rate.new(0.15, :nominal, :compounds => :daily)
23
+ assert_equal D('0.16180'), rate.effective.round(5)
24
+ end
25
+
26
+ it "should compound quarterly" do
27
+ rate = Rate.new(0.15, :nominal, :compounds => :quarterly)
28
+ assert_equal D('0.15865'), rate.effective.round(5)
29
+ end
30
+
31
+ it "should compound semiannually" do
32
+ rate = Rate.new(0.15, :nominal, :compounds => :semiannually)
33
+ assert_equal D('0.15563'), rate.effective.round(5)
34
+ end
35
+
36
+ it "should accept a numerical value as the compounding frequency per year" do
37
+ rate = Rate.new(0.15, :nominal, :compounds => 7)
38
+ assert_equal D('0.15999'), rate.effective.round(5)
39
+ end
40
+
41
+ it "should raise an exception if an unknown string is given" do
42
+ assert_raises(ArgumentError){ Rate.new(0.15, :nominal, :compounds => :quickly) }
43
+ end
44
+ end
45
+
46
+ it "should accept a duration if given" do
47
+ rate = Rate.new(0.0375, :effective, :duration => 360)
48
+ assert_equal 360, rate.duration
49
+ end
50
+
51
+ it "should be comparable to other interest rates" do
52
+ r1 = Rate.new(0.15, :nominal)
53
+ r2 = Rate.new(0.16, :nominal)
54
+ assert_equal( 1, r2 <=> r1)
55
+ assert_equal(-1, r1 <=> r2)
56
+ end
57
+
58
+ it "should convert to a monthly value" do
59
+ rate = Rate.new(0.0375, :effective)
60
+ assert_equal D('0.003125'), rate.monthly
61
+ end
62
+
63
+ it "should convert effective interest rates to nominal" do
64
+ assert_equal D('0.03687'), Rate.to_nominal(D('0.0375'), 12).round(5)
65
+ assert_equal D('0.03681'), Rate.to_nominal(D('0.0375'), Flt::DecNum.infinity).round(5)
66
+ end
67
+
68
+ it "should raise an exception if an unknown value is given for :type" do
69
+ assert_raises(ArgumentError){ Rate.new(0.0375, :foo) }
70
+ end
71
+ end
72
+ end
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: finance_velocity
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.0.3
5
+ platform: ruby
6
+ authors:
7
+ - Mani Bhushan
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-05-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: flt
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 1.3.0
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '1.3'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 1.3.0
33
+ - !ruby/object:Gem::Dependency
34
+ name: minitest
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '4.7'
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: 4.7.5
43
+ type: :development
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '4.7'
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 4.7.5
53
+ - !ruby/object:Gem::Dependency
54
+ name: activesupport
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - "~>"
58
+ - !ruby/object:Gem::Version
59
+ version: '4.0'
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: 4.0.0
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '4.0'
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: 4.0.0
73
+ description: The finance library provides a Ruby interface for working with interest
74
+ rates, mortgage amortization, and cashflows (NPV, IRR, etc.).
75
+ email: manilnct@gmail.com
76
+ executables: []
77
+ extensions: []
78
+ extra_rdoc_files:
79
+ - README.md
80
+ - COPYING
81
+ - COPYING.LESSER
82
+ - HISTORY
83
+ files:
84
+ - ".gitignore"
85
+ - ".rbenv-version"
86
+ - ".yardopts"
87
+ - COPYING
88
+ - COPYING.LESSER
89
+ - Gemfile
90
+ - HISTORY
91
+ - README.md
92
+ - Rakefile
93
+ - finance.gemspec
94
+ - lib/finance.rb
95
+ - lib/finance/amortization.rb
96
+ - lib/finance/cashflows.rb
97
+ - lib/finance/decimal.rb
98
+ - lib/finance/rates.rb
99
+ - lib/finance/transaction.rb
100
+ - test/test_amortization.rb
101
+ - test/test_cashflows.rb
102
+ - test/test_helper.rb
103
+ - test/test_rates.rb
104
+ homepage: https://rubygems.org/gems/finance
105
+ licenses:
106
+ - LGPL-3.0
107
+ metadata: {}
108
+ post_install_message:
109
+ rdoc_options: []
110
+ require_paths:
111
+ - lib
112
+ required_ruby_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '1.9'
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ requirements: []
123
+ rubygems_version: 3.4.12
124
+ signing_key:
125
+ specification_version: 4
126
+ summary: a library for financial modelling in Ruby.
127
+ test_files: []