Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash due to complex rate of return when investment value goes down. #16

Open
muonzoo opened this issue Feb 15, 2022 · 0 comments
Open

Comments

@muonzoo
Copy link

muonzoo commented Feb 15, 2022

When the price goes down post investment, beangrow crashes with complex type error (sum of real and complex).

An investment that has the price drop after acquisition results in a complex rate of return that cannot be summed.

Removing the 9.00 USD Price on line 22 stops the crash.

Output:

INFO    : Reading ledger: bug.bean
INFO    : Processing account: Assets:US:Investments:XYZ
INFO    : Writing details file: bug-returns/investments/Assets_US_Investments_XYZ.org
INFO    : Writing returns dir for currency.XYZ: bug-returns/groups/currency.XYZ
DEBUG   : top of Axes not in the figure, so title not moved
DEBUG   : top of Axes not in the figure, so title not moved
Traceback (most recent call last):
  File ".../scm/gh/beangrow/beangrow/compute_returns.py", line 105, in <module>
    main()
  File ".../scm/gh/beangrow/beangrow/compute_returns.py", line 86, in main
    pricer = reports.generate_reports(account_data_map, config,
  File ".../scm/gh/beangrow/beangrow/reports.py", line 551, in generate_reports
    func()
  File ".../scm/gh/beangrow/beangrow/reports.py", line 218, in write_returns_html
    plots = plot_flows(
  File ".../scm/gh/beangrow/beangrow/reports.py", line 415, 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'

Version:

Beancount 2.3.4 (git:0003608e; 2021-12-05)

==> bug.bean <==

; -*- mode: beancount; fill-column: 9999; -*-

2000-01-01 commodity USD
2000-01-01 commodity XYZ

2000-01-01 open Equity:Opening-Balances
2000-01-01 open Assets:US:Investments:XYZ XYZ
2000-01-01 open Assets:US:Investments:Cash USD

2022-02-07 price XYZ               9.950 USD

2022-01-01 * "Opening"
  Equity:Opening-Balances     -10,000.00 USD
  Assets:US:Investments:Cash  10,000.000 USD

2022-02-10 * " Make Investment"
  Assets:US:Investments:XYZ         1000 XYZ { 10.00 USD, 2022-02-10 }
  Assets:US:Investments:Cash  -10,000.00 USD
  closing: TRUE

; Change this to > 10.00 USD and it will not crash.
2022-02-14 price XYZ                9.00 USD

2022-02-28 price XYZ               11.00 USD

==> bug.conf <==

investments {
  investment {
    currency: "XYZ"
    asset_account: "Assets:US:Investments:XYZ"
    cash_accounts: "Assets:US:Investments:Cash"
  }
}
groups {
  group {
    name: "currency.XYZ"
    investment: "Assets:US:Investments:XYZ"
  }
}

Bean Report Print output:

; - bean-report bug.bean print
2000-01-01 open Equity:Opening-Balances
2000-01-01 open Assets:US:Investments:XYZ                       XYZ
2000-01-01 open Assets:US:Investments:Cash                      USD

2000-01-01 commodity USD

2000-01-01 commodity XYZ

2022-01-01 * "Opening"
  Equity:Opening-Balances     -10000.00 USD
  Assets:US:Investments:Cash  10000.000 USD

2022-02-07 price XYZ                                 9.950 USD

2022-02-10 * " Make Investment"
  Assets:US:Investments:XYZ        1000 XYZ {10.00 USD, 2022-02-10}
  Assets:US:Investments:Cash  -10000.00 USD
    closing: TRUE

2022-02-14 price XYZ                                  9.00 USD
2022-02-28 price XYZ                                 11.00 USD
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant