cash_flow_analysis 0.1.0 → 0.2.0

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: 2b3168369c2bf3f70bd53f6bb2aab55b40de177c
4
- data.tar.gz: 00c14fbfd6c104881d33a3878938c7012cfdcb17
3
+ metadata.gz: 6733d7147f9960c3406bc16a6d0cadfc47d2f13b
4
+ data.tar.gz: 6a596b24bb14ce9a3e6590ff0c27a84c5298d737
5
5
  SHA512:
6
- metadata.gz: aa8a365bcc767a0267aee8f2ce0f11a63d2c67bd47e6849bce0ee88f3abbdad32b0ceca1c67054b4ccbb3c43d0531a1eecb0eb93e61853e3dffa7ed4381a7387
7
- data.tar.gz: 3668b7a5ae6292a4407d5c3a1d316a8e1febdc8c9bc6be96ea324e67287611792026ec7fc485556e429bca13990ec250c641f29b0c4064851209dd6be850befd
6
+ metadata.gz: 3b452a60589f5a23eb56cca2ee89ec4412e88222bad6dc8ebce1239de2689b1b46bfe9259df7d693b29c286babc2aabbef92abab7431a9db49ab48ea9663856f
7
+ data.tar.gz: 8c9f9383465b66516ea18401994a1179c44a8da34a1b02ba9ab03a9e7e24ebd3b02ac7da937fcfced10f270be6e89961a67459c10fdd2ef43979c69e03d59518
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # CashFlowAnalysis
2
2
 
3
+ [![Build Status](https://travis-ci.org/hightower/cash_flow_analysis.svg?branch=master)](https://travis-ci.org/hightower/cash_flow_analysis)
4
+
3
5
  Ruby implementation of various financial analysis functions.
4
6
 
5
7
  ## Installation
@@ -40,21 +42,6 @@ CashFlowAnalysis::Calculator::Payment.calculate(10000, 60, 0.025)
40
42
  # 323.5339590005929
41
43
  ```
42
44
 
43
- ### XIRR
44
-
45
- Calculates the [XIRR](http://en.wikipedia.org/wiki/Internal_rate_of_return), assuming irregularly timed cash flows.
46
-
47
- ```
48
- items = []
49
- items << OpenStruct.new(date: Date.new(2008, 1, 1), amount: -10000)
50
- items << OpenStruct.new(date: Date.new(2008, 3, 1), amount: 2750)
51
- items << OpenStruct.new(date: Date.new(2008, 10, 30), amount: 4250)
52
- items << OpenStruct.new(date: Date.new(2009, 2, 15), amount: 3250)
53
- items << OpenStruct.new(date: Date.new(2009, 4, 1), amount: 2750)
54
- CashFlowAnalysis::Calculator::Xirr.calculate(items)
55
- # 0.373362533517793504136316860945228...
56
- ```
57
-
58
45
  ### XNPV
59
46
 
60
47
  Calculates the [XNPV](http://en.wikipedia.org/wiki/Net_present_value), assuming irregularly timed cash flows.
data/Rakefile CHANGED
@@ -1,2 +1,13 @@
1
1
  require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
2
3
 
4
+ desc "Run all specs in spec/"
5
+ task :spec do
6
+ RSpec::Core::RakeTask.new(:spec) do |t|
7
+ t.fail_on_error = true
8
+ t.pattern = "./spec/**/*_spec.rb"
9
+ t.rspec_opts = %w[--color]
10
+ end
11
+ end
12
+
13
+ task default: [:spec]
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_development_dependency "bundler", "~> 1.8"
21
+ spec.add_development_dependency "bundler", ">= 1.7"
22
22
  spec.add_development_dependency "pry", "~> 0"
23
23
  spec.add_development_dependency "rake", "~> 10.0"
24
24
  spec.add_development_dependency "rspec", "~> 3.2"
@@ -1,7 +1,4 @@
1
1
  require "cash_flow_analysis/version"
2
- require "cash_flow_analysis/calculation_error"
3
2
  require "cash_flow_analysis/calculator/cagr"
4
3
  require "cash_flow_analysis/calculator/payment"
5
- require "cash_flow_analysis/calculator/xirr"
6
4
  require "cash_flow_analysis/calculator/xnpv"
7
- require "cash_flow_analysis/util/objective_function"
@@ -1,3 +1,3 @@
1
1
  module CashFlowAnalysis
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cash_flow_analysis
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hightower
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-03-06 00:00:00.000000000 Z
11
+ date: 2015-03-09 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
- version: '1.8'
19
+ version: '1.7'
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
- version: '1.8'
26
+ version: '1.7'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: pry
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -85,12 +85,9 @@ files:
85
85
  - bin/setup
86
86
  - cash_flow_analysis.gemspec
87
87
  - lib/cash_flow_analysis.rb
88
- - lib/cash_flow_analysis/calculation_error.rb
89
88
  - lib/cash_flow_analysis/calculator/cagr.rb
90
89
  - lib/cash_flow_analysis/calculator/payment.rb
91
- - lib/cash_flow_analysis/calculator/xirr.rb
92
90
  - lib/cash_flow_analysis/calculator/xnpv.rb
93
- - lib/cash_flow_analysis/util/objective_function.rb
94
91
  - lib/cash_flow_analysis/version.rb
95
92
  homepage: https://github.com/hightower/cash_flow_analysis
96
93
  licenses:
@@ -1,8 +0,0 @@
1
- module CashFlowAnalysis
2
- class CalculationError < StandardError
3
- def initializer(error)
4
- @cause = cause
5
- super "An error occurred performing the calculation. See the cause property for further information"
6
- end
7
- end
8
- end
@@ -1,29 +0,0 @@
1
- require "bigdecimal/newton"
2
-
3
- module CashFlowAnalysis
4
- module Calculator
5
- module Xirr
6
- extend Newton
7
-
8
- # Calculates the {http://en.wikipedia.org/wiki/Internal_rate_of_return XIRR}, assuming irregularly timed cash flows.
9
- #
10
- # @param cash_flow_items [Array] items which have `#date` ([Date]) and `#amount` ([Numeric]) properties
11
- # @return [Numeric] the XIRR for the cash flow
12
- def self.calculate(cash_flow_items)
13
- return nil if cash_flow_items.map(&:amount).none? { |amount| amount >= 0 }
14
- return nil if cash_flow_items.map(&:amount).none? { |amount| amount < 0 }
15
-
16
- objective_function = Util::ObjectiveFunction.new(Xnpv, cash_flow_items)
17
- discount_rate_vector = [objective_function.one]
18
-
19
- begin
20
- nlsolve(objective_function, discount_rate_vector)
21
- rescue RuntimeError => ex
22
- raise CalculationError.new(ex)
23
- end
24
-
25
- discount_rate_vector.first
26
- end
27
- end
28
- end
29
- end
@@ -1,39 +0,0 @@
1
- module CashFlowAnalysis
2
- module Util
3
- class ObjectiveFunction
4
- def eps
5
- BigDecimal.new("1.0e-16")
6
- end
7
-
8
- def zero
9
- BigDecimal.new("0.0")
10
- end
11
-
12
- def one
13
- BigDecimal.new("1.0")
14
- end
15
-
16
- def two
17
- BigDecimal.new("2.0")
18
- end
19
-
20
- def ten
21
- BigDecimal.new("10.0")
22
- end
23
-
24
- def initialize(calculator, cash_flow_items)
25
- @calculator = calculator
26
- @cash_flow_items = cash_flow_items
27
- end
28
-
29
- def values(discount_rates)
30
- [calculator.calculate(discount_rates.first.round(15), cash_flow_items)]
31
- end
32
-
33
- private
34
-
35
- attr_reader :calculator
36
- attr_reader :cash_flow_items
37
- end
38
- end
39
- end