Commits

intgr committed a4a84f5

New test, try different guesses

  • Participants
  • Parent commits 221c4f7

Comments (0)

Files changed (2)

test/expected/xirr.out

  2.2427441504
 (3 rows)
 
+-- Different guesses
+SELECT 0.1*i AS guess, xirr(amt, ts, 0.1*i) FROM (VALUES
+    (-10000, '2009-01-01'::timestamptz),
+    (-10000, '2010-01-01'),
+    ( 10000, '2011-01-01'),
+    ( 10000, '2012-01-01'),
+    (  1000, '2013-01-01')
+) x(amt, ts)
+CROSS JOIN generate_series(-10, 10) i
+GROUP BY i
+ORDER BY i;
+ guess |      xirr      
+-------+----------------
+  -1.0 |               
+  -0.9 | 0.023844261812
+  -0.8 | 0.023844261812
+  -0.7 | 0.023844261812
+  -0.6 | 0.023844261812
+  -0.5 | 0.023844261812
+  -0.4 | 0.023844261812
+  -0.3 | 0.023844261812
+  -0.2 | 0.023844261812
+  -0.1 | 0.023844261812
+   0.0 | 0.023844261812
+   0.1 | 0.023844261812
+   0.2 | 0.023844261812
+   0.3 | 0.023844261812
+   0.4 | 0.023844261812
+   0.5 | 0.023844261812
+   0.6 |               
+   0.7 |               
+   0.8 |               
+   0.9 |               
+   1.0 |               
+(21 rows)
+

test/sql/xirr.sql

 
 -- Window function
 SELECT xirr(amt, ts) OVER (ORDER BY ts) FROM (VALUES(-100::float, '2013-01-01'::timestamptz), (10, '2013-02-01'), (110, '2013-03-01')) x(amt, ts);
+
+-- Different guesses
+SELECT 0.1*i AS guess, xirr(amt, ts, 0.1*i) FROM (VALUES
+    (-10000, '2009-01-01'::timestamptz),
+    (-10000, '2010-01-01'),
+    ( 10000, '2011-01-01'),
+    ( 10000, '2012-01-01'),
+    (  1000, '2013-01-01')
+) x(amt, ts)
+CROSS JOIN generate_series(-10, 10) i
+GROUP BY i
+ORDER BY i;