#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
use Finance::Math::IRR;

my %cashflow = (
'1992-02-11'	=>	-2025000,
'1993-03-22'	=>	-1350000,
'1993-07-12'	=>	-2025000,
'1994-03-28'	=>	-1350000,
'1994-11-14'	=>	-1350000,
'1995-04-28'	=>	129167,
'1995-05-02'	=>	4968,
'1995-06-27'	=>	344591,
'1995-09-20'	=>	854153,
'1995-11-20'	=>	-675000,
'1996-02-07'	=>	47743,
'1996-02-29'	=>	-675000,
'1996-04-04'	=>	1417276,
'1996-04-25'	=>	-675000,
'1996-05-13'	=>	438693,
'1996-05-31'	=>	-675000,
'1996-07-03'	=>	682731,
'1996-08-09'	=>	188652,
'1996-09-17'	=>	183229,
'1996-12-16'	=>	-675000,
'1997-01-08'	=>	132992,
'1997-03-21'	=>	-675000,
'1997-04-17'	=>	144686,
'1997-07-07'	=>	-675000,
'1997-07-24'	=>	649871,
'1997-10-14'	=>	130328,
'1997-11-18'	=>	595112.5,
'1998-09-01'	=>	624482,
'1998-12-16'	=>	2205618.05,
'1999-09-07'	=>	-177315,
'1999-09-07'	=>	177315,
'2000-07-07'	=>	2179206.44,
'2000-10-03'	=>	-172295.67,
'2000-10-03'	=>	689112.33,
'2001-08-14'	=>	451861.33,
'2002-03-26'	=>	-43073.67,
'2002-03-26'	=>	375381.01,
'2002-06-26'	=>	429867,
'2003-12-19'	=>	-17226,
'2003-12-19'	=>	1180602.05,
'2005-06-07'	=>	65520,
'2006-03-22'	=>	145467,
'2009-03-31'	=>	144938
);

# and get the internal rate of return for this cashflow
my $irr = xirr(%cashflow, precision => 0.0001);

if (!defined $irr) {
	die "ERROR: xirr() failed to calculate the IRR of this cashflow\n";
}
else {
	print "XIRR=$irr\n";
}

