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

Error message in Beancount 2.3.3 #7

Open
prabusw opened this issue Feb 24, 2021 · 6 comments
Open

Error message in Beancount 2.3.3 #7

prabusw opened this issue Feb 24, 2021 · 6 comments

Comments

@prabusw
Copy link

prabusw commented Feb 24, 2021

Martin,

When i try to run the code, i'm getting the below error message in Beancount 2.3.3... I can send you the ledger file privately, if you mail me.

$:~/beancount/beangrow-master/beangrow$ python compute_returns.py ~prabu/beancount/prabu/prabu2021_02_20.beancount config.pbtxt return_reports
/home/prabu/beancount/beangrow-master/beangrow/returns.py:63: RuntimeWarning: invalid value encountered in power
return np.sum(cash_flows / (1. + irr) ** years)
/home/prabu/beancount/beangrow-master/beangrow/returns.py:63: RuntimeWarning: invalid value encountered in power
return np.sum(cash_flows / (1. + irr) ** years)
/home/prabu/beancount/beangrow-master/beangrow/returns.py:63: RuntimeWarning: invalid value encountered in power
return np.sum(cash_flows / (1. + irr) ** years)
Traceback (most recent call last):
File "compute_returns.py", line 105, in
main()
File "compute_returns.py", line 100, in main
reports.write_price_directives(path.join(output_prices, "prices.beancount"),
File "/home/prabu/beancount/beangrow-master/beangrow/reports.py", line 406, in write_price_directives
days_late = (required_date - actual_date).days
TypeError: unsupported operand type(s) for -: 'datetime.date' and 'NoneType'

Here is the verbose output
prabu@homepc-lm:~/beancount/beangrow-master/beangrow$ python compute_returns.py ~prabu/beancount/prabu/prabu2021_02_20.beancount config.pbtxt return_reports -v
INFO : Reading ledger: /home/prabu/beancount/prabu/prabu2021_02_20.beancount
INFO : Processing account: Assets:TH:Investment:KGI:INTUCH-R
INFO : Processing account: Assets:US:Investment:ETrade:BP
INFO : Processing account: Assets:US:Investment:ETrade:CVX
INFO : Processing account: Assets:US:Investment:ETrade:EQIX
INFO : Processing account: Assets:US:Investment:ETrade:IXC
INFO : Processing account: Assets:US:Investment:ETrade:TOT
INFO : Processing account: Assets:US:Investment:ETrade:RDS-B
INFO : Processing account: Assets:US:Investment:ETrade:XLE
INFO : Processing account: Assets:US:Investment:ETrade:XOM
INFO : Writing details file: return_reports/investments/Assets_TH_Investment_KGI_INTUCH-R.org
INFO : Writing details file: return_reports/investments/Assets_US_Investment_ETrade_BP.org
INFO : Writing details file: return_reports/investments/Assets_US_Investment_ETrade_CVX.org
INFO : Writing details file: return_reports/investments/Assets_US_Investment_ETrade_EQIX.org
INFO : Writing details file: return_reports/investments/Assets_US_Investment_ETrade_IXC.org
INFO : Writing details file: return_reports/investments/Assets_US_Investment_ETrade_TOT.org
INFO : Writing details file: return_reports/investments/Assets_US_Investment_ETrade_RDS-B.org
INFO : Writing details file: return_reports/investments/Assets_US_Investment_ETrade_XLE.org
INFO : Writing details file: return_reports/investments/Assets_US_Investment_ETrade_XOM.org
INFO : Writing returns dir for strategy:GlobalEnergy: return_reports/groups/strategy:GlobalEnergy
DEBUG : top of axes not in the figure, so title not moved
DEBUG : top of axes not in the figure, so title not moved
/home/prabu/beancount/beangrow-master/beangrow/returns.py:63: RuntimeWarning: invalid value encountered in power
return np.sum(cash_flows / (1. + irr) ** years)
INFO : Writing returns dir for strategy:GlobalEnergy: return_reports/groups/strategy:GlobalEnergy.org
INFO : Writing returns dir for currency.EQIX: return_reports/groups/currency.EQIX
DEBUG : top of axes not in the figure, so title not moved
DEBUG : top of axes not in the figure, so title not moved
/home/prabu/beancount/beangrow-master/beangrow/returns.py:63: RuntimeWarning: invalid value encountered in power
return np.sum(cash_flows / (1. + irr) ** years)
INFO : Writing returns dir for currency.EQIX: return_reports/groups/currency.EQIX.org
INFO : Writing returns dir for Thailand.Intuch: return_reports/groups/Thailand.Intuch
DEBUG : top of axes not in the figure, so title not moved
DEBUG : top of axes not in the figure, so title not moved
/home/prabu/beancount/beangrow-master/beangrow/returns.py:63: RuntimeWarning: invalid value encountered in power
return np.sum(cash_flows / (1. + irr) ** years)
INFO : Writing returns dir for Thailand.Intuch: return_reports/groups/Thailand.Intuch.org
INFO : Producing price page for ('BP', 'USD')
INFO : Producing price page for ('CVX', 'USD')
INFO : Producing price page for ('EQIX', 'USD')
INFO : Producing price page for ('INTUCH-R', 'THB')
INFO : Producing price page for ('IXC', 'USD')
INFO : Producing price page for ('RDS-B', 'USD')
INFO : Producing price page for ('TOT', 'USD')
INFO : Producing price page for ('XLE', 'USD')
INFO : Producing price page for ('XOM', 'USD')
Traceback (most recent call last):
File "compute_returns.py", line 105, in
main()
File "compute_returns.py", line 100, in main
reports.write_price_directives(path.join(output_prices, "prices.beancount"),
File "/home/prabu/beancount/beangrow-master/beangrow/reports.py", line 406, in write_price_directives
days_late = (required_date - actual_date).days
TypeError: unsupported operand type(s) for -: 'datetime.date' and 'NoneType'

@redstreet
Copy link

I had exactly the same issue (among several others), and had it figured out, but unfortunately seem to have lost my notes on what was causing it. I'd be happy to debug this if you'd be okay sharing your ledger file with me. If so, please message me. Perhaps you could anonymize it, change numbers etc., or produce a separate minimal example.

@prabusw
Copy link
Author

prabusw commented Feb 28, 2021 via email

@redstreet
Copy link

redstreet commented Feb 28, 2021

Hello @prabusw, the attachment doesn't seem to have come through. In case you meant to send it to my email, my address is ---removed---.

@redstreet
Copy link

redstreet commented Mar 1, 2021

Thanks for sharing, @prabusw! I took a look. There are several issues to fix in beangrow, and a few tips that might help you:

  1. Your source doesn't include explicit price entries needed to compute returns. That's totally fine and not surprising - beangrow should error out gracefully, but instead crashes with the TypeError (I'll send a PR for this later, @blais). This results in meaningless returns values for the second (out of your three) groups in your config, and also is the source of the final TypeError. To fix this, include this line in your beancount source so the prices can come from your buy/sell transactions to start with:
plugin "beancount.plugins.implicit_prices"

This should make the TypeError go away.

  1. After including the above, you will want to run:
beangrow/beangrow/download_prices_from_file.py <your_returns_output_dir>/prices/prices.beancount

and include the resulting price database in your source. Without that, beangrow uses the price values on the closest dates it can find, which in your case could be weeks or months off, which means your returns numbers will be off. Do take a look at your returns numbers after doing this and see if they make sense. I haven't examined them. Ignore the two appearances of "20.0%", which is the solver crashing (the RuntimeWarning below).

  1. The RuntimeWarning, is raised by the solver for the net present value. It's for your account that was zeroed out in 2020. All your other returns numbers should be correct apart from this one. I think I know what the problem is here. More on this later, probably next weekend when I can look into it again.

Hope that helped! Do take a look at your returns numbers after (1) and (2) above, and feel free to post questions here or in the forum.

@prabusw
Copy link
Author

prabusw commented Mar 1, 2021 via email

@redstreet
Copy link

redstreet commented Mar 1, 2021

Hello @prabusw,
When compute_returns.py it's run for the first time on your ledger file, it figures out the price entries it needs on the dates it needs them in order to make an accurate returns computation.

As an example, to calculate the returns for each calendar year, it needs a price entry for each commodity on Jan 1 of each calendar year. Your ledger file may not have these entries. So ./compute_returns.py takes the closest price entries it can find to those dates and creates the prices.beancount with a list of those missing entries.

When you run the download_prices script, it therefore does not need access to your ledger. It only needs to know the list of dates and commodities that are in prices.beancount, for which it goes and fetches the actual prices (remember, the entries in prices.beancount thus far are the closest ones the first pass above could find, and not exact).

Martin's "Filling in Missing Price Points" in his document in the readme file of beangrow explains this very well.

So once the prices are fetched, you append these to your ledger file and then run compute_returns again, and this time it will produce more accurate results.

Feel free to look at your returns numbers right at the beginning when you run compute_returns for the first time. Open up the index.html files in your returns directory if you already haven't, in a browser. Then, download prices, rerun, and look at the returns again.

Hope that helped, and glad to hear you're finding beancount and its ecosystem useful :).

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

2 participants