Skip to content

numpy type missmatch during beangrow-returns if price difference too big #50

@tuhriel

Description

@tuhriel

I have a portfolio for which the creation of the reports fails with the following error:

Traceback (most recent call last):
  File "/home/stefan/gitrepos/ledger_test/.venv/bin/beangrow-returns", line 10, in <module>
    sys.exit(main())
             ^^^^^^
  File "/home/stefan/gitrepos/ledger_test/.venv/lib/python3.12/site-packages/beangrow/compute_returns.py", line 86, in main
    pricer = reports.generate_reports(account_data_map, config,
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/stefan/gitrepos/ledger_test/.venv/lib/python3.12/site-packages/beangrow/reports.py", line 641, in generate_reports
    func()
  File "/home/stefan/gitrepos/ledger_test/.venv/lib/python3.12/site-packages/beangrow/reports.py", line 242, in write_returns_html
    plots = plot_flows(
            ^^^^^^^^^^^
  File "/home/stefan/gitrepos/ledger_test/.venv/lib/python3.12/site-packages/beangrow/reports.py", line 492, in plot_flows
    gamounts[-remaining_days:] += gflow
numpy._core._exceptions._UFuncOutputCastingError: Cannot cast ufunc 'add' output from dtype('complex128') to dtype('float64') with casting rule 'same_kind'

I was able to identify which asset is creating the issue and have pulled all the entries to this specific asset. I'm at a loss what exactly leads to this issue. I tried to find the issue by:

  • changing the source of the price information between coinbase and yahoo
  • modifying the prices to have less decimals
  • modifying the amount of bought assets to have less decimals
  • removing the inferred_tolerance_default value for EUR

it still kept throwing the error and stopping the finalization of the report.

while writing this issue, I got the idea that it might be missing some prices, so I added some prices....nothing..still an error

I removed the most current price: 2025-12-16 price SOL 107.825 EUR

I did some additional testing with the dates and prices and voila I found it:
2025-12-14 price SOL 111.517886352539060000 EUR --> Error
2025-12-14 price SOL 111.557886352539060000 EUR --> OK

somehow the calculation fails, if the current price falls too low (or maybe the difference grows too large). That's where my python debugging skills end, as I can't figure out which two variables it want's to add up.

beancount file:

option "operating_currency" "CHF"

option "booking_method" "FIFO"
option "inferred_tolerance_default" "USD:0.00001"
option "inferred_tolerance_default" "EUR:0.0001"
option "inferred_tolerance_default" "SEK:0.00001"

plugin "beancount.plugins.implicit_prices"


2025-03-18 commodity SOL
	price: "EUR:coinbase/SOL-EUR"
2025-03-18 open Assets:CH:Swissquote:SOL
2025-03-18 open Income:CH:Swissquote:PnL:SOL


1900-01-01 commodity EUR
	price: "CHF:ratesapi/EUR-CHF"
    

2025-10-23 * "Kauf 1.21 SOL"
    Assets:CH:Swissquote:SOL                    1.21350534 SOL  { 163.16 EUR }
    Assets:CH:Swissquote:Cash:EUR            - 199.98 EUR
    Expenses:CH:Swissquote:Kommission            1.98 EUR



2025-11-18 price SOL                121.51249694824219 EUR
2025-12-16 price SOL                    107.825 EUR

beangrow config:

investments{
  investment {
    currency: "SOL"
    asset_account: "Assets:CH:Swissquote:SOL"
    cash_accounts: "Assets:CH:Swissquote:Cash:EUR"
  }
}
groups{
  group {
    name: "currency.SOL"
    investment: "Assets:CH:Swissquote:SOL"
  }
}

this is the output (up until it is stopped by the error above) if run with --verbose:

INFO    : Reading ledger: sol.beancount
DEBUG   : Processing account: Assets:CH:Swissquote:SOL
INFO    : Writing details file: ./sol/investments/Assets_CH_Swissquote_SOL.org
INFO    : Writing returns dir for currency.SOL: sol/groups/currency.SOL
DEBUG   : Inside Dietz. From None to 2025-12-16
DEBUG   : Setting start date to 2025-10-23
DEBUG   : Start date: 2025-10-23
DEBUG   : End date: 2025-12-16
DEBUG   : PnL: 130.8462132855 + 0.0 - 199.98 = -69.13378671449999
DEBUG   : Average capital: -0.0 + 203.68333333333334 = 203.68333333333334
DEBUG   : Dietz return: -0.33941798566974873
DEBUG   : Inside Dietz. From None to 2025-12-16
DEBUG   : Setting start date to 2025-10-23
DEBUG   : Start date: 2025-10-23
DEBUG   : End date: 2025-12-16
DEBUG   : PnL: 130.8462132855 + 0.0 - 199.98 = -69.13378671449999
DEBUG   : Average capital: -0.0 + 203.68333333333334 = 203.68333333333334
DEBUG   : Dietz return: -0.33941798566974873
DEBUG   : Loaded backend agg version v2.2.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions