close, equity
Prints a "closing balances" transaction and an "opening balances"
transaction that bring account balances to and from zero, respectively.
These can be added to your journal file(s), eg to bring asset/liability
balances forward into a new journal file, or to close out
revenues/expenses to retained earnings at the end of a period.

_FLAGS

You can print just one of these transactions by using the --close or
--open flag. You can customise their descriptions with the --close-desc
and --open-desc options.

One amountless posting to "equity:opening/closing balances" is added to
balance the transactions, by default. You can customise this account
name with --close-acct and --open-acct; if you specify only one of
these, it will be used for both.

With --x/--explicit, the equity posting's amount will be shown. And if
it involves multiple commodities, a posting for each commodity will be
shown, as with the print command.

With --interleaved, the equity postings are shown next to the postings
they balance, which makes troubleshooting easier.

By default, transaction prices in the journal are ignored when
generating the closing/opening transactions. With --show-costs, this
cost information is preserved (balance -B reports will be unchanged
after the transition). Separate postings are generated for each cost in
each commodity. Note this can generate very large journal entries, if
you have many foreign currency or investment transactions.

close usage

If you split your journal files by time (eg yearly), you will typically
run this command at the end of the year, and save the closing
transaction as last entry of the old file, and the opening transaction
as the first entry of the new file. This makes the files self contained,
so that correct balances are reported no matter which of them are
loaded. Ie, if you load just one file, the balances are initialised
correctly; or if you load several files, the redundant closing/opening
transactions cancel each other out. (They will show up in print or
register reports; you can exclude them with a query like
not:desc:'(opening|closing) balances'.)

If you're running a business, you might also use this command to "close
the books" at the end of an accounting period, transferring income
statement account balances to retained earnings. (You may want to change
the equity account name to something like "equity:retained earnings".)

By default, the closing transaction is dated yesterday, the balances are
calculated as of end of yesterday, and the opening transaction is dated
today. To close on some other date, use: hledger close -e OPENINGDATE.
Eg, to close/open on the 2018/2019 boundary, use -e 2019. You can also
use -p or date:PERIOD (any starting date is ignored).

Both transactions will include balance assertions for the
closed/reopened accounts. You probably shouldn't use status or realness
filters (like -C or -R or status:) with this command, or the generated
balance assertions will depend on these flags. Likewise, if you run this
command with --auto, the balance assertions will probably always require
--auto.

Examples:

Carrying asset/liability balances into a new file for 2019:

$ hledger close -f 2018.journal -e 2019 assets liabilities --open
    # (copy/paste the output to the start of your 2019 journal file)
$ hledger close -f 2018.journal -e 2019 assets liabilities --close
    # (copy/paste the output to the end of your 2018 journal file)

Now:

$ hledger bs -f 2019.journal                   # one file - balances are correct
$ hledger bs -f 2018.journal -f 2019.journal   # two files - balances still correct
$ hledger bs -f 2018.journal not:desc:closing  # to see year-end balances, must exclude closing txn

Transactions spanning the closing date can complicate matters, breaking
balance assertions:

2018/12/30 a purchase made in 2018, clearing the following year
    expenses:food          5
    assets:bank:checking  -5  ; [2019/1/2]

Here's one way to resolve that:

; in 2018.journal:
2018/12/30 a purchase made in 2018, clearing the following year
    expenses:food          5
    liabilities:pending

; in 2019.journal:
2019/1/2 clearance of last year's pending transactions
    liabilities:pending    5 = 0
    assets:checking
