Hi Eric,
As Martin mentioned, Beangrow is code that Martin shared at some point 
years ago. I would consider it highly experimental, and fringe part of the 
larger Beancount ecosystem. I personally take that to mean “I’d be very 
pleasantly surprised if this worked out of the box” :). Beancount itself is 
mature, well maintained (I personally use v2), and has a large number of 
active users.

All that said, I ran your example (thanks for a simple case!), and can 
confirm this seems like a bug. It seems like an issue around root finding 
in the XIRR calculation which is done with scipy.optimize.fsolve() and an 
NPV formula. With your given example, the iterative process incorrectly 
converges towards -1 (-100%). Try running your example with the sale on Dec 
31, so the time period between your purchase and sale is longer, and the 
formula converges to the correct IRR.

I lack the time right now to figure out why that happens numerically, but I 
imagine if that part of the code were replaced with an XIRR library, it 
would work fine. I’ve had a personal interest in getting Beangrow to work 
for some of my projects, but I’ve lacked the time to contribute to it. If 
you want to debug and contribute to that code base, that would be awesome. 
Your example is a great starting point. There is not much code in there, it 
is fairly straightforward, and there is Martin’s excellent documentation 
<https://docs.google.com/document/d/1nPsMIunLnDvdsg6TSsd0PZb7jngojNpFlqnaX36WRp8/edit?tab=t.0#heading=h.606vlnpt44xn>
 
to help you understand the code well.

-Red
​
On Wednesday, November 27, 2024 at 12:53:33 PM UTC-8 Eric Morgan wrote:

> This is an attempt at making my original question easier to answer by 
> providing a minimal example.
>
> Here is a beancount file with one purchas and sale. 
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> *option "operating_currency" "SEK"2010-01-01 custom "fava-extension" 
> "fava_portfolio_returns" "{  'beangrow_config': 
> '/data/beancount/beangrow.pbtxt',}"2010-01-01 open Assets:MIPS             
>                         MIPS2010-01-01 open Assets:Cash:SEK                 
>                 SEK2010-01-01 commodity MIPS  price: "SEK:yahoo/MIPS.ST 
> <http://MIPS.ST>"2022-07-08 * "Purchase MIPS"  Assets:MIPS                 
>                       453.0 MIPS @ 464.8 SEK  Assets:Cash:SEK               
>                 -210655.0 SEK2022-08-08 * "Sale MIPS"  Assets:MIPS         
>                             -453.0 MIPS @ 608.0 SEK  Assets:Cash:SEK       
>                         275325.0 SEK*
> Here is a beangrow config file with one investment and group
>
>
>
>
>
>
>
>
>
> *investments {  investment {    currency: "MIPS"    asset_account: 
> "Assets:MIPS"    cash_accounts: "Assets:Cash:SEK"  }}*
>
>
>
>
>
> *groups {  group {    name: "stocks.MIPS"    investment: "Assets:MIPS"    
> currency: "SEK"  }}*
>
> Here is the output
>
>
>
>
>
>
>
>
>
> *Investment              stocks.MIPSUnits                   -Cash In       
>           210655.0 SEKCash Out                275325.0 SEKMarket Value     
>        -Returns                 64670.0 SEKYield                   30.70 
> %IRR                     -100.00 %*
>
> I would expect that since the investment returned 30% in a month, the 
> annual IRR should be higher than 30%. Does -100% indicate a bug in beangrow 
> or am I thinking incorrectly about this?
> On Sunday, November 3, 2024 at 12:09:23 AM UTC+1 Eric Morgan wrote:
>
>> Here is another attempt at inserting images
>>
>> [image: 20241102_23h47m09s_grim.png]
>>
>> [image: 20241102_23h51m09s_grim.png]
>> On Sunday, November 3, 2024 at 12:07:13 AM UTC+1 Eric Morgan wrote:
>>
>>> I'm using the beangrow plugin for fava. It shows the following numbers. 
>>> I've double checked that yield is correct using a different library. But I 
>>> don't understand why IRR is -100.00%. My calculations suggest it should 
>>> be 285.78%.
>>>
>>> [image: 20241102_23h47m09s_grim.png]
>>>
>>> Here is the same data visualized with the beangrow tool.
>>>
>>> [image: 20241102_23h51m09s_grim.png]
>>>
>>> Here is the beangrow config file
>>>
>>> investments {
>>>   investment {
>>>     currency: "MIPS"
>>>     asset_account: "Assets:MIPS"
>>>     cash_accounts: "Assets:Cash:SEK:BankA:AccountA"
>>>     cash_accounts:  "Assets:Cash:SEK:BankB:AccountB"
>>>   }
>>> groups {
>>>   group {
>>>     name: "stocks.MIPS"
>>>     investment: "Assets:MIPS"
>>>     currency: "SEK"
>>>   }
>>> }
>>>
>>> Here are the entries on that account copied from fava
>>>
>>> 2022-06-22
>>> Open
>>> Assets:MIPS
>>> 2022-06-22
>>> *
>>> Purchase MIPS
>>> si
>>> 108057.6 SEK
>>> 108057.6 SEK
>>> signature:
>>> ASSET_CASH_EXPENSES_INCOME
>>> Assets:MIPS
>>> 224.0 MIPS
>>> 461.7 SEK
>>> Assets:Cash:SEK:BankB:AccountB
>>> -103480.0 SEK
>>> Income:Financial:Rounding:SEK:BankB:AccountB
>>> 0.20 SEK
>>> Expenses:Comissions:SEK:BankB:AccountB
>>> 59.0 SEK
>>> 2022-06-22
>>> *
>>> Purchase MIPS
>>> si
>>> 120600.0 SEK
>>> 228657.6 SEK
>>> signature:
>>> ASSET_CASH_EXPENSES_INCOME
>>> Assets:MIPS
>>> 250.0 MIPS
>>> 458.7 SEK
>>> Assets:Cash:SEK:BankB:AccountB
>>> -114738.0 SEK
>>> Income:Financial:Rounding:SEK:BankB:AccountB
>>> Expenses:Comissions:SEK:BankB:AccountB
>>> 63.0 SEK
>>> 2022-06-22
>>> *
>>> Purchase MIPS
>>> si
>>> 120600.0 SEK
>>> 349257.6 SEK
>>> signature:
>>> ASSET_CASH_EXPENSES_INCOME
>>> Assets:MIPS
>>> 250.0 MIPS
>>> 460.6 SEK
>>> Assets:Cash:SEK:BankB:AccountB
>>> -115213.0 SEK
>>> Income:Financial:Rounding:SEK:BankB:AccountB
>>> Expenses:Comissions:SEK:BankB:AccountB
>>> 63.0 SEK
>>> 2022-06-22
>>> *
>>> Purchase MIPS
>>> si
>>> 117705.6 SEK
>>> 466963.2 SEK
>>> signature:
>>> ASSET_CASH_EXPENSES_INCOME
>>> Assets:MIPS
>>> 244.0 MIPS
>>> 456.1 SEK
>>> Assets:Cash:SEK:BankB:AccountB
>>> -111349.0 SEK
>>> Income:Financial:Rounding:SEK:BankB:AccountB
>>> -0.40 SEK
>>> Expenses:Comissions:SEK:BankB:AccountB
>>> 61.0 SEK
>>> 2022-06-22
>>> *
>>> Purchase MIPS
>>> si
>>> 96480.0 SEK
>>> 563443.2 SEK
>>> signature:
>>> ASSET_CASH_EXPENSES_INCOME
>>> Assets:MIPS
>>> 200.0 MIPS
>>> 457.6 SEK
>>> Assets:Cash:SEK:BankB:AccountB
>>> -91579.0 SEK
>>> Income:Financial:Rounding:SEK:BankB:AccountB
>>> Expenses:Comissions:SEK:BankB:AccountB
>>> 59.0 SEK
>>> 2022-06-22
>>> *
>>> Purchase MIPS
>>> si
>>> 14472.0 SEK
>>> 577915.2 SEK
>>> signature:
>>> ASSET_CASH_EXPENSES_INCOME
>>> Assets:MIPS
>>> 30.0 MIPS
>>> 456.7 SEK
>>> Assets:Cash:SEK:BankB:AccountB
>>> -13760.0 SEK
>>> Income:Financial:Rounding:SEK:BankB:AccountB
>>> Expenses:Comissions:SEK:BankB:AccountB
>>> 59.0 SEK
>>> 2022-07-04
>>> *
>>> Purchase MIPS
>>> si
>>> 134790.0 SEK
>>> 673051.4 SEK
>>> signature:
>>> ASSET_CASH_EXPENSES_INCOME
>>> Assets:MIPS
>>> 300.0 MIPS
>>> 446.1 SEK
>>> Assets:Cash:SEK:BankB:AccountB
>>> -133904.0 SEK
>>> Income:Financial:Rounding:SEK:BankB:AccountB
>>> Expenses:Comissions:SEK:BankB:AccountB
>>> 74.0 SEK
>>> 2022-07-08
>>> *
>>> Purchase MIPS
>>> si
>>> 212728.8 SEK
>>> 916189.6 SEK
>>> signature:
>>> ASSET_CASH_EXPENSES_INCOME
>>> Assets:MIPS
>>> 453.0 MIPS
>>> 464.8 SEK
>>> Assets:Cash:SEK:BankB:AccountB
>>> -210655.0 SEK
>>> Income:Financial:Rounding:SEK:BankB:AccountB
>>> 1.60 SEK
>>> Expenses:Comissions:SEK:BankB:AccountB
>>> 99.0 SEK
>>> 2022-08-08
>>> *
>>> Sale MIPS
>>> si
>>> -277326.6 SEK
>>> 917075.6 SEK
>>> signature:
>>> ASSET_CASH_EXPENSES_INCOME
>>> Assets:MIPS
>>> -453.0 MIPS
>>> 608.0 SEK
>>> Assets:Cash:SEK:BankB:AccountB
>>> 275325.0 SEK
>>> Income:Financial:Rounding:SEK:BankB:AccountB
>>> Expenses:Comissions:SEK:BankB:AccountB
>>> 99.0 SEK
>>> 2022-08-22
>>> *
>>> Sale MIPS
>>> si
>>> -820005.2 SEK
>>> signature:
>>> ASSET_CASH_EXPENSES_INCOME
>>> Assets:MIPS
>>> -1498.0 MIPS
>>> 540.0 SEK
>>> Assets:Cash:SEK:BankA:AccountA
>>> 808721.0 SEK
>>> Income:Financial:Rounding:SEK:BankA:AccountA
>>> Expenses:Comissions:SEK:BankA:AccountA
>>> 199.0 SEK
>>>
>>> The Yield and IRR has been correct for other investments I've looked at 
>>> in my data.
>>>
>>> Appreciate any help on this. Thanks!
>>
>>

-- 
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 beancount+unsubscr...@googlegroups.com.
To view this discussion visit 
https://groups.google.com/d/msgid/beancount/5db0277e-7c0f-464a-a4f9-6e0da430e856n%40googlegroups.com.

Reply via email to