Hi,

That looks very interesting. I'm doing something similar right now.

Two things that I found necessary/helpful:

* I have one interest account and I just tie it to the security by adding an empty posting.

e.g.

2015-01-22 * "Dividend"
  Assets:Investment:CHCORP                           0 CHCORP
  Assets:Liquidity:CHF                                  20.00 CHF
  Income:Patrick:Interest                           -20.00 CHF


That way I can tie all the flows together for CHCORP



* Another thing is to make sure to prevent transactions between different investments in the same transaction as this confuses my logic, so I'm preventing this by


import collections

from beancount.core import getters
from beancount.core import data

__plugins__ = ['check']

MixedInvestAssets = collections.namedtuple('MixedInvestAssets', 'source message entry')

def check(entries, options_map):
    errors = []

    commodity_map = getters.get_commodity_map(entries, create_missing=True)
    commodity_type_map = getters.get_values_meta(commodity_map, 'type')

    for entry in data.filter_txns(entries):
        ccys = set()
        for posting in entry.postings:
            ccy = posting.units.currency
            if commodity_type_map[ccy] == 'invest':
                ccys.add(ccy)

        if len(ccys) > 1:
            errors.append(MixedInvestAssets(
                entry.meta,
                "Transaction with two or more different investment postings",
                entry
            ))

    return entries, errors


Regards,

Patrick


On 19-Jan-19 05:22, Justus Pendleton wrote:
Here's my take at a script that will calculate the money-weighted return for a portfolio (i.e. the XIRR function in spreadsheets).

https://github.com/hoostus/portfolio-returns

All it does it output a single number -- the rate of return. The only real work this script does is crawl through beancount files and figure out what cashflows in & out of the account there were over the specified time period. Then it feeds those cashflows into an IRR calculation.

Here's the return over the past 1 year.

> python irr.py --account Assets:US:Vanguard:Roth --1year /Volumes/my_docs/beancount/my.beancount --internal Income:TaxFree:Dividends
0.72%

(Apparently not a fantastic year for my Roth IRA!)
Here's the return year-to-date.

> python irr.py --account Assets:US:Vanguard:Roth --ytd /Volumes/my_docs/beancount/my.beancount --internal Income:TaxFree:Dividends
115.86%

(All numbers are annualised, so even a tiny increase after 19 days results in a huge annual rate of return.)

It seems to work the way I expect on my own beancount file and a few other small test cases I put together. Feel free to email me or post here if you have problems, suggestions, etc.
--
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 <mailto:beancount+unsubscr...@googlegroups.com>. To post to this group, send email to beancount@googlegroups.com <mailto:beancount@googlegroups.com>. To view this discussion on the web visit https://groups.google.com/d/msgid/beancount/bba922da-b960-480e-9e0c-9aececcf39b1%40googlegroups.com <https://groups.google.com/d/msgid/beancount/bba922da-b960-480e-9e0c-9aececcf39b1%40googlegroups.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.

--
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 post to this group, send email to beancount@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/beancount/9616f1d1-e938-db10-a294-0f0541f9941a%40ch.tario.org.
For more options, visit https://groups.google.com/d/optout.

Reply via email to