On Sat, Aug 9, 2014 at 3:24 PM, Ivanov Dmitry <[email protected]> wrote:

> Suppose, we have $102 on a broker account at the beginning. Then we bought
> and sold 1 share of Apple:
>
> ---------------------------------------------------------
>
> 2014/08/07 * Opening Balances
>   Assets:Broker                 $102
>   Equity
>
> 2014/08/08 * Buying Apple stocks
>   Assets:Broker                      1 AAPL @ $100
>   Expenses:Broker:Commissions        $1
>   Assets:Broker                       $-101
>
> 2014/08/09 * Selling Apple stocks
>   Assets:Broker                      -1 AAPL @ $90
>   Expenses:Broker:Commissions        $1
>   Assets:Broker                       $89
>

This transaction is missing the cost of the lot you're selling.
It should be -1 AAPL {$100} @ $90.
The price is optional; the cash legs are the ones that provide the amounts
of proceeds that determine the PnL. In order to balance the transaction,
you will also need to add an Income leg, which will accumulate the PnL,
which is what you're looking for:

2014/08/09 * Selling Apple stocks
>   Assets:Broker                      -1 AAPL {$100}
>   Expenses:Broker:Commissions        $1
>   Assets:Broker                       $89
>   Income:PnL                       $-10
>



---------------------------------------------------------
>
> Totally we have $12 of losses. How can I get a report, that could clearly
> say that?
>
> When I tried to get a balance report, I got this:
>
>                  $90  Assets:Broker
>                $-102  Equity
>                   $2  Expenses:Broker:Commissions
> --------------------
>                 $-10
>
>
The $-10 above is an artifact of Ledger; it does not force you to book
inventory changes against existing inventory lots at the time of your
transaction - in my opinion that's problematic ultimately - but in any
case, that's not a reliable way to accumulate your PnL (enforcing correct
lots would ensure the final amount is _always_ zero). The method you're
using now also breaks down if you have many many accounts because it would
only provide a single amount in aggregate for all accounts. This is not a
good way to track your PnL. What you need to do instead is as I indicate
previously: put it in an Income account.

IMPORTANT NOTE: You will need a patch in latest Ledger in order for this to
work correctly. Until very recently, Ledger did not use the cost to balance
transactions and this wouldn't work. See Michael Michalmayer's recent post
about this on the list.



>
> How can I include broker commissions into this sum to get $-12?
>


Short answer: at the moment, you can't.

(Well you could if you use virtual transactions, virtual transactions can
do anything because they don't balance, but then there's no point in using
the double-entry method, you might as well use a spreadsheet.)

Long answer:
http://furius.ca/beancount/doc/trading

Also note that there's a lot more to your question, in particular, how you
deduct the commissions if you're only selling part of your lot's shares. To
do this correctly with pro-rata shares as described in the doc above, there
is no implementation in Ledger, HLedger nor Beancount, though I have a
proposal to solve this problem using a simple syntax extension:
http://furius.ca/beancount/doc/proposal-inventory

This is not implemented yet, but I'm working on it for Beancount (will be
done in a few months, I need it for myself, esp. for booking trades with
the average cost method).

-- 

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

Reply via email to