Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Understanding transactions
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  8 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
John Wiegley  
View profile  
 More options Mar 10 2012, 2:51 am
From: John Wiegley <jwieg...@gmail.com>
Date: Sat, 10 Mar 2012 01:51:37 -0600
Local: Sat, Mar 10 2012 2:51 am
Subject: Understanding transactions
The following mini-doc attempts to cover every syntactic corner of the
Ledger transaction syntax.  If I've missed anything, please let me know.

Note that this is a subset of all the syntax allowed in a journal file.  I
haven't covered directives here or file-level comments.

John

# Basic format

The most basic form of transaction is:

    2012-03-10 KFC
        Expenses:Food                $20.00
        Assets:Cash                 $-20.00

This transaction has a date, a payee or description, a target account (the
first posting), and a source account (the second posting).  Each posting
specifies what action is taken related to that account.

## Multiple postings

A transaction can have any number of postings:

    2012-03-10 KFC
        Expenses:Food                $20.00
        Assets:Cash                 $-10.00
        Liabilities:Credit          $-10.00

# Eliding amounts

The first thing you can do to make things easier is elide amounts.  That is,
if exactly one posting has no amount specified, Ledger will infer the inverse
of the other postings' amounts:

    2012-03-10 KFC
        Expenses:Food                $20.00
        Assets:Cash                 $-10.00
        Liabilities:Credit                   ; same as specifying $-10

## Elision with multiple commodities

If the other postings use multiple commodities, Ledger will copy the empty
posting N times and fill in the negated values of the various commodities:

    2012-03-10 KFC
        Expenses:Food                $20.00
        Expenses:Tips                 $2.00
        Assets:Cash              EUR -10.00
        Assets:Cash              GBP -10.00
        Liabilities:Credit

This transaction is identical to writing:

    2012-03-10 KFC
        Expenses:Food                $20.00
        Expenses:Tips                 $2.00
        Assets:Cash              EUR -10.00
        Assets:Cash              GBP -10.00
        Liabilities:Credit          $-22.00
        Liabilities:Credit        EUR 10.00
        Liabilities:Credit        GBP 10.00

# Auxiliary dates

You can associate a second date with a transaction by following the primary
date with an equals sign:

    2012-03-10=2012-03-08 KFC
        Expenses:Food                $20.00
        Assets:Cash                 $-20.00

What this auxiliary date means is entirely up to you.  The only use Ledger has
for it is that if you specify --aux-date, then all reports and calculations
(including pricing) will use the aux date as if it were the primary date.

# Codes

A transaction can have a textual "code".  This has no meaning and is only
displayed by the print command.  Checking accounts often use codes like DEP,
XFER, etc., as well as check numbers.  This is to give you a place to put
those codes:

    2012-03-10 (#100) KFC
        Expenses:Food                $20.00
        Assets:Checking

# Transaction state

A transaction can have a "state": cleared, pending, or uncleared.  The default
is uncleared.  To mark a transaction cleared, put a * before the payee, and
after date or code:

    2012-03-10 * KFC
        Expenses:Food                $20.00
        Assets:Cash

To mark it pending, use a !:

    2012-03-10 ! KFC
        Expenses:Food                $20.00
        Assets:Cash

What these mean is entirely up to you.  The --cleared option will limits to
reports to only cleared items, while --uncleared shows both uncleared and
pending items, and --pending shows only pending items.

I use cleared to mean that I've reconciled the transaction with my bank
statement, and pending to mean that I'm in the middle of a reconciliation.

## Posting state

When you clear a transaction, that's really just shorthand for clearing all of
postings.  That is:

    2012-03-10 * KFC
        Expenses:Food                $20.00
        Assets:Cash

Is the same as writing:

    2012-03-10 KFC
        * Expenses:Food                $20.00
        * Assets:Cash

You can mark individual postings as cleared or pending, in case one "side" of
the transaction has cleared, but the other hasn't yet:

    2012-03-10 * KFC
        Liabilities:Credit            $100.00
        * Assets:Checking

# Transaction notes

After the payee, and after at least one tab or two spaces (or a space and a
tab) [Ledger calls this a "hard separator"], you may introduce a note about
the transaction using the ; character:

    2012-03-10 * KFC                ; yum, chicken...
        Expenses:Food                $20.00
        Assets:Cash

Notes can also appear on the next line, so long as that line begins with
whitespace:

    2012-03-10 * KFC                ; yum, chicken...
        ; and more notes...
        Expenses:Food                $20.00
        Assets:Cash

    2012-03-10 * KFC
        ; just these notes...
        Expenses:Food                $20.00
        Assets:Cash

## Posting notes

A transaction notes is shared by all its postings.  This becomes significant
when querying for metadata (see below).  To specify that a note belongs only
to one posting, place it after a hard separator after the amount, or on its
own line preceded by whitespace:

    2012-03-10 * KFC
        Expenses:Food                $20.00  ; posting #1 note
        Assets:Cash
          ; posting #2 note, extra indentation is optional

# Metadata

One of Ledger's more powerful features is the ability to associate typed
metadata with postings and transactions (by which I mean all of a
transaction's postings).  This metadata can be queried, displayed, and used in
calculations.

The are two forms of metadata: tags and tag/value pairs.

## Metadata tags

To tag an item, put any word not containing whitespace between two colons:

    2012-03-10 * KFC
        Expenses:Food                $20.00
        Assets:Cash
          ; :TAG:

You can gang up multiple tags by sharing colons:

    2012-03-10 * KFC
        Expenses:Food                $20.00
        Assets:Cash
          ; :TAG1:TAG2:TAG3:

## Metadata values

To associate a value with a tag, use the syntax "Key: Value", where the value
can be any string of characters.  Whitespace is needed after the colon, and
cannot appear in the Key:

    2012-03-10 * KFC
        Expenses:Food                $20.00
        Assets:Cash
          ; MyTag: This is just a bogus value for MyTag

### Typed metadata

If a metadata tag ends in ::, it's value will be parsed as a value expression
and stored internally as a value rather than as a string.  For example,
although I can specify a date textually like so:

    2012-03-10 * KFC
        Expenses:Food                $20.00
        Assets:Cash
          ; AuxDate: 2012/02/30

This date is just a string, and won't be parsed as a date unless its value is
used in a date-context (at which time the string is parsed into a date
automatically every time it is needed as a date).  If on the other hand I
write this:

    2012-03-10 * KFC
        Expenses:Food                $20.00
        Assets:Cash
          ; AuxDate:: [2012/02/30]

Then it is parsed as a date only once, and during parsing of the journal file,
which would let me know right away that it is an invalid date.

# Virtual postings

Ordinary, the amounts of all postings in a transaction must balance to zero.
This is non-negotiable.  It's what double-entry accounting is all about!  But
there are some tricks up Ledger's sleeve...

You can use virtual accounts to transfer amounts to an account on the sly,
bypassing the balancing requirement.  The trick is that these postings are not
considered "real", and can be removed from all reports using --real.

To specify a virtual account, surround the account name with parentheses:

    2012-03-10 * KFC
        Expenses:Food                $20.00
        Assets:Cash
        (Budget:Food)               $-20.00

If you want, you can state that virtual postings *should* balance against
one or more other virtual postings by using brackets (which look "harder")
rather than parentheses:

    2012-03-10 * KFC
        Expenses:Food                $20.00
        Assets:Cash
        [Budget:Food]               $-20.00
        [Equity:Budgets]             $20.00

# Expression amounts

An amount is usually a numerical figure with an (optional) commodity, but it
can also be any value expression.  To indicate this, surround the amount
expression with parentheses:

    2012-03-10 * KFC
        Expenses:Food      ($10.00 + $20.00)  ; Ledger adds it up for you
        Assets:Cash

# Balance verification

If at the end of a posting's amount (and after the cost too, if there is one)
there is an equals sign, then Ledger will verify that the total value for that
account as of that posting matches the amount specified.

There are two forms of this features: balance assertions, and balance
assignments.

## Balance assertions

A balance assertion has this general form:

    2012-03-10 KFC
        Expenses:Food                $20.00
        Assets:Cash                 $-20.00 = $500.00

This simply asserts that after subtracting $20.00 from Assets:Cash, that the
resulting total matches $500.00.  If not, it is an error.

## Balance assignments

A balance assignment has this form:

    2012-03-10 KFC
        Expenses:Food                $20.00
        Assets:Cash                         = $500.00

This sets the amount of the second posting to whatever it would need to be for
the total in Assets:Cash to be $500.00 after the posting.  If the resulting
amount is not $-20.00 in this case, it is an error.

## Tip: Resetting a balance

Say your book-keeping has gotten a bit out of date, and your Ledger balance no
longer matches your bank balance.  You can create an adjustment transaction
using balance assignments:

    2012-03-10 Adjustment
        Assets:Cash                         = $500.00
        Equity:Adjustments

Since the second posting is also null, it's value will become the inverse of
whatever amount is generated for the first posting.

This is the only time in ledger ...

read more »


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Gabriel Kerneis  
View profile  
 More options Mar 10 2012, 3:40 am
From: Gabriel Kerneis <kern...@pps.jussieu.fr>
Date: Sat, 10 Mar 2012 09:40:09 +0100
Local: Sat, Mar 10 2012 3:40 am
Subject: Re: Understanding transactions
Hi John,

thanks for the explanations, great piece of documentation.  A few remarks and
questions.

On Sat, Mar 10, 2012 at 01:51:37AM -0600, John Wiegley wrote:
> You can mark individual postings as cleared or pending, in case one "side" of
> the transaction has cleared, but the other hasn't yet:

>     2012-03-10 * KFC
>         Liabilities:Credit            $100.00
>         * Assets:Checking

Is this a spurious * on the first line?

> If you want, you can state that virtual postings *should* balance against
> one or more other virtual postings by using brackets (which look "harder")
> rather than parentheses:

What happens if it doesn't balance?

> It is a general convention within Ledger that the "top" postings in a
> transaction contain the target accounts, while the final posting contains the
> source account.  Whenever a commodity is exchanged like this, the commodity
> moved to the target account is considered "secondary", while the commodity
> used for purchasing and tracked in the cost is "primary".

Great, this part is totally new to me.  Much clearer now.

> For example, consider the stock sale given above:

>     2012-03-10 My Broker
>         Assets:Brokerage             10 AAPL @ $50.00
>         Assets:Brokerage:Cash

> The commodity transferred into Assets:Brokerage is not actually 10 AAPL, but
> rather 10 AAPL {$5.00}.  The figure in braces after the amount is called the
> "lot price".  It's Ledger's way of remembering that this commodity was
> transferred through an exchange, and that $5.00 was the price of that
> exchange.

Is it {$50.00} or {$5.00}? You lost me there.

> Instead, if you reference that same hidden price annotation, Ledger will
> figure out that the price of the shares you're selling, and the cost you're
> selling them at, don't balance:

>     2012-04-10 My Broker
>         Assets:Brokerage:Cash       $750.00
>         Assets:Brokerage            -10 AAPL {$50.00} @ $75.00
> This transaction will fail because the $250.00 price difference between the
> price you bought those shares at, and the cost you're selling them for, does
> not match.  The lot price also identifies which shares you purchased on that
> prior date.

So what is the exact rule when both sides of an @ don't match? Here we have a
$250 difference, and this difference is added to the balance of the transaction
if and only if I use the lot-price annotation { } (or the shorthand {{ }})?

> Plus, it comes with dangers.  This works fine:

>     2012-04-10 My Broker
>         Assets:Brokerage            10 AAPL @ $50.00
>         Assets:Brokerage:Cash       $750.00

I don't understand how this can balance.  Should it be $500.00 instead? (I
believe it's not a typo since you reuse the example several times below).

> In addition to lot prices, you can specify lot dates and reveal them with
> --lot-dates.  Other than that, however, they have no special meaning to
> Ledger.  They are specified after the amount in square brackets (the same way
> that dates are parsed in value expressions):

>     2012-04-10 My Broker
>         Assets:Brokerage:Cash       $375.00
>         Assets:Brokerage            -5 AAPL {$50.00} [2012-04-10] @@ $375.00
>         Income:Capital Gains       $-125.00

Does ledger check that the dates match (ie can I use the lot date as some kind
of inventory tracking)?

> # Lot value expressions

I skipped that part, I feel I need to understand the rest before diving into it.

Best,
--
Gabriel


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
djp  
View profile  
 More options Mar 10 2012, 3:45 am
From: djp <davamu...@gmail.com>
Date: Sat, 10 Mar 2012 00:45:04 -0800 (PST)
Local: Sat, Mar 10 2012 3:45 am
Subject: Re: Understanding transactions

On Saturday, 10 March 2012 02:51:37 UTC-5, John Wiegley wrote:

> The following mini-doc attempts to cover every syntactic corner of the
> Ledger transaction syntax.  If I've missed anything, please let me know.

> Note that this is a subset of all the syntax allowed in a journal file.  I
> haven't covered directives here or file-level comments.

> TODO: I ran out of steam.

> John

wow John, thank you! this makes a HUGE difference (more please ;-)

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Craig Earls  
View profile  
 More options Mar 10 2012, 10:27 am
From: Craig Earls <ender...@gmail.com>
Date: Sat, 10 Mar 2012 08:27:21 -0700
Local: Sat, Mar 10 2012 10:27 am
Subject: Re: Understanding transactions

I will make sure this gets into the docs ASAP.  Along with the other recent
long posting about features and behavior.

On Sat, Mar 10, 2012 at 00:51, John Wiegley <jwieg...@gmail.com> wrote:
> The following mini-doc attempts to cover every syntactic corner of the
> Ledger transaction syntax.  If I've missed anything, please let me know.

--
Craig, Corona De Tucson, AZ
enderw88.wordpress.com

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
John Wiegley  
View profile  
 More options Mar 10 2012, 9:21 pm
From: John Wiegley <jwieg...@gmail.com>
Date: Sat, 10 Mar 2012 20:21:35 -0600
Local: Sat, Mar 10 2012 9:21 pm
Subject: Re: Understanding transactions

>>>>> Gabriel Kerneis <kerneis-klhGwnj84BUD5ynB6aA...@public.gmane.org> writes:
>>     2012-03-10 * KFC
>>         Liabilities:Credit            $100.00
>>         * Assets:Checking
> Is this a spurious * on the first line?

Ah, yes, thank you for catching that.  Craig, can you incorporate that fix?

>> If you want, you can state that virtual postings *should* balance against
>> one or more other virtual postings by using brackets (which look "harder")
>> rather than parentheses:
> What happens if it doesn't balance?

The transaction will result in a balancing error.

>> For example, consider the stock sale given above:

>> 2012-03-10 My Broker Assets:Brokerage 10 AAPL @ $50.00
>> Assets:Brokerage:Cash

>> The commodity transferred into Assets:Brokerage is not actually 10 AAPL,
>> but rather 10 AAPL {$5.00}.  The figure in braces after the amount is
>> called the "lot price".  It's Ledger's way of remembering that this
>> commodity was transferred through an exchange, and that $5.00 was the price
>> of that exchange.
> Is it {$50.00} or {$5.00}? You lost me there.

Oops, it should be {$50.00}, you are right.  The @ goes to {} just as @@ goes
to {{}}.

>> 2012-04-10 My Broker Assets:Brokerage:Cash $750.00 Assets:Brokerage -10
>> AAPL {$50.00} @ $75.00
> So what is the exact rule when both sides of an @ don't match? Here we have
> a $250 difference, and this difference is added to the balance of the
> transaction if and only if I use the lot-price annotation { } (or the
> shorthand {{ }})?

Yes.  Without the pricing annotation, Ledger doesn't know there is a
difference between what you paid in the past, and what you are paying now.  It
is this difference which it accumulates in either Equity:Capital Gains or
Equity:Capital Losses (those strings soon to be made configurable).

>> Plus, it comes with dangers.  This works fine:

>> 2012-04-10 My Broker Assets:Brokerage 10 AAPL @ $50.00
>> Assets:Brokerage:Cash $750.00
> I don't understand how this can balance.  Should it be $500.00 instead? (I
> believe it's not a typo since you reuse the example several times below).

Sorry, in this case it should be $500.00.  Guess it got too late for me. :)

When this document gets converted into Texinfo format by Craig, we'll add
markers to turn all these examples into regression tests, to prove that each
example does what I think it should.

> Does ledger check that the dates match (ie can I use the lot date as some
> kind of inventory tracking)?

No.  The only way to find a discrepancy is to add --lot-dates to a balance
report and look and see what results.  There is no case in Ledger where it
ensures that transactions balance against *other* transactions.  You can
balance the postings within a transaction, or you can balance an amount
against a current account total, but you can say that transaction B should
match the details of some earlier transaction A.

>> # Lot value expressions
> I skipped that part, I feel I need to understand the rest before diving into
> it.

Don't blame you. :) That feature is more to provide infrastructure.  It gets
used behind the scenes by -H and a few other features now.  Plus, it's an
access point into the valuation logic for those who have the need.  I'm
guessing 99% of people won't use it, but I'm glad it's there because Ledger
itself now uses it!

John


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Simon Michael  
View profile  
 More options Mar 11 2012, 5:01 pm
From: Simon Michael <si...@joyful.com>
Date: Sun, 11 Mar 2012 14:01:47 -0700
Local: Sun, Mar 11 2012 5:01 pm
Subject: Re: Understanding transactions
Awesome docs, John!

I think https://github.com/jwiegley/ledger/commits/next/doc/ledger3.texi will show when they land on the site.
(Thanks Craig!)


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
thierry  
View profile  
 More options Mar 14 2012, 4:24 pm
From: thierry <thierry.dauco...@free.fr>
Date: Wed, 14 Mar 2012 13:24:09 -0700 (PDT)
Local: Wed, Mar 14 2012 4:24 pm
Subject: Re: Understanding transactions

On Mar 10, 8:51 am, John Wiegley <jwieg...@gmail.com> wrote:

> ## Primary and secondary commodities

> It is a general convention within Ledger that the "top" postings in a
> transaction contain the target accounts, while the final posting contains the
> source account.  Whenever a commodity is exchanged like this, the commodity
> moved to the target account is considered "secondary", while the commodity
> used for purchasing and tracked in the cost is "primary".

> Said another way, whenever Ledger sees a posting cost of the form "AMOUNT @
> AMOUNT", the commodity used in the second amount is marked "primary".

> The only meaning a primary commodity has is that -V flag will never convert a
> primary commodity into any other commodity.  -X still will, however.

Is that really important? I have 10% of my transactions with "top"
posting as source, and "final" posting as target. And IMHO, I do
prefer that source is first, and target is last. Can I safely ignore
this ledger convention?
I realize also that I am never using -V, but only -X, and this may be
the explanation.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
John Wiegley  
View profile  
 More options Mar 15 2012, 12:58 am
From: John Wiegley <jwieg...@gmail.com>
Date: Wed, 14 Mar 2012 23:58:12 -0500
Local: Thurs, Mar 15 2012 12:58 am
Subject: Re: Understanding transactions

>>>>> thierry  <thierry.daucourt-GANU6spQ...@public.gmane.org> writes:
> Is that really important? I have 10% of my transactions with "top" posting
> as source, and "final" posting as target. And IMHO, I do prefer that source
> is first, and target is last. Can I safely ignore this ledger convention?  I
> realize also that I am never using -V, but only -X, and this may be the
> explanation.

It's not important, it only affects the behavior of -V.  -V tries to be a
shorthand for "show me values in terms of the commodities I used to purchase
things with".  This was the best heuristic I could come up with.

John


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »