Re: [emacs] using ledger-mode for beancount

2019-01-20 Thread Daniele Nicolodi
On 20/01/2019 09:26, Stefano Zacchiroli wrote:
> Since we're talking about customizability, it would be nice to have a
> local variable to set the desired amount of indentation. I know
> beancount goes for 2 spaces by default, but I currently use 4, for
> consistency with ledger. YMMV.

It is already there:

(setq beancount-posting-alignment-column 4)

Ciao,
Dan

-- 
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/51ff28d4-f2fe-73b9-bacd-ecc0f2296418%40grinta.net.
For more options, visit https://groups.google.com/d/optout.


Re: Portfolio returns calculator

2019-01-20 Thread 'Patrick Ruckstuhl' via Beancount

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 
.
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/bba922da-b960-480e-9e0c-9aececcf39b1%40googlegroups.com 
.

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.


Re: Supported syntaxes for acquiring lots

2019-01-20 Thread Martin Blais
That sounds like a bug
It should be accepted without a zero

On Sat, Jan 19, 2019, 12:07 Martin Michlmayr  * Jeff Brantley  [2019-01-19 11:23]:
> > How new? I'm running Beancount 2.2.0, per `bean-check --version`.
> >
> > If I try to use { # 123 USD} instead of {{123 USD}}, bean-check barfs
> with
> > "Too many missing numbers for currency group 'USD'" for each instance.
>
> It has to be
>
> { 0 # 123 USD}
>
> which I believe means: 0 per share plus a total of 123 USD.
>
> One of the examples previously given is
>Assets:Investments 100 MSFT {42.00 # 9.95 USD}
> i.e. 100 shares at $42 each plus $9.95 fees.
>
> Martin, it sounds like { 0 # xx USD} is preferred over {{...}}, right?
> (I'm wondering if ledger2beancount should use this syntax.  Then
> again, {{ ... }} works)
> --
> Martin Michlmayr
> https://www.cyrius.com/
>
> --
> 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/20190119200725.r6etrpaig7xi6xgx%40jirafa.cyrius.com
> .
> 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/CAK21%2BhOV4mXSOubkQrKpKN7SoqTU6GUuDc9yH3T9MbUoHb1YdQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [emacs] using ledger-mode for beancount

2019-01-20 Thread Stefano Zacchiroli
On Sat, Jan 19, 2019 at 10:59:36PM -0700, Daniele Nicolodi wrote:
> I have now re-implemented number alignment.  It is automatically
> triggered on newline and on tab.  I also implemented
> beancount-align-transaction that you can bind to C-C C-q to obtain the
> ledger-mode functionality.

I've tested this, and it works great!

I was initially surprised that the function doesn't also align each line
of the transaction before aligning the amounts (i.e., doing the
equivalent of hitting TAB on each line and *then* align the amounts),
but that is indeed consistent with ledger-mode's behavior.

> By default numbers are aligned to the 52nd column, controlled by the
> beancount-posting-amount-alignment-column defcustom variable. If that
> variable is set to nil the column is computed in a similar way asin
> beancount-align-numbers. This is probably quite slow for huge ledger
> files, and I personally prefer to have the alignment independent of
> the length of the account names.

That is my own preference too, but it's nice to have the re-align
everything option, for those who really want to.

Since we're talking about customizability, it would be nice to have a
local variable to set the desired amount of indentation. I know
beancount goes for 2 spaces by default, but I currently use 4, for
consistency with ledger. YMMV.

Also, on your yesterday's point about breaking the current behavior, I
guess this list is a good start to check if there really are people who
want TAB to trigger autocompletion when the cursor is in the middle of
an account name. But anyway, I'm guessing you'll eventually submit these
amazing improvements to Martin B. as PR, so you can also let him be the
arbiter of the preferred behavior there.

Thanks a lot for all this!

Ciao,
-- 
Stefano Zacchiroli . z...@upsilon.cc . upsilon.cc/zack . . o . . . o . o
Computer Science Professor . CTO Software Heritage . . . . . o . . . o o
Former Debian Project Leader & OSI Board Director  . . . o o o . . . o .
« the first rule of tautology club is the first rule of tautology club »

-- 
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/20190120162658.tmm5fa6m45w2tdxy%40upsilon.cc.
For more options, visit https://groups.google.com/d/optout.


Re: [emacs] using ledger-mode for beancount

2019-01-20 Thread Stefano Zacchiroli
On Sun, Jan 20, 2019 at 09:32:24AM -0700, Daniele Nicolodi wrote:
> (setq beancount-posting-alignment-column 4)

Nice :-)

-- 
Stefano Zacchiroli . z...@upsilon.cc . upsilon.cc/zack . . o . . . o . o
Computer Science Professor . CTO Software Heritage . . . . . o . . . o o
Former Debian Project Leader . OSI Board Director  . . . o o o . . . o .
« the first rule of tautology club is the first rule of tautology club »

-- 
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/20190120164800.xpqczk2tnirfqhhp%40upsilon.cc.
For more options, visit https://groups.google.com/d/optout.


Re: [emacs] using ledger-mode for beancount

2019-01-20 Thread Daniele Nicolodi
On 20/01/2019 19:36, Daniele Nicolodi wrote:
> I changed the customization variable names to
> 
> beancount-transaction-indent
> beancount-number-alignment-column
> 
> which seem more descriptive (and a bit shorter).

I forgot to mention that to obtain automatic alignment column
determination now beancount-number-alignment-column should be set to 0
instead than nil. This is a bit easier for the customize interface.

Cheers,
Dan

-- 
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/e0e893fa-146f-6de5-bec4-4d4a1e05565e%40grinta.net.
For more options, visit https://groups.google.com/d/optout.


Re: [emacs] using ledger-mode for beancount

2019-01-20 Thread Daniele Nicolodi
Hi Stefano,

I just commit another round of updated.

On 20/01/2019 09:26, Stefano Zacchiroli wrote:
> On Sat, Jan 19, 2019 at 10:59:36PM -0700, Daniele Nicolodi wrote:
> I was initially surprised that the function doesn't also align each line
> of the transaction before aligning the amounts (i.e., doing the
> equivalent of hitting TAB on each line and *then* align the amounts),
> but that is indeed consistent with ledger-mode's behavior.

Now you can use a prefix argument to align everything. I realized that
automatic alignment does not do the right thing if there are posting
metadata. This remains to be fixed.

>> By default numbers are aligned to the 52nd column, controlled by the
>> beancount-posting-amount-alignment-column defcustom variable. If that
>> variable is set to nil the column is computed in a similar way asin
>> beancount-align-numbers. This is probably quite slow for huge ledger
>> files, and I personally prefer to have the alignment independent of
>> the length of the account names.
> 
> That is my own preference too, but it's nice to have the re-align
> everything option, for those who really want to.

I changed the customization variable names to

beancount-transaction-indent
beancount-number-alignment-column

which seem more descriptive (and a bit shorter).

I reworked completion-at-point extensively, and I think I fixed the
problem you were seeing. What I would like to do now is to get rid of
the need for beancount-init-accounts but I am afraid completion would
slow down considerably in very large buffers. On the other hand,
completion for tags does not use any caching and I haven't seen
complaints about it.

Please test and let me know.

Cheers,
Dan

-- 
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/cd6c829a-f330-083c-9017-c9dfb50ca1c9%40grinta.net.
For more options, visit https://groups.google.com/d/optout.