xirr 0.5.3 → 0.5.4
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.
- checksums.yaml +4 -4
- data/.gitignore +0 -0
- data/CHANGE_LOG.md +3 -0
- data/lib/xirr/cashflow.rb +12 -7
- data/lib/xirr/newton_method.rb +2 -1
- data/lib/xirr/version.rb +1 -1
- data/test/test_cashflow.rb +8 -0
- metadata +2 -3
- data/.DS_Store +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 19f0ca0058f57982916f0a8e2b96ceb6717a6dc4
|
4
|
+
data.tar.gz: e2467167fa94e1f7132815933034502a0a999b9a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d6ab5e1fe60ef7859c938938b23ca06e01b148e2c1e5cb9cd8fb82f4d15e9ba30818abea6004440da26ad90016c31191bab62cde26c7e635d78ac64b3a3b0a0f
|
7
|
+
data.tar.gz: 38da74ebbfe057d53139d13d25d73553db8edb1b6fbe5492dfac8816920ee0efab77ae2fb21a7edc5dfc7039cb5b77a6e7ec0a91f1b0c08d084db23affb700e8
|
data/.gitignore
CHANGED
Binary file
|
data/CHANGE_LOG.md
CHANGED
data/lib/xirr/cashflow.rb
CHANGED
@@ -62,7 +62,7 @@ module Xirr
|
|
62
62
|
BigDecimal.new(0, Xirr::PRECISION)
|
63
63
|
else
|
64
64
|
xirr = choose_(method).send :xirr, guess, options
|
65
|
-
xirr = choose_(other_calculation_method(method)).send(:xirr, guess, options) if xirr.nil? && fallback
|
65
|
+
xirr = choose_(other_calculation_method(method)).send(:xirr, guess, options) if (xirr.nil? || xirr.nan?) && fallback
|
66
66
|
xirr || Xirr::REPLACE_FOR_NIL
|
67
67
|
end
|
68
68
|
end
|
@@ -116,6 +116,12 @@ module Xirr
|
|
116
116
|
@temporary_period || @period
|
117
117
|
end
|
118
118
|
|
119
|
+
def << arg
|
120
|
+
super arg
|
121
|
+
self.sort! { |x, y| x.date <=> y.date }
|
122
|
+
self
|
123
|
+
end
|
124
|
+
|
119
125
|
private
|
120
126
|
|
121
127
|
# @param method [Symbol]
|
@@ -138,8 +144,8 @@ module Xirr
|
|
138
144
|
# This implies the first transaction is a disbursement
|
139
145
|
# @return [Integer]
|
140
146
|
def first_transaction_direction
|
141
|
-
self.sort! { |x, y| x.date <=> y.date }
|
142
|
-
self.first.amount / self.first.amount.abs
|
147
|
+
# self.sort! { |x, y| x.date <=> y.date }
|
148
|
+
@first_transaction_direction ||= self.first.amount / self.first.amount.abs
|
143
149
|
end
|
144
150
|
|
145
151
|
# Based on the direction of the first investment finds the multiple cash-on-cash
|
@@ -148,8 +154,7 @@ module Xirr
|
|
148
154
|
# @api private
|
149
155
|
# @return [Float]
|
150
156
|
def multiple
|
151
|
-
|
152
|
-
first_transaction_positive? ? result : 1 / result
|
157
|
+
inflow.sum(&:amount).abs / outflows.sum(&:amount).abs
|
153
158
|
end
|
154
159
|
|
155
160
|
def first_transaction_positive?
|
@@ -168,7 +173,7 @@ module Xirr
|
|
168
173
|
# @see #outflows
|
169
174
|
# Selects all positives transactions from Cashflow
|
170
175
|
def inflow
|
171
|
-
self.select { |x| x.amount < 0 }
|
176
|
+
self.select { |x| x.amount * first_transaction_direction < 0 }
|
172
177
|
end
|
173
178
|
|
174
179
|
# @api private
|
@@ -176,7 +181,7 @@ module Xirr
|
|
176
181
|
# @see #inflow
|
177
182
|
# Selects all negatives transactions from Cashflow
|
178
183
|
def outflows
|
179
|
-
self.select { |x| x.amount > 0 }
|
184
|
+
self.select { |x| x.amount * first_transaction_direction > 0 }
|
180
185
|
end
|
181
186
|
|
182
187
|
end
|
data/lib/xirr/newton_method.rb
CHANGED
@@ -48,7 +48,8 @@ module Xirr
|
|
48
48
|
rate = [guess || cf.irr_guess]
|
49
49
|
begin
|
50
50
|
nlsolve(func, rate)
|
51
|
-
rate[0] <= -1 ? nil : rate[0].round(Xirr::PRECISION)
|
51
|
+
(rate[0] <= -1 || rate[0].nan?) ? nil : rate[0].round(Xirr::PRECISION)
|
52
|
+
|
52
53
|
# rate[0].round(Xirr::PRECISION)
|
53
54
|
rescue
|
54
55
|
nil
|
data/lib/xirr/version.rb
CHANGED
data/test/test_cashflow.rb
CHANGED
@@ -289,7 +289,15 @@ describe 'Cashflows' do
|
|
289
289
|
cf << Transaction.new(500, date: '2014-10-19'.to_date)
|
290
290
|
assert_equal '-0.996814607'.to_f.round(3), cf.xirr.to_f.round(3)
|
291
291
|
end
|
292
|
+
end
|
293
|
+
describe 'marano' do
|
292
294
|
|
295
|
+
it 'it matchs Excel' do
|
296
|
+
cf = Cashflow.new
|
297
|
+
cf << Transaction.new(900.0, date: '2014-11-07'.to_date)
|
298
|
+
cf << Transaction.new(-13.5, date: '2015-05-06'.to_date)
|
299
|
+
assert_equal '-0.9998'.to_f.round(4), cf.xirr.to_f.round(4)
|
300
|
+
end
|
293
301
|
end
|
294
302
|
|
295
303
|
describe 'period' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xirr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- tubedude
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-05-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -102,7 +102,6 @@ executables: []
|
|
102
102
|
extensions: []
|
103
103
|
extra_rdoc_files: []
|
104
104
|
files:
|
105
|
-
- ".DS_Store"
|
106
105
|
- ".coveralls.yml"
|
107
106
|
- ".gitignore"
|
108
107
|
- ".ruby-gemset"
|
data/.DS_Store
DELETED
Binary file
|