Re: State of capital gains tracking in hledger

194 views
Skip to first unread message

Martin Blais

unread,
Jun 8, 2015, 12:40:30 AM6/8/15
to ma.k...@gmail.com, bean...@googlegroups.com
(Moved thread from hledger list, to be polite and avoid spamming too much beancount stuff on Simon's list. Answers below.)


On Sun, Jun 7, 2015 at 3:39 PM, <ma.k...@gmail.com> wrote:
Hi Simon, Hi Martin,
thank you very much for the explanations that you added!

Regarding beancount: I have read the comparison document you (Martin) had written. I like it very much and I agree with many of the steps you have taken there. At the same time, I am somewhat put off by the lengthy installation process that your documents lay out.

Actually, if you use pip3 and apt-get/brew on a Linux of Mac box it takes about 10 minutes to setup the whole thing from scratch. I bought a new computer a few weeks ago (a MBA 11") and went through this myself. Maybe the length of my document is misleading. Here's the TL;DR:

- Install Python >=3.3 using the .exe from python.org
- pip3 install python-dateutil bottle ply
- apt-get install wget (on Linux), or brew install wget (on Mac)
- cd beancount
  (a) install with: sudo python3 setup.py install
  (b) or setup in place with: make build, + export PATH and PYTHONPATH environment variables.

I'll add these summary instructions to my install doc.



 
In fact, I'm actually worried that it may not run on Windows at all. You mention wget and ncurses if I remember correctly. How necessary are those? You are developing on Linux or Mac, I suppose?

That is correct.
I have never tried to install it myself on Windows.
(Has anyone on the list installed Beancount on Windows? What was your experience like?)

Some notes:

- wget is only necessary for bean-bake. You don't need it unless you want to zip up the contents of the web interface to static HTML files (to share with your accountant, for instance). Nothing will fail unless you use bean-bake. You don't need it.

- curses is only there to compute the width of the terminal, which is used to set default values for rendering tables from the SQL-like query tool that comes with it, e.g. how many lines to page by for long output. I could live without it just fine, i.e., change the code so that when it is not available everything would still work okay and it would use reasonable default values. (Also, normally curses is installed on a regular C/Python Windows box, you shouldn't have to install this, this was just there for someone who is using an exotic Linux distribution.)

 I should probably create a VM on gcloud/amazon to go through it once and document the process. 



On Sunday, June 7, 2015 at 1:29:09 AM UTC+8, Martin Blais wrote:
On Sat, Jun 6, 2015 at 1:17 PM, Martin Blais <bl...@furius.ca> wrote:
On Sat, Jun 6, 2015 at 9:25 AM, Simon Michael <si...@joyful.com> wrote:
Welcome Matthias,

hledger doesn't currently parse Ledger's {...} prices (with no equals sign). I don't fully understand what those do. The Ledger manual implies they are equivalent to @ (a fluctuating unit price), but what does

 -50 AAPL {$30.00} @ $50.00 

mean ?

Indeed.

In Beancount the semantics of this is that 50 units of "AAPL at $30 cost basis" are added to the inventory, and a price annotation of $50 is present on the posting. The cost basis is the value used in balancing the transaction. The price annotation is not entirely ignored however, it is used by plugins:

beancount.ops.implicit_prices: Automatically creates price directives corresponding to these annotations. This fills in values for the in-memory database of prices which is then used in reporting.

beancount.plugins.sellgains: Applies a secondary balance check that uses the price instead of the cost basis, and that also ignores any Income postings in the transaction. See the comment at the top of this file for a rationale and examples: https://bitbucket.org/blais/beancount/src/c8cedf46c100d0cb80553b091aff481243ade44d/src/python/beancount/plugins/sellgains.py?at=default
This additional check finds many errors in data entry.

I clarified the example in the sellgains plugin that explains how this works; here's an improved version:


 

Finally, when you write custom scripts against your data you can find the price annotations on the Python API and use them in creative ways if you want.



Currently in hledger all prices are fixed, like Ledger's {=...} prices (which we do parse). So I think there's no practical way to track fluctuating prices in hledger without implementing https://github.com/simonmichael/hledger/issues/131 (which should be not too hard).



On Jun 6, 2015, at 3:36 AM, ma.k...@gmail.com wrote:

Hi,
I'm trying to figure out whether I should use ledger, hledger or beancount. Hledger has a big head start for me because the binaries you provide make it so much easier to get started, especially on Windows systems.

Now I'm wondering what the state of capital gains tracking is in hledger.
Is it completely impossible with the lack of fluctuating prices?
Or can I make it work by only tracking differences in sales prices?

I'm looking at the following example from the ledger manual (see below)
Running hledger -f test.dat balance, I receive the error "unexpected {" referring to the { in the sale.
is there any way to make something like this work at the moment? What are the plans for this?

Best regards,
Matthias

2004/05/01 Stock purchase
    Assets:Broker                     50 AAPL @ $30.00
    Expenses:Broker:Commissions        $19.95
    Assets:Broker                  $-1,519.95

2005/08/01 Stock sale
    Assets:Broker                    -50 AAPL {$30.00} @ $50.00
    Expenses:Broker:Commissions        $19.95
    Income:Capital Gains           $-1,000.00
    Assets:Broker                   $2,480.05


--
You received this message because you are subscribed to the Google Groups "hledger" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hledger+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google Groups "hledger" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hledger+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

redst...@gmail.com

unread,
Jun 8, 2015, 7:42:11 PM6/8/15
to bean...@googlegroups.com
(Has anyone on the list installed Beancount on Windows? What was your experience like?)

I tried and have been unsuccessful so far. I haven't spent much time on it though. The problem is, the install process requires C compilation at some stage, and this fails:

src/python/beancount/parser/parser.c: In function 'PyInit__parser': <command-line>:0:20: error: invalid suffix "f1cf...." on integer constant
src/python/beancount/parser/parser.c:272:50: note: in expansion of macro 'PARSE_SOURCE_HASH'

Steps to get this far:
1) Install Python-3.4 under Windows
2) Install MinGW32 for Windows. I believe the MinGW Base System (chosen via the MinGW installer) is adequate, though I'm not sure.
4) Set your PATH in a cmd window to include both MinGW\bin and \Python34
5) Open a cmd window and follow beancount install instructions

Perhaps this will work better if Visual C++ is used instead of MinGW, I don't know. I haven't dug any deeper. I'll post if I do.

redst...@gmail.com

unread,
Jun 8, 2015, 7:48:50 PM6/8/15
to bean...@googlegroups.com, redst...@gmail.com
Sorry, meant to start a new thread for installation on Windows. It's now at:
https://groups.google.com/d/msg/beancount/ExjKmJoMpzc/Fft02VUA_zoJ

Martin Blais

unread,
Jun 10, 2015, 2:02:24 AM6/10/15
to Matthias Kauer, bean...@googlegroups.com
Hi Mathias,

I created a 2012 Windows VM on gcloud and successfully built a working install of Beancount using Cygwin on it. It was surprisingly easy, and all the unit test just passed with no changes.

Here's how to do this:

  • Install the latest Cygwin. This may take a while (it downloads a lot of stuff), but it is well worth it in any case. But before you kick off the install, make sure the following packages are all manually enabled in the interface provided by setup.exe (they’re not selected by default):

    • python3

    • python3-setuptools

    • mercurial

    • make

    • gcc-core

    • flex

    • bison

    • wget

  • Start a new Cygwin bash shell (there should be a new icon on your desktop) and install the pip3 installer tool by running this command:
    easy_install3.3 pip

At this point, you should be able to follow the regular instructions from the install file.


I rewrote the installation instructions to be much more brief and simple and include a section specifically on installing on Windows:

(The way it was written before made it sound a lot more complicated than it actually is.)

I hope this is useful,


Reply all
Reply to author
Forward
0 new messages