Skip to content
This repository has been archived by the owner on Sep 30, 2021. It is now read-only.

Commit

Permalink
Rename from Croovy::Finance to CroovyFinance
Browse files Browse the repository at this point in the history
The former was clashing with our Croovy app's namespace.
  • Loading branch information
Eric Wollesen committed Aug 12, 2013
1 parent a25de9d commit 0fcd668
Show file tree
Hide file tree
Showing 18 changed files with 73 additions and 83 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Croovy::Finance
# CroovyFinance

Brought to you by the good folks at [Croovy](http://croovy.com).

Expand All @@ -18,10 +18,10 @@ RATE function found in a Google Docs Spreadsheet or Microsoft Excel.
* https://support.google.com/drive/table/25273?hl=en
* http://office.microsoft.com/en-us/excel-help/rate-function-HP010342819.aspx

## How Croovy::Finance differs from Finance
## How CroovyFinance differs from Finance

The Finance gem uses Newton's method (while Croovy::Finance uses the secant
method), and as a result, Croovy::Finance's results are more inline with Excel
The Finance gem uses Newton's method (while CroovyFinance uses the secant
method), and as a result, CroovyFinance's results are more inline with Excel
and Google Docs. In the author's experience, certain reasonable inputs, when
used with the Finance gem, produced obviously incorrect results.

Expand All @@ -44,7 +44,7 @@ Or install it yourself as:
```ruby
irb(main):001:0> require "croovy/finance"
=> true
irb(main):002:0> Croovy::Finance::Apr.new(360, 1_044.50, 238_650).calc
irb(main):002:0> CroovyFinance::Apr.new(360, 1_044.50, 238_650).calc
=> 0.0027456868896171853
```

Expand Down
4 changes: 2 additions & 2 deletions croovy_finance.gemspec
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# coding: utf-8
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'croovy/finance/version'
require 'croovy_finance/version'

Gem::Specification.new do |spec|
spec.name = "croovy_finance"
spec.version = Croovy::Finance::VERSION
spec.version = CroovyFinance::VERSION
spec.authors = ["Eric Wollesen"]
spec.email = ["[email protected]"]
spec.description = %q{Financial calculations used by Croovy}
Expand Down
3 changes: 0 additions & 3 deletions lib/croovy.rb

This file was deleted.

10 changes: 0 additions & 10 deletions lib/croovy/finance.rb

This file was deleted.

5 changes: 0 additions & 5 deletions lib/croovy/finance/version.rb

This file was deleted.

7 changes: 7 additions & 0 deletions lib/croovy_finance.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module CroovyFinance
require_relative "croovy_finance/version"
require_relative "croovy_finance/npv"
require_relative "croovy_finance/secant"
require_relative "croovy_finance/irr"
require_relative "croovy_finance/apr"
end
4 changes: 2 additions & 2 deletions lib/croovy/finance/apr.rb → lib/croovy_finance/apr.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require_relative "irr"


class Croovy::Finance::Apr
class CroovyFinance::Apr

# Calculate the APR for a loan
#
Expand All @@ -20,7 +20,7 @@ def initialize(nper, pmt, pv)
end

def calc
Croovy::Finance::Irr.new(payments).calc
CroovyFinance::Irr.new(payments).calc
end


Expand Down
8 changes: 4 additions & 4 deletions lib/croovy/finance/irr.rb → lib/croovy_finance/irr.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
require_relative "npv"


class Croovy::Finance::Irr
class CroovyFinance::Irr

# Calculate the Internal Rate of Return for a loan
#
Expand All @@ -17,14 +17,14 @@ def calc(r_1=nil, r_2=nil)
r_1 ||= r_1_guess
r_2 ||= r_2_guess

Croovy::Finance::Secant.new.solve(npv, r_1, r_2)
CroovyFinance::Secant.new.solve(npv, r_1, r_2)
end


private

def npv
@npv ||= Croovy::Finance::Npv.new(@payments)
@npv ||= CroovyFinance::Npv.new(@payments)
end

def r_1_guess
Expand Down Expand Up @@ -53,7 +53,7 @@ def p
end

def npv_1_in
@npv_1_in ||= Croovy::Finance::Npv.new(@payments[1..-1])
@npv_1_in ||= CroovyFinance::Npv.new(@payments[1..-1])
end

end
2 changes: 1 addition & 1 deletion lib/croovy/finance/npv.rb → lib/croovy_finance/npv.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class Croovy::Finance::Npv
class CroovyFinance::Npv

# Calculate the Net Present Value of a time series of cash flows.
#
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class Croovy::Finance::Secant
class CroovyFinance::Secant

# Calculate the root of a function
#
Expand Down
3 changes: 3 additions & 0 deletions lib/croovy_finance/version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module CroovyFinance
VERSION = "0.0.1"
end
2 changes: 0 additions & 2 deletions test/croovy/finance.rb

This file was deleted.

18 changes: 0 additions & 18 deletions test/croovy/finance/irr_test.rb

This file was deleted.

25 changes: 0 additions & 25 deletions test/croovy/finance/npv_test.rb

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
require "minitest/autorun"
require_relative "../../../lib/croovy"
require_relative "../../lib/croovy_finance"


class TestApr < Minitest::Unit::TestCase

def test_apr
apr = Croovy::Finance::Apr.new(360, 1_044.50, 238_650)
apr = CroovyFinance::Apr.new(360, 1_044.50, 238_650)
result = apr.calc

assert_in_delta 0.002745656227846, result, 0.0000001
Expand All @@ -29,7 +29,7 @@ def test_apr_vs_calculations_spreadsheet
examples.each do |example|
periods, payment, value, expected_times_12 = example

result = Croovy::Finance::Apr.new(periods, payment, value).calc * 12
result = CroovyFinance::Apr.new(periods, payment, value).calc * 12

assert_in_delta expected_times_12, result, 0.000001
end
Expand Down
18 changes: 18 additions & 0 deletions test/croovy_finance/irr_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
require "minitest/autorun"
require_relative "../../lib/croovy_finance"


class TestIrr < Minitest::Unit::TestCase

def test_irr
irr = CroovyFinance::Irr.new([-4_000,
1200,
1410,
1875,
1050,])
result = irr.calc(0.25, 0.2)

assert_in_delta 0.142, result, 0.001
end

end
25 changes: 25 additions & 0 deletions test/croovy_finance/npv_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
require "minitest/autorun"
require_relative "../../lib/croovy_finance"


class TestNpv < Minitest::Unit::TestCase

def test_npv
npv = CroovyFinance::Npv.new([-100_000,
-54_672,
-39_161,
3_054,
7_128,
25_927,
28_838,
46_088,
77_076,
46_726,
76_852,
132_332,
166_047])

assert_in_delta 59_832.766488911, npv.call(0.1), 0.0000000001
end

end
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require "minitest/autorun"
require_relative "../../../lib/croovy"
require_relative "../../lib/croovy_finance"


class TestSecant < Minitest::Unit::TestCase
Expand All @@ -8,7 +8,7 @@ def test_secant
callable = proc {|x|
x ** 2.0 - 612
}
secant = Croovy::Finance::Secant.new
secant = CroovyFinance::Secant.new
result = secant.solve(callable, 30.0, 10.0)

assert_in_delta 24.7386, result, 0.0001
Expand Down

0 comments on commit 0fcd668

Please sign in to comment.