Closed wkranec closed 12 years ago
Finance should have an implementation of the XIRR function. Some details are available on the OpenOffice.org wiki:
http://wiki.services.openoffice.org/wiki/Documentation/How_Tos/Calc:_XIRR_function
Other implementations I've found on the web:
Some thoughts on the implementation:
xirr
Array
Array#irr
Finance::Cashflow
Transaction
date
amount
String
Date
Datetime
Rate
Example
> t = [] > t << Transaction.new(-5000, :date => '3/1/2011') > t << Transaction.new(100, :date => '4/1/2011') > t << Transaction.new(100, :date => '5/15/2011') > t << Transaction.new(100, :date => '6/29/2011') > t << Transaction.new(5000, :date => '7/4/2011') > t.xirr #=> 0.19021145803047
Added basic working support in 1.1.0. Tests and feedback are welcome!
Finance should have an implementation of the XIRR function. Some details are available on the OpenOffice.org wiki:
http://wiki.services.openoffice.org/wiki/Documentation/How_Tos/Calc:_XIRR_function
Other implementations I've found on the web:
Some thoughts on the implementation:
xirr
method will be defined as anArray
method (similar toArray#irr
) insideFinance::Cashflow
.Array
should containTransaction
objects, which will havedate
andamount
attributes.date
attribute hasn't been defined yet, but it should probably accept aString
, and convert internally to a RubyDate
(orDatetime
) object.xirr
method ought to return aRate
object (this is not the case in the example below).Example