Hi Eric,
Applying this patch should help. It uses XIRR from this library <https://anexen.github.io/pyxirr/functions.html#xirr>. It certainly resolves your test case, and works on several accounts of mine (but not all). However, I’ve barely tested it, and there are cases where it might not work. Nor do I have an explanation for why the test case you presented wasn't caught earlier. Posting it here for you or anyone who is inspired to dig deeper into this issue. --- /home/user/beangrow/beangrow/returns.py +++ returns.py @@ -17,7 +17,7 @@ from beancount.core.inventory import Inventory from beancount.core.number import ZERO from beancount.core.position import Position -from scipy.optimize import fsolve +import pyxirr from beangrow.investments import AccountData, CashFlow, Cat, compute_balance_at @@ -196,14 +196,10 @@ years = [(flow.date - end_date).days / 365 for flow in dated_flows] years = np.array(years) - # Start with something reasonably normal. - estimated_irr = 0.2 * np.sign(np.sum(cash_flows)) + date_list = [d.date for d in dated_flows] + irr = pyxirr.xirr(date_list, cash_flows) + return irr - # Solve for the root of the NPV equation. - irr, *_ = fsolve( - net_present_value, x0=estimated_irr, args=(cash_flows, years), full_output=True - ) - return irr.item() -- You received this message because you are subscribed to the Google Groups "Beancount" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion visit https://groups.google.com/d/msgid/beancount/146d315d-3733-428c-b9f8-91db49bd874fn%40googlegroups.com.
