diff --git a/hledger/hledger.1 b/hledger/hledger.1 index 3894be4f1..69e1e33a8 100644 --- a/hledger/hledger.1 +++ b/hledger/hledger.1 @@ -2453,46 +2453,96 @@ balance, bal .PD Show accounts and their balances. .PP -The balance command is hledger\[aq]s most versatile command. -Note, despite the name, it is not always used for showing real-world -account balances; the more accounting-aware balancesheet and -incomestatement may be more convenient for that. +\f[C]balance\f[R] is one of hledger\[aq]s oldest and most versatile +commands, for listing account balances, balance changes, values, value +changes and more, during one time period or many. +Generally it shows a table, with rows representing accounts, and columns +representing periods. .PP -By default, it displays all accounts, and each account\[aq]s change in -balance during the entire period of the journal. -Balance changes are calculated by adding up the postings in each -account. -You can limit the postings matched, by a query, to see fewer accounts, -changes over a different time period, changes from only cleared -transactions, etc. +Note there are some higher-level variants of the \f[C]balance\f[R] +command with convenient defaults, which can be simpler to use: +\f[C]balancesheet\f[R], \f[C]balancesheetequity\f[R], \f[C]cashflow\f[R] +and \f[C]incomestatement\f[R]. +When you need more control, then use \f[C]balance\f[R]. +.SS balance features .PP -If you include an account\[aq]s complete history of postings in the -report, the balance change is equivalent to the account\[aq]s current -ending balance. -For a real-world account, typically you won\[aq]t have all transactions -in the journal; instead you\[aq]ll have all transactions after a certain -date, and an \[dq]opening balances\[dq] transaction setting the correct -starting balance on that date. -Then the balance command will show real-world account balances. -In some cases the -H/--historical flag is used to ensure this (more -below). +Here\[aq]s a quick overview of the \f[C]balance\f[R] command\[aq]s +features, followed by more detailed descriptions and examples. +Many of these work with the higher-level commands as well. .PP -This command also supports the output destination and output format -options The output formats supported are (in most modes): \f[C]txt\f[R], -\f[C]csv\f[R], \f[C]html\f[R], and \f[C]json\f[R]. +\f[C]balance\f[R] can show.. +.IP \[bu] 2 +accounts as a list (\f[C]-l\f[R]) or a tree (\f[C]-t\f[R]) +.IP \[bu] 2 +optionally depth-limited (\f[C]-[1-9]\f[R]) +.IP \[bu] 2 +sorted by declaration order and name, or by amount .PP -The balance command can produce several styles of report: +\&..and their.. +.IP \[bu] 2 +balance changes (the default) +.IP \[bu] 2 +or actual and planned balance changes (\f[C]--budget\f[R]) +.IP \[bu] 2 +or value of balance changes (\f[C]-V\f[R]) +.IP \[bu] 2 +or change of balance values (\f[C]--valuechange\f[R]) .PP -.SS Single-period flat balance report +\&..in.. +.IP \[bu] 2 +one time period (the whole journal period by default) +.IP \[bu] 2 +or multiple periods (\f[C]-D\f[R], \f[C]-W\f[R], \f[C]-M\f[R], +\f[C]-Q\f[R], \f[C]-Y\f[R], \f[C]-p INTERVAL\f[R]) .PP -This is the default for hledger\[aq]s balance command: a flat list of -all (or with a query, matched) accounts, showing full account names. -Accounts are sorted by declaration order if any, and then by account -name. -Accounts which have zero balance are not shown unless -\f[C]-E/--empty\f[R] is used. -The reported balances\[aq] total is shown as the last line, unless -disabled by \f[C]-N\f[R]/\f[C]--no-total\f[R]. +\&..either.. +.IP \[bu] 2 +per period (the default) +.IP \[bu] 2 +or accumulated since report start date (\f[C]--cumulative\f[R]) +.IP \[bu] 2 +or accumulated since account creation (\f[C]--historical/-H\f[R]) +.PP +\&..possibly converted to.. +.IP \[bu] 2 +cost (\f[C]--value=cost[,COMM]\f[R]/\f[C]--cost\f[R]/\f[C]-B\f[R]) +.IP \[bu] 2 +or market value, as of transaction dates (\f[C]--value=then[,COMM]\f[R]) +.IP \[bu] 2 +or at period ends (\f[C]--value=end[,COMM]\f[R]) +.IP \[bu] 2 +or now (\f[C]--value=now\f[R]) +.IP \[bu] 2 +or at some other date (\f[C]--value=YYYY-MM-DD\f[R]) +.PP +\&..with.. +.IP \[bu] 2 +totals (\f[C]-T\f[R]), averages (\f[C]-A\f[R]), percentages +(\f[C]-%\f[R]), inverted sign (\f[C]--invert\f[R]) +.IP \[bu] 2 +rows and columns swapped (\f[C]--transpose\f[R]) +.IP \[bu] 2 +another field used as account name (\f[C]--pivot\f[R]) +.IP \[bu] 2 +custom-formatted line items (single-period reports only) +(\f[C]--format\f[R]) +.PP +This command supports the output destination and output format options, +with output formats \f[C]txt\f[R], \f[C]csv\f[R], \f[C]json\f[R], and +(multi-period reports only:) \f[C]html\f[R]. +In \f[C]txt\f[R] output in a colour-supporting terminal, negative +amounts are shown in red. +.SS Simple balance report +.PP +With no arguments, \f[C]balance\f[R] shows a list of all accounts and +their change of balance - ie, the sum of posting amounts, both inflows +and outflows - during the entire period of the journal. +For real-world accounts, this should also match their end balance at the +end of the journal period (more on this below). +.PP +Accounts are sorted by declaration order if any, and then alphabetically +by account name. +For instance, using examples/sample.journal: .IP .nf \f[C] @@ -2509,12 +2559,51 @@ $ hledger bal \f[R] .fi .PP -.SS Single-period tree-mode balance report +Accounts with a zero balance (and no non-zero subaccounts, in tree mode +- see below) are hidden by default. +Use \f[C]-E/--empty\f[R] to show them (revealing +\f[C]assets:bank:checking\f[R] here): +.IP +.nf +\f[C] +$ hledger -f examples/sample.journal bal -E + 0 assets:bank:checking + $1 assets:bank:saving + $-2 assets:cash + $1 expenses:food + $1 expenses:supplies + $-1 income:gifts + $-1 income:salary + $1 liabilities:debts +-------------------- + 0 +\f[R] +.fi .PP -With the \f[C]-t/--tree\f[R] flag, accounts are displayed -hierarchically, showing subaccounts as short names indented below their -parent. -(This is the default style in Ledger and in older hledger versions.) +The total of the amounts displayed is shown as the last line, unless +\f[C]-N\f[R]/\f[C]--no-total\f[R] is used. +.SS Filtered balance report +.PP +You can show fewer accounts, a different time period, totals from +cleared transactions only, etc. +by using query arguments or options to limit the postings being matched. +Eg: +.IP +.nf +\f[C] +$ hledger bal --cleared assets date:200806 + $-2 assets:cash +-------------------- + $-2 +\f[R] +.fi +.SS List or tree mode +.PP +By default, or with \f[C]-l/--flat\f[R], accounts are shown as a flat +list with their full names visible, as in the examples above. +.PP +With \f[C]-t/--tree\f[R], the account hierarchy is shown, with +subaccounts\[aq] \[dq]leaf\[dq] names indented below their parent: .IP .nf \f[C] @@ -2534,43 +2623,63 @@ $ hledger balance \f[R] .fi .PP -For more compact output, \[dq]boring\[dq] accounts containing a single -interesting subaccount and no balance of their own -(\f[C]assets:bank\f[R] and \f[C]liabilities\f[R] here) are elided into -the following line, unless \f[C]--no-elide\f[R] is used. -And accounts which have zero balance and no non-zero subaccounts are -omitted, unless \f[C]-E/--empty\f[R] is used. +Notes: +.IP \[bu] 2 +\[dq]Boring\[dq] accounts are combined with their subaccount for more +compact output, unless \f[C]--no-elide\f[R] is used. +Boring accounts have no balance of their own and just one subaccount (eg +\f[C]assets:bank\f[R] and \f[C]liabilities\f[R] above). +.IP \[bu] 2 +All balances shown are \[dq]inclusive\[dq], ie including the balances +from all subaccounts. +Note this means some repetition in the output, which requires +explanation when sharing reports with non-plaintextaccounting-users. +A tree mode report\[aq]s final total is the sum of the top-level +balances shown, not of all the balances shown. +.IP \[bu] 2 +Each group of sibling accounts (ie, under a common parent) is sorted +separately. +.SS Depth limiting .PP -Account balances in tree mode are \[dq]inclusive\[dq] - they include the -balances of any subaccounts. -Eg, the \f[C]assets\f[R] \f[C]$-1\f[R] balance here includes the -\f[C]$1\f[R] from \f[C]assets:bank:saving\f[R] and the \f[C]$-2\f[R] -from \f[C]assets:cash\f[R]. -(And it would include balance posted to the \f[C]assets\f[R] account -itself, if there was any). -Note this causes some repetition, and the final total (\f[C]0\f[R]) is -the sum of the top-level balances, not of all the balances shown. +With a \f[C]depth:N\f[R] query, or \f[C]--depth N\f[R] option, or just +\f[C]-N\f[R], balance reports will show accounts only to the specified +depth, hiding the deeper subaccounts. +Account balances at the depth limit always include the balances from any +hidden subaccounts (even in list mode). +This can be useful for getting an overview. +Eg, limiting to depth 1: +.IP +.nf +\f[C] +$ hledger balance -N -1 + $-1 assets + $2 expenses + $-2 income + $1 liabilities +\f[R] +.fi +.PP +You can also hide top-level account name parts, using +\f[C]--drop N\f[R]. +This can be useful for hiding repetitive top-level account names: +.IP +.nf +\f[C] +$ hledger bal expenses --drop 1 + $1 food + $1 supplies +-------------------- + $2 +\f[R] +.fi .PP -Each group of sibling accounts is sorted separately, by declaration -order and then by account name. .SS Multi-period balance report .PP -Multi-period balance reports are a very useful hledger feature, -activated if you provide one of the reporting interval flags, such as -\f[C]-M\f[R]/\f[C]--monthly\f[R]. -They are similar to single-period balance reports, but they show the -report as a table, with columns representing one or more successive time -periods. -This is the usually the preferred style of balance report in hledger -(even for a single period). -.PP -Multi-period balance reports come in several types, showing different -information: -.IP "1." 3 -A balance change report: by default, each column shows the sum of -postings in that period, ie the account\[aq]s change of balance in that -period. -This is useful eg for a monthly income statement: +With a report interval (set by the \f[C]-D/--daily\f[R], +\f[C]-W/--weekly\f[R], \f[C]-M/--monthly\f[R], \f[C]-Q/--quarterly\f[R], +\f[C]-Y/--yearly\f[R], or \f[C]-p/--period\f[R] flag), \f[C]balance\f[R] +shows a tabular report, with columns representing successive time +periods (and a title): .IP .nf \f[C] @@ -2587,272 +2696,349 @@ Balance changes in 2008: || $-1 $1 0 0 \f[R] .fi -.IP "2." 3 -A cumulative end balance report: with \f[C]--cumulative\f[R], each -column shows the end balance for that period, accumulating the changes -across periods, starting from 0 at the report start date: -.RS 4 -.IP -.nf -\f[C] -$ hledger balance --quarterly income expenses -E --cumulative -Ending balances (cumulative) in 2008: - - || 2008/03/31 2008/06/30 2008/09/30 2008/12/31 -===================++================================================= - expenses:food || 0 $1 $1 $1 - expenses:supplies || 0 $1 $1 $1 - income:gifts || 0 $-1 $-1 $-1 - income:salary || $-1 $-1 $-1 $-1 --------------------++------------------------------------------------- - || $-1 0 0 0 -\f[R] -.fi -.RE -.IP "3." 3 -A historical end balance report: with \f[C]--historical/-H\f[R], each -column shows the actual historical end balance for that period, -accumulating the changes across periods, and including the balance from -any postings before the report start date. -This is useful eg for a multi-period balance sheet, and when you want to -see balances only after a certain date: -.RS 4 -.IP -.nf -\f[C] -$ hledger balance \[ha]assets \[ha]liabilities --quarterly --historical --begin 2008/4/1 -Ending balances (historical) in 2008/04/01-2008/12/31: - - || 2008/06/30 2008/09/30 2008/12/31 -======================++===================================== - assets:bank:checking || $1 $1 0 - assets:bank:saving || $1 $1 $1 - assets:cash || $-2 $-2 $-2 - liabilities:debts || 0 0 $1 -----------------------++------------------------------------- - || 0 0 0 -\f[R] -.fi -.RE .PP -Note that \f[C]--cumulative\f[R] or \f[C]--historical/-H\f[R] disable -\f[C]--row-total/-T\f[R], since summing end balances generally does not -make sense. +Notes: +.IP \[bu] 2 +The report\[aq]s start/end dates will be expanded, if necessary, to +fully encompass the displayed subperiods (so that the first and last +subperiods have the same duration as the others). +.IP \[bu] 2 +Leading and trailing periods (columns) containing all zeroes are not +shown, unless \f[C]-E/--empty\f[R] is used. +.IP \[bu] 2 +Accounts (rows) containing all zeroes are not shown, unless +\f[C]-E/--empty\f[R] is used. +.IP \[bu] 2 +Amounts with many commodities are shown in abbreviated form, unless +\f[C]--no-elide\f[R] is used. +\f[I](experimental)\f[R] +.IP \[bu] 2 +Average and/or total columns can be added with the +\f[C]-A/--average\f[R] and \f[C]-T/--row-total\f[R] flags. +.IP \[bu] 2 +The \f[C]--transpose\f[R] flag can be used to exchange rows and columns. +.IP \[bu] 2 +The \f[C]--pivot FIELD\f[R] option causes a different transaction field +to be used as \[dq]account name\[dq]. +See PIVOTING. .PP -With a reporting interval (like \f[C]--quarterly\f[R] above), the report -start/end dates will be adjusted if necessary so that they encompass the -displayed report periods. -This is so that the first and last periods will be \[dq]full\[dq] and -comparable to the others. -.PP -The \f[C]-E/--empty\f[R] flag does two things in multicolumn balance -reports: first, the report will show all columns within the specified -report period (without -E, leading and trailing columns with all zeroes -are not shown). -Second, all accounts which existed at the report start date will be -considered, not just the ones with activity during the report period -(use -E to include low-activity accounts which would otherwise would be -omitted). -.PP -The \f[C]-T/--row-total\f[R] flag adds an additional column showing the -total for each row. -.PP -The \f[C]-A/--average\f[R] flag adds a column showing the average value -in each row. -.PP -Here\[aq]s an example of all three: -.IP -.nf -\f[C] -$ hledger balance -Q income expenses --tree -ETA -Balance changes in 2008: - - || 2008q1 2008q2 2008q3 2008q4 Total Average -============++=================================================== - expenses || 0 $2 0 0 $2 $1 - food || 0 $1 0 0 $1 0 - supplies || 0 $1 0 0 $1 0 - income || $-1 $-1 0 0 $-2 $-1 - gifts || 0 $-1 0 0 $-1 0 - salary || $-1 0 0 0 $-1 0 -------------++--------------------------------------------------- - || $-1 $1 0 0 0 0 - -(Average is rounded to the dollar here since all journal amounts are) -\f[R] -.fi -.PP -The \f[C]--transpose\f[R] flag can be used to exchange the rows and -columns of a multicolumn report. -.PP -When showing multicommodity amounts, multicolumn balance reports will -elide any amounts which have more than two commodities, since otherwise -columns could get very wide. -The \f[C]--no-elide\f[R] flag disables this. -Hiding totals with the \f[C]-N/--no-total\f[R] flag can also help reduce -the width of multicommodity reports. -.PP -When the report is still too wide, a good workaround is to pipe it into -\f[C]less -RS\f[R] (-R for colour, -S to chop long lines). -Eg: \f[C]hledger bal -D --color=yes | less -RS\f[R]. -.SS Depth limiting -.PP -With a \f[C]depth:N\f[R] query, or \f[C]--depth N\f[R] option, or just -\f[C]-N\f[R], balance reports will show accounts only to the specified -depth. -This is very useful to hide low-level accounts and get an overview. -Eg, limiting to depth 1 shows the top-level accounts: -.IP -.nf -\f[C] -$ hledger balance -N -1 - $-1 assets - $2 expenses - $-2 income - $1 liabilities -\f[R] -.fi -.PP -Accounts at the depth limit will include the balances of any hidden -subaccounts (even in flat mode, which normally shows exclusive -balances). -.PP -You can also drop account name components from the start of account -names, using \f[C]--drop N\f[R]. -This can be useful to hide unwanted top-level detail. -.SS Colour support -.PP -In terminal output, when colour is enabled, the balance command shows -negative amounts in red. +Multi-period reports with many periods can be too wide for easy viewing +in the terminal. +Here are some ways to handle that: +.IP \[bu] 2 +Hide the totals row with \f[C]-N/--no-total\f[R] +.IP \[bu] 2 +Convert to a single currency with \f[C]-V\f[R] +.IP \[bu] 2 +Maximize the terminal window +.IP \[bu] 2 +Reduce the terminal\[aq]s font size +.IP \[bu] 2 +View with a pager like less, eg: +\f[C]hledger bal -D --color=yes | less -RS\f[R] +.IP \[bu] 2 +Output as CSV and use a CSV viewer like visidata +(\f[C]hledger bal -D -O csv | vd -f csv\f[R]), Emacs\[aq] csv-mode +(\f[C]M-x csv-mode, C-c C-a\f[R]), or a spreadsheet +(\f[C]hledger bal -D -o a.csv && open a.csv\f[R]) +.IP \[bu] 2 +Output as HTML and view with a browser: +\f[C]hledger bal -D -o a.html && open a.html\f[R] .SS Sorting by amount .PP -With \f[C]-S\f[R]/\f[C]--sort-amount\f[R], accounts with the largest -(most positive) balances are shown first. -For example, \f[C]hledger bal expenses -MAS\f[R] shows your biggest -averaged monthly expenses first. +With \f[C]-S/--sort-amount\f[R], accounts with the largest (most +positive) balances are shown first. +Eg: \f[C]hledger bal expenses -MAS\f[R] shows your biggest averaged +monthly expenses first. .PP Revenues and liability balances are typically negative, however, so \f[C]-S\f[R] shows these in reverse order. To work around this, you can add \f[C]--invert\f[R] to flip the signs. -Or, use one of the sign-flipping reports like \f[C]balancesheet\f[R] or -\f[C]incomestatement\f[R], which also support \f[C]-S\f[R]. -Eg: \f[C]hledger is -MAS\f[R]. +(Or, use one of the higher-level reports, which flip the sign +automatically. +Eg: \f[C]hledger incomestatement -MAS\f[R]). +.PP .SS Percentages .PP -With \f[C]-%\f[R] or \f[C]--percent\f[R], balance reports show each -account\[aq]s value expressed as a percentage of the column\[aq]s total. -This is useful to get an overview of the relative sizes of account -balances. -For example to obtain an overview of expenses: +With \f[C]-%/--percent\f[R], balance reports show each account\[aq]s +value expressed as a percentage of the (column) total: .IP .nf \f[C] -$ hledger balance expenses -% - 100.0 % expenses - 50.0 % food - 50.0 % supplies --------------------- - 100.0 % +$ hledger bal expenses -Q -% +Balance changes in 2008: + + || 2008Q1 2008Q2 2008Q3 2008Q4 +===================++================================= + expenses:food || 0 50.0 % 0 0 + expenses:supplies || 0 50.0 % 0 0 +-------------------++--------------------------------- + || 0 100.0 % 0 0 \f[R] .fi .PP -Note that \f[C]--tree\f[R] does not have an effect on \f[C]-%\f[R]. -The percentages are always relative to the total sum of each column, -they are never relative to the parent account. -.PP -Since the percentages are relative to the columns sum, it is usually not -useful to calculate percentages if the signs of the amounts are mixed. -Although the results are technically correct, they are most likely -useless. -Especially in a balance report that sums up to zero (eg -\f[C]hledger balance -B\f[R]) all percentage values will be zero. -.PP -This flag does not work if the report contains any mixed commodity -accounts. -If there are mixed commodity accounts in the report be sure to use -\f[C]-V\f[R] or \f[C]-B\f[R] to coerce the report into using a single -commodity. -.PP -.SS Customising single-period balance reports -.PP -You can customise the layout of single-period balance reports with -\f[C]--format FMT\f[R], which sets the format of each line. -Eg: +Note it is not useful to calculate percentages if the amounts in a +column have mixed signs. +In this case, make a separate report for each sign, eg: .IP .nf \f[C] -$ hledger balance --format \[dq]%20(account) %12(total)\[dq] - assets $-1 - bank:saving $1 - cash $-2 - expenses $2 - food $1 - supplies $1 - income $-2 - gifts $-1 - salary $-1 - liabilities:debts $1 ---------------------------------- - 0 +$ hledger bal -% amt:\[ga]>0\[ga] +$ hledger bal -% amt:\[ga]<0\[ga] \f[R] .fi .PP -The FMT format string (plus a newline) specifies the formatting applied -to each account/balance pair. -It may contain any suitable text, with data fields interpolated like so: +Similarly, if the amounts in a column have mixed commodities, convert +them to one commodity with \f[C]-B\f[R], \f[C]-V\f[R], \f[C]-X\f[R] or +\f[C]--value\f[R], or make a separate report for each commodity: +.IP +.nf +\f[C] +$ hledger bal -% cur:\[rs]\[rs]$ +$ hledger bal -% cur:\[Eu] +\f[R] +.fi +.SS Balance change, end balance .PP -\f[C]%[MIN][.MAX](FIELDNAME)\f[R] -.IP \[bu] 2 -MIN pads with spaces to at least this width (optional) -.IP \[bu] 2 -MAX truncates at this width (optional) -.IP \[bu] 2 -FIELDNAME must be enclosed in parentheses, and can be one of: -.RS 2 -.IP \[bu] 2 -\f[C]depth_spacer\f[R] - a number of spaces equal to the account\[aq]s -depth, or if MIN is specified, MIN * depth spaces. -.IP \[bu] 2 -\f[C]account\f[R] - the account\[aq]s name -.IP \[bu] 2 -\f[C]total\f[R] - the account\[aq]s balance/posted total, right -justified -.RE +It\[aq]s important to be clear on the meaning of the numbers shown in +balance reports. +Here is some terminology we use: .PP -Also, FMT can begin with an optional prefix to control how -multi-commodity amounts are rendered: -.IP \[bu] 2 -\f[C]%_\f[R] - render on multiple lines, bottom-aligned (the default) -.IP \[bu] 2 -\f[C]%\[ha]\f[R] - render on multiple lines, top-aligned -.IP \[bu] 2 -\f[C]%,\f[R] - render on one line, comma-separated +A \f[B]\f[BI]balance change\f[B]\f[R] is the net amount added to, or +removed from, an account during some period. .PP -There are some quirks. -Eg in one-line mode, \f[C]%(depth_spacer)\f[R] has no effect, instead -\f[C]%(account)\f[R] has indentation built in. -Experimentation may be needed to get pleasing results. +An \f[B]\f[BI]end balance\f[B]\f[R] is the amount accumulated in an +account as of some date (and some time, but hledger doesn\[aq]t store +that; assume end of day in your timezone). +It is the sum of previous balance changes. .PP -Some example formats: +We call it a \f[B]\f[BI]historical end balance\f[B]\f[R] if it includes +all balance changes since the account was created. +For a real world account, this means it will match the \[dq]historical +record\[dq], eg the balances reported in your bank statements or bank +web UI. +(If they are correct!) +.PP +In general, balance changes are what you want to see when reviewing +revenues and expenses, and historical end balances are what you want to +see when reviewing or reconciling asset, liability and equity accounts. +.PP +\f[C]balance\f[R] shows balance changes by default. +To see accurate historical end balances: +.IP "1." 3 +Initialise account starting balances with an \[dq]opening balances\[dq] +transaction (a transfer from equity to the account), unless the journal +covers the account\[aq]s full lifetime. +.IP "2." 3 +Include all of of the account\[aq]s prior postings in the report, by not +specifying a report start date, or by using the +\f[C]-H/--historical\f[R] flag. +(\f[C]-H\f[R] causes report start date to be ignored when summing +postings.) +.SS Balance report types +.PP +For more flexible reporting, there are three important option groups: +.PP +\f[C]hledger balance [CALCULATIONTYPE] [ACCUMULATIONTYPE] [VALUATIONTYPE] ...\f[R] +.PP +The first two are the most important: calculation type selects the basic +calculation to perform for each table cell, while accumulation type says +which postings should be included in each cell\[aq]s calculation. +Typically one or both of these are selected by default, so you don\[aq]t +need to write them explicitly. +A valuation type can be added if you want to convert the basic report to +value or cost. +.PP +\f[B]Calculation type:\f[R] +.PD 0 +.P +.PD +The basic calculation to perform for each table cell. +It is one of: .IP \[bu] 2 -\f[C]%(total)\f[R] - the account\[aq]s total +\f[C]--sum\f[R] : sum the posting amounts (\f[B]default\f[R]) .IP \[bu] 2 -\f[C]%-20.20(account)\f[R] - the account\[aq]s name, left justified, -padded to 20 characters and clipped at 20 characters +\f[C]--budget\f[R] : like --sum but also show a goal amount .IP \[bu] 2 -\f[C]%,%-50(account) %25(total)\f[R] - account name padded to 50 -characters, total padded to 20 characters, with multiple commodities -rendered on one line +\f[C]--valuechange\f[R] : show the change in period-end historical +balance values +.PP +\f[B]Accumulation type:\f[R] +.PD 0 +.P +.PD +Which postings should be included in each cell\[aq]s calculation. +It is one of: .IP \[bu] 2 -\f[C]%20(total) %2(depth_spacer)%-(account)\f[R] - the default format -for the single-column balance report +\f[C]--change\f[R] : postings from column start to column end, ie within +the cell\[aq]s period. +Typically used to see revenues/expenses. +(\f[B]default for balance, incomestatement\f[R]) +.IP \[bu] 2 +\f[C]--cumulative\f[R] : postings from report start to column end, eg to +show changes accumulated since the report\[aq]s start date. +Rarely used. +.IP \[bu] 2 +\f[C]--historical/-H\f[R] : postings from journal start to column end, +ie all postings from account creation to the end of the cell\[aq]s +period. +Typically used to see historical end balances of +assets/liabilities/equity. +(\f[B]default for balancesheet, balancesheetequity, cashflow\f[R]) +.PP +\f[B]Valuation type:\f[R] +.PD 0 +.P +.PD +Which kind of valuation, valuation date(s) and optionally a target +valuation commodity to use. +It is one of: +.IP \[bu] 2 +no valuation, show amounts in their original commodities +(\f[B]default\f[R]) +.IP \[bu] 2 +\f[C]--value=cost[,COMM]\f[R] : no valuation, show amounts converted to +cost +.IP \[bu] 2 +\f[C]--value=then[,COMM]\f[R] : show value at transaction dates +.IP \[bu] 2 +\f[C]--value=end[,COMM]\f[R] : show value at period end date(s) +(\f[B]default with \f[CB]--valuechange\f[B]\f[R]) +.IP \[bu] 2 +\f[C]--value=now[,COMM]\f[R] : show value at today\[aq]s date +.IP \[bu] 2 +\f[C]--value=YYYY-MM-DD[,COMM]\f[R] : show value at another date +.PP +or one of their aliases: \f[C]--cost/-B\f[R], \f[C]--market/-V\f[R] or +\f[C]--exchange/-X\f[R]. +.PP +Most combinations of these options should produce reasonable reports, +but if you find any that seem wrong or misleading, let us know. +The following restrictions are applied: +.IP \[bu] 2 +\f[C]--valuechange\f[R] implies \f[C]--value=end\f[R] +.IP \[bu] 2 +\f[C]--valuechange\f[R] makes \f[C]--change\f[R] the default when used +with the \f[C]balancesheet\f[R]/\f[C]balancesheetequity\f[R] commands +.IP \[bu] 2 +\f[C]--cumulative\f[R] or \f[C]--historical\f[R] disables +\f[C]--row-total/-T\f[R] +.PP +For reference, here is what the combinations of accumulation and +valuation show: +.PP +.TS +tab(@); +lw(8.2n) lw(16.3n) lw(16.8n) lw(15.1n) lw(13.6n). +T{ +Valuation: >Accumulation: v +T}@T{ +no valuation +T}@T{ +\f[C]--value= then\f[R] +T}@T{ +\f[C]--value= end\f[R] +T}@T{ +\f[C]--value= YYYY-MM-DD /now\f[R] +T} +_ +T{ +\f[C]--change\f[R] +T}@T{ +change in period +T}@T{ +sum of posting-date market values in period +T}@T{ +period-end value of change in period +T}@T{ +DATE-value of change in period +T} +T{ +\f[C]--cumulative\f[R] +T}@T{ +change from report start to period end +T}@T{ +sum of posting-date market values from report start to period end +T}@T{ +period-end value of change from report start to period end +T}@T{ +DATE-value of change from report start to period end +T} +T{ +\f[C]--historical /-H\f[R] +T}@T{ +change from journal start to period end (historical end balance) +T}@T{ +sum of posting-date market values from journal start to period end +T}@T{ +period-end value of change from journal start to period end +T}@T{ +DATE-value of change from journal start to period end +T} +.TE +.SS Useful balance reports +.PP +Some frequently used \f[C]balance\f[R] options/reports are: +.IP \[bu] 2 +\f[C]bal -M revenues expenses\f[R] +.PD 0 +.P +.PD +Show revenues/expenses in each month. +Also available as the \f[C]incomestatement\f[R] command. +.IP \[bu] 2 +\f[C]bal -M -H assets liabilities\f[R] +.PD 0 +.P +.PD +Show historical asset/liability balances at each month end. +Also available as the \f[C]balancesheet\f[R] command. +.IP \[bu] 2 +\f[C]bal -M -H assets liabilities equity\f[R] +.PD 0 +.P +.PD +Show historical asset/liability/equity balances at each month end. +Also available as the \f[C]balancesheetequity\f[R] command. +.IP \[bu] 2 +\f[C]bal -M assets not:receivable\f[R] +.PD 0 +.P +.PD +Show changes to liquid assets in each month. +Also available as the \f[C]cashflow\f[R] command. +.PP +Also: +.IP \[bu] 2 +\f[C]bal -M expenses -2 -SA\f[R] +.PD 0 +.P +.PD +Show monthly expenses summarised to depth 2 and sorted by average +amount. +.IP \[bu] 2 +\f[C]bal -M --budget expenses\f[R] +.PD 0 +.P +.PD +Show monthly expenses and budget goals. +.IP \[bu] 2 +\f[C]bal -M --valuechange investments\f[R] +.PD 0 +.P +.PD +Show monthly change in market value of investment assets. +.IP \[bu] 2 +\f[C]bal investments --valuechange -D date:lastweek amt:\[aq]>1000\[aq] -STA [--invert]\f[R] +.PD 0 +.P +.PD +Show top gainers [or losers] last week .SS Budget report .PP -There is also a special balance report mode for showing budget -performance. -The \f[C]--budget\f[R] flag activates extra columns showing the budget -goals for each account and period, if any. -For this report, budget goals are defined by periodic transactions. +The \f[C]--budget\f[R] report type activates extra columns showing any +budget goals for each account and period. +The budget goals are defined by periodic transactions. This is very useful for comparing planned and actual income, expenses, time usage, etc. .PP @@ -2919,11 +3105,11 @@ amounts are shown, and the actual/goal percentage. (Note: budget goals should be in the same commodity as the actual amount.) .IP \[bu] 2 -All parent accounts are always shown, even in flat mode. +All parent accounts are always shown, even in list mode. Eg assets, assets:bank, and expenses above. .IP \[bu] 2 Amounts always include all subaccounts, budgeted or unbudgeted, even in -flat mode. +list mode. .PP This means that the numbers displayed will not always add up! Eg above, the \f[C]expenses\f[R] actual amount includes the gifts and supplies @@ -3138,6 +3324,80 @@ Budget performance in 2019/01: || 0 [ 0] \f[R] .fi +.SS Customising single-period balance reports +.PP +For single-period balance reports displayed in the terminal (only), you +can use \f[C]--format FMT\f[R] to customise the format and content of +each line. +Eg: +.IP +.nf +\f[C] +$ hledger balance --format \[dq]%20(account) %12(total)\[dq] + assets $-1 + bank:saving $1 + cash $-2 + expenses $2 + food $1 + supplies $1 + income $-2 + gifts $-1 + salary $-1 + liabilities:debts $1 +--------------------------------- + 0 +\f[R] +.fi +.PP +The FMT format string (plus a newline) specifies the formatting applied +to each account/balance pair. +It may contain any suitable text, with data fields interpolated like so: +.PP +\f[C]%[MIN][.MAX](FIELDNAME)\f[R] +.IP \[bu] 2 +MIN pads with spaces to at least this width (optional) +.IP \[bu] 2 +MAX truncates at this width (optional) +.IP \[bu] 2 +FIELDNAME must be enclosed in parentheses, and can be one of: +.RS 2 +.IP \[bu] 2 +\f[C]depth_spacer\f[R] - a number of spaces equal to the account\[aq]s +depth, or if MIN is specified, MIN * depth spaces. +.IP \[bu] 2 +\f[C]account\f[R] - the account\[aq]s name +.IP \[bu] 2 +\f[C]total\f[R] - the account\[aq]s balance/posted total, right +justified +.RE +.PP +Also, FMT can begin with an optional prefix to control how +multi-commodity amounts are rendered: +.IP \[bu] 2 +\f[C]%_\f[R] - render on multiple lines, bottom-aligned (the default) +.IP \[bu] 2 +\f[C]%\[ha]\f[R] - render on multiple lines, top-aligned +.IP \[bu] 2 +\f[C]%,\f[R] - render on one line, comma-separated +.PP +There are some quirks. +Eg in one-line mode, \f[C]%(depth_spacer)\f[R] has no effect, instead +\f[C]%(account)\f[R] has indentation built in. +Experimentation may be needed to get pleasing results. +.PP +Some example formats: +.IP \[bu] 2 +\f[C]%(total)\f[R] - the account\[aq]s total +.IP \[bu] 2 +\f[C]%-20.20(account)\f[R] - the account\[aq]s name, left justified, +padded to 20 characters and clipped at 20 characters +.IP \[bu] 2 +\f[C]%,%-50(account) %25(total)\f[R] - account name padded to 50 +characters, total padded to 20 characters, with multiple commodities +rendered on one line +.IP \[bu] 2 +\f[C]%20(total) %2(depth_spacer)%-(account)\f[R] - the default format +for the single-column balance report .SS balancesheet .PP balancesheet, bs @@ -3155,9 +3415,6 @@ the \f[C]Asset\f[R] or \f[C]Cash\f[R] or \f[C]Liability\f[R] type, or otherwise all accounts under a top-level \f[C]asset\f[R] or \f[C]liability\f[R] account (case insensitive, plurals allowed). .PP -(This report is essentially similar to \[dq]hledger balance --historical -assets liabilities\[dq], with liabilities sign-flipped.) -.PP Example: .IP .nf @@ -3183,16 +3440,12 @@ Total: \f[R] .fi .PP -With a reporting interval, multiple columns will be shown, one for each -report period. -As with multicolumn balance reports, you can alter the report mode with -\f[C]--change\f[R]/\f[C]--cumulative\f[R]/\f[C]--historical\f[R]. -Normally balancesheet shows historical ending balances, which is what -you need for a balance sheet; note this means it ignores report begin -dates (and \f[C]-T/--row-total\f[R], since summing end balances -generally does not make sense). -Instead of absolute values percentages can be displayed with -\f[C]-%\f[R]. +This command is a higher-level variant of the \f[C]balance\f[R] command, +and supports many of that command\[aq]s features, such as multi-period +reports. +It is similar to \f[C]hledger balance -H assets liabilities\f[R], but +with smarter account detection, and liabilities displayed with their +sign flipped. .PP This command also supports the output destination and output format options The output formats supported are \f[C]txt\f[R], \f[C]csv\f[R], @@ -3214,10 +3467,6 @@ or \f[C]Equity\f[R] type, or otherwise all accounts under a top-level \f[C]asset\f[R], \f[C]liability\f[R] or \f[C]equity\f[R] account (case insensitive, plurals allowed). .PP -(This report is essentially similar to \[dq]hledger balance --historical -assets liabilities equity\[dq], with liabilities and equity -sign-flipped.) -.PP Example: .IP .nf @@ -3248,6 +3497,13 @@ Total: \f[R] .fi .PP +This command is a higher-level variant of the \f[C]balance\f[R] command, +and supports many of that command\[aq]s features, such as multi-period +reports. +It is similar to \f[C]hledger balance -H assets liabilities equity\f[R], +but with smarter account detection, and liabilities/equity displayed +with their sign flipped. +.PP This command also supports the output destination and output format options The output formats supported are \f[C]txt\f[R], \f[C]csv\f[R], \f[C]html\f[R], and (experimental) \f[C]json\f[R]. @@ -3268,9 +3524,6 @@ The \[dq]cash\[dq] accounts shown are those accounts declared with the have \f[C]fixed\f[R], \f[C]investment\f[R], \f[C]receivable\f[R] or \f[C]A/R\f[R] in their name. .PP -(This report is essentially similar to \[dq]hledger balance --change -assets not:fixed not:investment not:receivable\[dq].) -.PP Example: .IP .nf @@ -3291,13 +3544,12 @@ Total: \f[R] .fi .PP -With a reporting interval, multiple columns will be shown, one for each -report period. -Normally cashflow shows changes in assets per period, though as with -multicolumn balance reports you can alter the report mode with -\f[C]--change\f[R]/\f[C]--cumulative\f[R]/\f[C]--historical\f[R]. -Instead of absolute values percentages can be displayed with -\f[C]-%\f[R]. +This command is a higher-level variant of the \f[C]balance\f[R] command, +and supports many of that command\[aq]s features, such as multi-period +reports. +It is similar to +\f[C]hledger balance assets not:fixed not:investment not:receivable\f[R], +but with smarter account detection. .PP This command also supports the output destination and output format options The output formats supported are \f[C]txt\f[R], \f[C]csv\f[R], @@ -3362,13 +3614,11 @@ These checks can be run only by giving their names as arguments to They are more specialised and not desirable for everyone, therefore optional: .IP \[bu] 2 -\f[B]ordereddates\f[R] - transactions are ordered by date (similar to -the old \f[C]check-dates\f[R] command) +\f[B]ordereddates\f[R] - transactions are ordered by date in each file .IP \[bu] 2 \f[B]payees\f[R] - all payees used by transactions have been declared .IP \[bu] 2 -\f[B]uniqueleafnames\f[R] - all account leaf names are unique (similar -to the old \f[C]check-dupes\f[R] command). +\f[B]uniqueleafnames\f[R] - all account leaf names are unique .SS Custom checks .PP A few more checks are are available as separate add-on commands, in @@ -3673,21 +3923,80 @@ Or with --dry-run, just print the transactions that would be added. Or with --catchup, just mark all of the FILEs\[aq] transactions as imported, without actually importing any. .PP -The input files are specified as arguments - no need to write -f before -each one. -So eg to add new transactions from all CSV files to the main journal, -it\[aq]s just: \f[C]hledger import *.csv\f[R] +Unlike other hledger commands, with \f[C]import\f[R] the journal file is +an output file, and will be modified, though only by appending (existing +data will not be changed). +The input files are specified as arguments, so to import one or more CSV +files to your main journal, you will run +\f[C]hledger import bank.csv\f[R] or perhaps +\f[C]hledger import *.csv\f[R]. .PP -New transactions are detected in the same way as print --new: by -assuming transactions are always added to the input files in increasing -date order, and by saving \f[C].latest.FILE\f[R] state files. +Note you can import from any file format, though CSV files are the most +common import source, and these docs focus on that case. +.SS Deduplication .PP -The --dry-run output is in journal format, so you can filter it, eg to -see only uncategorised transactions: +As a convenience \f[C]import\f[R] does \f[I]deduplication\f[R] while +reading transactions. +This does not mean \[dq]ignore transactions that look the same\[dq], but +rather \[dq]ignore transactions that have been seen before\[dq]. +This is intended for when you are periodically importing foreign data +which may contain already-imported transactions. +So eg, if every day you download bank CSV files containing redundant +data, you can safely run \f[C]hledger import bank.csv\f[R] and only new +transactions will be imported. +(\f[C]import\f[R] is idempotent.) +.PP +Since the items being read (CSV records, eg) often do not come with +unique identifiers, hledger detects new transactions by date, assuming +that: +.IP "1." 3 +new items always have the newest dates +.IP "2." 3 +item dates do not change across reads +.IP "3." 3 +and items with the same date remain in the same relative order across +reads. +.PP +These are often true of CSV files representing transactions, or true +enough so that it works pretty well in practice. +1 is important, but violations of 2 and 3 amongst the old transactions +won\[aq]t matter (and if you import often, the new transactions will be +few, so less likely to be the ones affected). +.PP +hledger remembers the latest date processed in each input file by saving +a hidden \[dq].latest\[dq] state file in the same directory. +Eg when reading \f[C]finance/bank.csv\f[R], it will look for and update +the \f[C]finance/.latest.bank.csv\f[R] state file. +The format is simple: one or more lines containing the same ISO-format +date (YYYY-MM-DD), meaning \[dq]I have processed transactions up to this +date, and this many of them on that date.\[dq] Normally you won\[aq]t +see or manipulate these state files yourself. +But if needed, you can delete them to reset the state (making all +transactions \[dq]new\[dq]), or you can construct them to \[dq]catch +up\[dq] to a certain date. +.PP +Note deduplication (and updating of state files) can also be done by +\f[C]print --new\f[R], but this is less often used. +.SS Import testing +.PP +With \f[C]--dry-run\f[R], the transactions that will be imported are +printed to the terminal, without updating your journal or state files. +The output is valid journal format, like the print command, so you can +re-parse it. +Eg, to see any importable transactions which CSV rules have not +categorised: .IP .nf \f[C] -$ hledger import --dry ... | hledger -f- print unknown --ignore-assertions +$ hledger import --dry bank.csv | hledger -f- -I print unknown +\f[R] +.fi +.PP +or (live updating): +.IP +.nf +\f[C] +$ ls bank.csv* | entr bash -c \[aq]echo ====; hledger import --dry bank.csv | hledger -f- -I print unknown\[aq] \f[R] .fi .SS Importing balance assignments @@ -3731,9 +4040,6 @@ the \f[C]Revenue\f[R] or \f[C]Expense\f[R] type, or otherwise all accounts under a top-level \f[C]revenue\f[R] or \f[C]income\f[R] or \f[C]expense\f[R] account (case insensitive, plurals allowed). .PP -(This report is essentially similar to \[dq]hledger balance --change -revenues expenses\[dq], with revenues sign-flipped.) -.PP Example: .IP .nf @@ -3761,13 +4067,13 @@ Total: \f[R] .fi .PP -With a reporting interval, multiple columns will be shown, one for each -report period. -Normally incomestatement shows revenues/expenses per period, though as -with multicolumn balance reports you can alter the report mode with -\f[C]--change\f[R]/\f[C]--cumulative\f[R]/\f[C]--historical\f[R]. -Instead of absolute values percentages can be displayed with -\f[C]-%\f[R]. +This command is a higher-level variant of the \f[C]balance\f[R] command, +and supports many of that command\[aq]s features, such as multi-period +reports. +It is similar to +\f[C]hledger balance \[aq](revenues|income)\[aq] expenses\f[R], but with +smarter account detection, and revenues/income displayed with their sign +flipped. .PP This command also supports the output destination and output format options The output formats supported are \f[C]txt\f[R], \f[C]csv\f[R], @@ -3937,27 +4243,10 @@ to STR, and is most recent. STR should contain at least two characters. If there is no similar-enough match, no transaction will be shown. .PP -With \f[C]--new\f[R], for each FILE being read, hledger reads (and -writes) a special state file (\f[C].latest.FILE\f[R] in the same -directory), containing the latest transaction date(s) that were seen -last time FILE was read. -When this file is found, only transactions with newer dates (and new -transactions on the latest date) are printed. -This is useful for ignoring already-seen entries in import data, such as -downloaded CSV files. -Eg: -.IP -.nf -\f[C] -$ hledger -f bank1.csv print --new -(shows transactions added since last print --new on this file) -\f[R] -.fi -.PP -This assumes that transactions added to FILE always have same or -increasing dates, and that transactions on the same day do not get -reordered. -See also the import command. +With \f[C]--new\f[R], hledger prints only transactions it has not seen +on a previous run. +This uses the same deduplication system as the \f[C]import\f[R] command. +(See import\[aq]s docs for details.) .PP This command also supports the output destination and output format options The output formats supported are \f[C]txt\f[R], \f[C]csv\f[R], @@ -4373,18 +4662,16 @@ roi Shows the time-weighted (TWR) and money-weighted (IRR) rate of return on your investments. .PP -This command assumes that you have account(s) that hold nothing but your -investments and whenever you record current appraisal/valuation of these -investments you offset unrealized profit and loss into account(s) that, -again, hold nothing but unrealized profit and loss. -.PP -Any transactions affecting balance of investment account(s) and not -originating from unrealized profit and loss account(s) are assumed to be -your investments or withdrawals. -.PP At a minimum, you need to supply a query (which could be just an account -name) to select your investments with \f[C]--inv\f[R], and another query -to identify your profit and loss transactions with \f[C]--pnl\f[R]. +name) to select your investment(s) with \f[C]--inv\f[R], and another +query to identify your profit and loss transactions with +\f[C]--pnl\f[R]. +.PP +If you do not record changes in the value of your investment manually, +or do not require computation of time-weighted return (TWR), +\f[C]--pnl\f[R] could be an empty query (\f[C]--pnl \[dq]\[dq]\f[R] or +\f[C]--pnl STR\f[R] where \f[C]STR\f[R] does not match any of your +accounts). .PP This command will compute and display the internalized rate of return (IRR) and time-weighted rate of return (TWR) for your investments for @@ -4392,6 +4679,9 @@ the time period requested. Both rates of return are annualized before display, regardless of the length of reporting interval. .PP +Price directives will be taken into account if you supply appropriate +\f[C]--cost\f[R] or \f[C]--value\f[R] flags (see VALUATION). +.PP Note, in some cases this report can fail, for these reasons: .IP \[bu] 2 Error (NotBracketed): No solution for Internal Rate of Return (IRR). @@ -4404,10 +4694,79 @@ Either search does not converge to a solution, or converges too slowly. .PP Examples: .IP \[bu] 2 -Using roi to report unrealised gains: +Using roi to compute total return of investment in stocks: https://github.com/simonmichael/hledger/blob/master/examples/roi-unrealised.ledger +.IP \[bu] 2 +Cookbook -> Return on Investment +.SS Semantics of \f[C]--inv\f[R] and \f[C]--pnl\f[R] .PP -More background: +Query supplied to \f[C]--inv\f[R] has to match all transactions that are +related to your investment. +Transactions not matching \f[C]--inv\f[R] will be ignored. +.PP +In these transactions, ROI will conside postings that match +\f[C]--inv\f[R] to be \[dq]investment postings\[dq] and other postings +(not matching \f[C]--inv\f[R]) will be sorted into two categories: +\[dq]cash flow\[dq] and \[dq]profit and loss\[dq], as ROI needs to know +which part of the investment value is your contributions and which is +due to the return on investment. +.IP \[bu] 2 +\[dq]Cash flow\[dq] is depositing or withdrawing money, buying or +selling assets, or otherwise converting between your investment +commodity and any other commodity. +Example: +.RS 2 +.IP +.nf +\f[C] +2019-01-01 Investing in Snake Oil + assets:cash -$100 + investment:snake oil + +2020-01-01 Selling my Snake Oil + assets:cash $10 + investment:snake oil = 0 +\f[R] +.fi +.RE +.IP \[bu] 2 +\[dq]Profit and loss\[dq] is change in the value of your investment: +.RS 2 +.IP +.nf +\f[C] +2019-06-01 Snake Oil falls in value + investment:snake oil = $57 + equity:unrealized profit or loss +\f[R] +.fi +.RE +.PP +All non-investment postings are assumed to be \[dq]cash flow\[dq], +unless they match \f[C]--pnl\f[R] query. +Changes in value of your investment due to \[dq]profit and loss\[dq] +postings will be considered as part of your investment return. +.PP +Example: if you use \f[C]--inv snake --pnl equity:unrealized\f[R], then +postings in the example below would be classifed as: +.IP +.nf +\f[C] +2019-01-01 Snake Oil #1 + assets:cash -$100 ; cash flow posting + investment:snake oil ; investment posting + +2019-03-01 Snake Oil #2 + equity:unrealized pnl -$100 ; profit and loss posting + snake oil ; investment posting + +2019-07-01 Snake Oil #3 + equity:unrealized pnl ; profit and loss posting + cash -$100 ; cash flow posting + snake oil $50 ; investment posting +\f[R] +.fi +.SS IRR and TWR explained .PP \[dq]ROI\[dq] stands for \[dq]return on investment\[dq]. Traditionally this was computed as a difference between current value of @@ -4429,38 +4788,36 @@ of your initial investment, and if you are adding to your investment, you will receive bigger absolute gains (but probably at the same rate of return). IRR is a way to compute rate of return for each period between in-flow -or out-flow of money, and then combine them in a way that gives you an -annual rate of return that investment is expected to generate. +or out-flow of money, and then combine them in a way that gives you a +compound annual rate of return that investment is expected to generate. .PP As mentioned before, in-flows and out-flows would be any cash that you personally put in or withdraw, and for the \[dq]roi\[dq] command, these -are transactions that involve account(s) matching \f[C]--inv\f[R] -argument and NOT involve account(s) matching \f[C]--pnl\f[R] argument. +are the postings that match the query in the\f[C]--inv\f[R] argument and +NOT match the query in the\f[C]--pnl\f[R] argument. .PP -Presumably, you will also record changes in the value of your -investment, and balance them against \[dq]profit and loss\[dq] (or -\[dq]unrealized gains\[dq]) account. -Note that in order for IRR to compute the precise effect of your -in-flows and out-flows on the rate of return, you will need to record -the value of your investement on or close to the days when in- or -out-flows occur. -.PP -Implementation of IRR in hledger should match the \f[C]XIRR\f[R] formula -in Excel. -.PP -Second way to compute rate of return that \f[C]roi\f[R] command -implements is called \[dq]time-weighted rate of return\[dq] or -\[dq]TWR\[dq]. -Like IRR, it will also break the history of your investment into periods -between in-flows and out-flows to compute rate of return per each period -and then a compound rate of return. -However, internal workings of TWR are quite different. +If you manually record changes in the value of your investment as +transactions that balance them against \[dq]profit and loss\[dq] (or +\[dq]unrealized gains\[dq]) account or use price directives, then in +order for IRR to compute the precise effect of your in-flows and +out-flows on the rate of return, you will need to record the value of +your investement on or close to the days when in- or out-flows occur. .PP In technical terms, IRR uses the same approach as computation of net present value, and tries to find a discount rate that makes net present value of all the cash flows of your investment to add up to zero. This could be hard to wrap your head around, especially if you haven\[aq]t done discounted cash flow analysis before. +Implementation of IRR in hledger should produce results that match the +\f[C]XIRR\f[R] formula in Excel. +.PP +Second way to compute rate of return that \f[C]roi\f[R] command +implements is called \[dq]time-weighted rate of return\[dq] or +\[dq]TWR\[dq]. +Like IRR, it will also break the history of your investment into periods +between in-flows, out-flows and value changes, to compute rate of return +per each period and then a compound rate of return. +However, internal workings of TWR are quite different. .PP TWR represents your investment as an imaginary \[dq]unit fund\[dq] where in-flows/ out-flows lead to buying or selling \[dq]units\[dq] of your @@ -4472,209 +4829,6 @@ of return of your investment. References: * Explanation of rate of return * Explanation of IRR * Explanation of TWR * Examples of computing IRR and TWR and discussion of the limitations of both metrics -.PP -More examples: -.PP -Lets say that we found an investment in Snake Oil that is proising to -give us 10% annually: -.IP -.nf -\f[C] -2019-01-01 Investing in Snake Oil - assets:cash -$100 - investment:snake oil - -2019-12-24 Recording the growth of Snake Oil - investment:snake oil = $110 - equity:unrealized gains -\f[R] -.fi -.PP -For now, basic computation of the rate of return, as well as IRR and -TWR, gives us the expected 10%: -.IP -.nf -\f[C] -$ hledger roi -Y --inv investment --pnl \[dq]unrealized\[dq] -+---++------------+------------++---------------+----------+-------------+-----++--------+--------+ -| || Begin | End || Value (begin) | Cashflow | Value (end) | PnL || IRR | TWR | -+===++============+============++===============+==========+=============+=====++========+========+ -| 1 || 2019-01-01 | 2019-12-31 || 0 | 100 | 110 | 10 || 10.00% | 10.00% | -+---++------------+------------++---------------+----------+-------------+-----++--------+--------+ -\f[R] -.fi -.PP -However, lets say that shorty after investing in the Snake Oil we -started to have second thoughs, so we prompty withdrew $90, leaving only -$10 in. -Before Christmas, though, we started to get the \[dq]fear of mission -out\[dq], so we put the $90 back in. -So for most of the year, our investment was just $10 dollars, and it -gave us just $1 in growth: -.IP -.nf -\f[C] -2019-01-01 Investing in Snake Oil - assets:cash -$100 - investment:snake oil - -2019-01-02 Buyers remorse - assets:cash $90 - investment:snake oil - -2019-12-30 Fear of missing out - assets:cash -$90 - investment:snake oil - -2019-12-31 Recording the growth of Snake Oil - investment:snake oil = $101 - equity:unrealized gains -\f[R] -.fi -.PP -Now IRR and TWR are drastically different: -.IP -.nf -\f[C] -$ hledger roi -Y --inv investment --pnl \[dq]unrealized\[dq] -+---++------------+------------++---------------+----------+-------------+-----++-------+-------+ -| || Begin | End || Value (begin) | Cashflow | Value (end) | PnL || IRR | TWR | -+===++============+============++===============+==========+=============+=====++=======+=======+ -| 1 || 2019-01-01 | 2019-12-31 || 0 | 100 | 101 | 1 || 9.32% | 1.00% | -+---++------------+------------++---------------+----------+-------------+-----++-------+-------+ -\f[R] -.fi -.PP -Here, IRR tells us that we made close to 10% on the $10 dollars that we -had in the account most of the time. -And TWR is ... -just 1%? -Why? -.PP -Based on the transactions in our journal, TWR \[dq]think\[dq] that we -are buying back $90 worst of Snake Oil at the same price that it had at -the beginning of they year, and then after that our $100 investment gets -$1 increase in value, or 1% of $100. -Let\[aq]s take a closer look at what is happening here by asking for -quarterly reports instead of annual: -.IP -.nf -\f[C] -$ hledger roi -Q --inv investment --pnl \[dq]unrealized\[dq] -+---++------------+------------++---------------+----------+-------------+-----++--------+-------+ -| || Begin | End || Value (begin) | Cashflow | Value (end) | PnL || IRR | TWR | -+===++============+============++===============+==========+=============+=====++========+=======+ -| 1 || 2019-01-01 | 2019-03-31 || 0 | 10 | 10 | 0 || 0.00% | 0.00% | -| 2 || 2019-04-01 | 2019-06-30 || 10 | 0 | 10 | 0 || 0.00% | 0.00% | -| 3 || 2019-07-01 | 2019-09-30 || 10 | 0 | 10 | 0 || 0.00% | 0.00% | -| 4 || 2019-10-01 | 2019-12-31 || 10 | 90 | 101 | 1 || 37.80% | 4.03% | -+---++------------+------------++---------------+----------+-------------+-----++--------+-------+ -\f[R] -.fi -.PP -Now both IRR and TWR are thrown off by the fact that all of the growth -for our investment happens in Q4 2019. -This happes because IRR computation is still yielding 9.32% and TWR is -still 1%, but this time these are rates for three month period instead -of twelve, so in order to get an annual rate they should be multiplied -by four! -.PP -Let\[aq]s try to keep a better record of how Snake Oil grew in value: -.IP -.nf -\f[C] -2019-01-01 Investing in Snake Oil - assets:cash -$100 - investment:snake oil - -2019-01-02 Buyers remorse - assets:cash $90 - investment:snake oil - -2019-02-28 Recording the growth of Snake Oil - investment:snake oil - equity:unrealized gains -$0.25 - -2019-06-30 Recording the growth of Snake Oil - investment:snake oil - equity:unrealized gains -$0.25 - -2019-09-30 Recording the growth of Snake Oil - investment:snake oil - equity:unrealized gains -$0.25 - -2019-12-30 Fear of missing out - assets:cash -$90 - investment:snake oil - -2019-12-31 Recording the growth of Snake Oil - investment:snake oil - equity:unrealized gains -$0.25 -\f[R] -.fi -.PP -Would our quartery report look better now? -Almost: -.IP -.nf -\f[C] -$ hledger roi -Q --inv investment --pnl \[dq]unrealized\[dq] -+---++------------+------------++---------------+----------+-------------+------++--------+--------+ -| || Begin | End || Value (begin) | Cashflow | Value (end) | PnL || IRR | TWR | -+===++============+============++===============+==========+=============+======++========+========+ -| 1 || 2019-01-01 | 2019-03-31 || 0 | 10 | 10.25 | 0.25 || 9.53% | 10.53% | -| 2 || 2019-04-01 | 2019-06-30 || 10.25 | 0 | 10.50 | 0.25 || 10.15% | 10.15% | -| 3 || 2019-07-01 | 2019-09-30 || 10.50 | 0 | 10.75 | 0.25 || 9.79% | 9.78% | -| 4 || 2019-10-01 | 2019-12-31 || 10.75 | 90 | 101.00 | 0.25 || 8.05% | 1.00% | -+---++------------+------------++---------------+----------+-------------+------++--------+--------+ -\f[R] -.fi -.PP -Something is still wrong with TWR computation for Q4, and if you have -been paying attention you know what it is already: big $90 buy-back is -recorded prior to the only transaction that captures the change of value -of Snake Oil that happened in this time period. -Lets combine transactions from 30th and 31st of Dec into one: -.IP -.nf -\f[C] -2019-12-30 Fear of missing out and growth of Snake Oil - assets:cash -$90 - investment:snake oil - equity:unrealized gains -$0.25 -\f[R] -.fi -.PP -Now growth of investment properly affects its price at the time of -buy-back: -.IP -.nf -\f[C] -$ hledger roi -Q --inv investment --pnl \[dq]unrealized\[dq] -+---++------------+------------++---------------+----------+-------------+------++--------+--------+ -| || Begin | End || Value (begin) | Cashflow | Value (end) | PnL || IRR | TWR | -+===++============+============++===============+==========+=============+======++========+========+ -| 1 || 2019-01-01 | 2019-03-31 || 0 | 10 | 10.25 | 0.25 || 9.53% | 10.53% | -| 2 || 2019-04-01 | 2019-06-30 || 10.25 | 0 | 10.50 | 0.25 || 10.15% | 10.15% | -| 3 || 2019-07-01 | 2019-09-30 || 10.50 | 0 | 10.75 | 0.25 || 9.79% | 9.78% | -| 4 || 2019-10-01 | 2019-12-31 || 10.75 | 90 | 101.00 | 0.25 || 8.05% | 9.57% | -+---++------------+------------++---------------+----------+-------------+------++--------+--------+ -\f[R] -.fi -.PP -And for annual report, TWR now reports the exact profitability of our -investment: -.IP -.nf -\f[C] -$ hledger roi -Y --inv investment --pnl \[dq]unrealized\[dq] -+---++------------+------------++---------------+----------+-------------+------++-------+--------+ -| || Begin | End || Value (begin) | Cashflow | Value (end) | PnL || IRR | TWR | -+===++============+============++===============+==========+=============+======++=======+========+ -| 1 || 2019-01-01 | 2019-12-31 || 0 | 100 | 101.00 | 1.00 || 9.32% | 10.00% | -+---++------------+------------++---------------+----------+-------------+------++-------+--------+ -\f[R] -.fi .SS stats .PP stats diff --git a/hledger/hledger.info b/hledger/hledger.info index 1c73a1209..b9b53ccbf 100644 --- a/hledger/hledger.info +++ b/hledger/hledger.info @@ -2064,56 +2064,118 @@ File: hledger.info, Node: balance, Next: balancesheet, Prev: aregister, Up: balance, bal Show accounts and their balances. - The balance command is hledger's most versatile command. Note, -despite the name, it is not always used for showing real-world account -balances; the more accounting-aware balancesheet and incomestatement -may be more convenient for that. + `balance' is one of hledger's oldest and most versatile commands, +for listing account balances, balance changes, values, value changes and +more, during one time period or many. Generally it shows a table, with +rows representing accounts, and columns representing periods. - By default, it displays all accounts, and each account's change in -balance during the entire period of the journal. Balance changes are -calculated by adding up the postings in each account. You can limit the -postings matched, by a query, to see fewer accounts, changes over a -different time period, changes from only cleared transactions, etc. - - If you include an account's complete history of postings in the -report, the balance change is equivalent to the account's current ending -balance. For a real-world account, typically you won't have all -transactions in the journal; instead you'll have all transactions after -a certain date, and an "opening balances" transaction setting the -correct starting balance on that date. Then the balance command will -show real-world account balances. In some cases the -H/-historical flag -is used to ensure this (more below). - - This command also supports the output destination and output format -options The output formats supported are (in most modes): `txt', `csv', -`html', and `json'. - - The balance command can produce several styles of report: + Note there are some higher-level variants of the `balance' command +with convenient defaults, which can be simpler to use: `balancesheet', +`balancesheetequity', `cashflow' and `incomestatement'. When you need +more control, then use `balance'. * Menu: -* Single-period flat balance report:: -* Single-period tree-mode balance report:: -* Multi-period balance report:: +* balance features:: +* Simple balance report:: +* Filtered balance report:: +* List or tree mode:: * Depth limiting:: -* Colour support:: +* Multi-period balance report:: * Sorting by amount:: * Percentages:: -* Customising single-period balance reports:: +* Balance change end balance:: +* Balance report types:: +* Useful balance reports:: * Budget report:: +* Customising single-period balance reports::  -File: hledger.info, Node: Single-period flat balance report, Next: Single-period tree-mode balance report, Up: balance +File: hledger.info, Node: balance features, Next: Simple balance report, Up: balance -11.5.1 Single-period flat balance report ----------------------------------------- +11.5.1 balance features +----------------------- -This is the default for hledger's balance command: a flat list of all -(or with a query, matched) accounts, showing full account names. -Accounts are sorted by declaration order if any, and then by account -name. Accounts which have zero balance are not shown unless -`-E/--empty' is used. The reported balances' total is shown as the last -line, unless disabled by `-N'/`--no-total'. +Here's a quick overview of the `balance' command's features, followed +by more detailed descriptions and examples. Many of these work with the +higher-level commands as well. + + `balance' can show.. + + * accounts as a list (`-l') or a tree (`-t') + + * optionally depth-limited (`-[1-9]') + + * sorted by declaration order and name, or by amount + + ..and their.. + + * balance changes (the default) + + * or actual and planned balance changes (`--budget') + + * or value of balance changes (`-V') + + * or change of balance values (`--valuechange') + + ..in.. + + * one time period (the whole journal period by default) + + * or multiple periods (`-D', `-W', `-M', `-Q', `-Y', `-p INTERVAL') + + ..either.. + + * per period (the default) + + * or accumulated since report start date (`--cumulative') + + * or accumulated since account creation (`--historical/-H') + + ..possibly converted to.. + + * cost (`--value=cost[,COMM]'/`--cost'/`-B') + + * or market value, as of transaction dates (`--value=then[,COMM]') + + * or at period ends (`--value=end[,COMM]') + + * or now (`--value=now') + + * or at some other date (`--value=YYYY-MM-DD') + + ..with.. + + * totals (`-T'), averages (`-A'), percentages (`-%'), inverted sign + (`--invert') + + * rows and columns swapped (`--transpose') + + * another field used as account name (`--pivot') + + * custom-formatted line items (single-period reports only) + (`--format') + + This command supports the output destination and output format +options, with output formats `txt', `csv', `json', and (multi-period +reports only:) `html'. In `txt' output in a colour-supporting terminal, +negative amounts are shown in red. + + +File: hledger.info, Node: Simple balance report, Next: Filtered balance report, Prev: balance features, Up: balance + +11.5.2 Simple balance report +---------------------------- + +With no arguments, `balance' shows a list of all accounts and their +change of balance - ie, the sum of posting amounts, both inflows and +outflows - during the entire period of the journal. For real-world +accounts, this should also match their end balance at the end of the +journal period (more on this below). + + Accounts are sorted by declaration order if any, and then +alphabetically by account name. For instance, using +examples/sample.journal: $ hledger bal @@ -2127,15 +2189,53 @@ $ hledger bal -------------------- 0 + Accounts with a zero balance (and no non-zero subaccounts, in tree +mode - see below) are hidden by default. Use `-E/--empty' to show them +(revealing `assets:bank:checking' here): + + +$ hledger -f examples/sample.journal bal -E + 0 assets:bank:checking + $1 assets:bank:saving + $-2 assets:cash + $1 expenses:food + $1 expenses:supplies + $-1 income:gifts + $-1 income:salary + $1 liabilities:debts +-------------------- + 0 + + The total of the amounts displayed is shown as the last line, unless +`-N'/`--no-total' is used. +  -File: hledger.info, Node: Single-period tree-mode balance report, Next: Multi-period balance report, Prev: Single-period flat balance report, Up: balance +File: hledger.info, Node: Filtered balance report, Next: List or tree mode, Prev: Simple balance report, Up: balance -11.5.2 Single-period tree-mode balance report ---------------------------------------------- +11.5.3 Filtered balance report +------------------------------ -With the `-t/--tree' flag, accounts are displayed hierarchically, -showing subaccounts as short names indented below their parent. (This is -the default style in Ledger and in older hledger versions.) +You can show fewer accounts, a different time period, totals from +cleared transactions only, etc. by using query arguments or options to +limit the postings being matched. Eg: + + +$ hledger bal --cleared assets date:200806 + $-2 assets:cash +-------------------- + $-2 + + +File: hledger.info, Node: List or tree mode, Next: Depth limiting, Prev: Filtered balance report, Up: balance + +11.5.4 List or tree mode +------------------------ + +By default, or with `-l/--flat', accounts are shown as a flat list with +their full names visible, as in the examples above. + + With `-t/--tree', the account hierarchy is shown, with subaccounts' +"leaf" names indented below their parent: $ hledger balance @@ -2152,42 +2252,63 @@ $ hledger balance -------------------- 0 - For more compact output, "boring" accounts containing a single -interesting subaccount and no balance of their own (`assets:bank' and -`liabilities' here) are elided into the following line, unless -`--no-elide' is used. And accounts which have zero balance and no -non-zero subaccounts are omitted, unless `-E/--empty' is used. + Notes: - Account balances in tree mode are "inclusive" - they include the -balances of any subaccounts. Eg, the `assets' `$-1' balance here -includes the `$1' from `assets:bank:saving' and the `$-2' from -`assets:cash'. (And it would include balance posted to the `assets' -account itself, if there was any). Note this causes some repetition, -and the final total (`0') is the sum of the top-level balances, not of -all the balances shown. + * "Boring" accounts are combined with their subaccount for more + compact output, unless `--no-elide' is used. Boring accounts have + no balance of their own and just one subaccount (eg `assets:bank' + and `liabilities' above). + + * All balances shown are "inclusive", ie including the balances from + all subaccounts. Note this means some repetition in the output, + which requires explanation when sharing reports with + non-plaintextaccounting-users. A tree mode report's final total is + the sum of the top-level balances shown, not of all the balances + shown. + + * Each group of sibling accounts (ie, under a common parent) is + sorted separately. - Each group of sibling accounts is sorted separately, by declaration -order and then by account name.  -File: hledger.info, Node: Multi-period balance report, Next: Depth limiting, Prev: Single-period tree-mode balance report, Up: balance +File: hledger.info, Node: Depth limiting, Next: Multi-period balance report, Prev: List or tree mode, Up: balance -11.5.3 Multi-period balance report +11.5.5 Depth limiting +--------------------- + +With a `depth:N' query, or `--depth N' option, or just `-N', balance +reports will show accounts only to the specified depth, hiding the +deeper subaccounts. Account balances at the depth limit always include +the balances from any hidden subaccounts (even in list mode). This can +be useful for getting an overview. Eg, limiting to depth 1: + + +$ hledger balance -N -1 + $-1 assets + $2 expenses + $-2 income + $1 liabilities + + You can also hide top-level account name parts, using `--drop N'. +This can be useful for hiding repetitive top-level account names: + + +$ hledger bal expenses --drop 1 + $1 food + $1 supplies +-------------------- + $2 + + +File: hledger.info, Node: Multi-period balance report, Next: Sorting by amount, Prev: Depth limiting, Up: balance + +11.5.6 Multi-period balance report ---------------------------------- -Multi-period balance reports are a very useful hledger feature, -activated if you provide one of the reporting interval flags, such as -`-M'/`--monthly'. They are similar to single-period balance reports, -but they show the report as a table, with columns representing one or -more successive time periods. This is the usually the preferred style -of balance report in hledger (even for a single period). - - Multi-period balance reports come in several types, showing different -information: - - 1. A balance change report: by default, each column shows the sum of - postings in that period, ie the account's change of balance in that - period. This is useful eg for a monthly income statement: +With a report interval (set by the `-D/--daily', `-W/--weekly', +`-M/--monthly', `-Q/--quarterly', `-Y/--yearly', or `-p/--period' +flag), `balance' shows a tabular report, with columns representing +successive time periods (and a title): $ hledger balance --quarterly income expenses -E @@ -2202,265 +2323,295 @@ Balance changes in 2008: -------------------++--------------------------------- || $-1 $1 0 0 - 2. A cumulative end balance report: with `--cumulative', each column - shows the end balance for that period, accumulating the changes - across periods, starting from 0 at the report start date: + Notes: + * The report's start/end dates will be expanded, if necessary, to + fully encompass the displayed subperiods (so that the first and + last subperiods have the same duration as the others). - $ hledger balance --quarterly income expenses -E --cumulative - Ending balances (cumulative) in 2008: + * Leading and trailing periods (columns) containing all zeroes are + not shown, unless `-E/--empty' is used. - || 2008/03/31 2008/06/30 2008/09/30 2008/12/31 - ===================++================================================= - expenses:food || 0 $1 $1 $1 - expenses:supplies || 0 $1 $1 $1 - income:gifts || 0 $-1 $-1 $-1 - income:salary || $-1 $-1 $-1 $-1 - -------------------++------------------------------------------------- - || $-1 0 0 0 + * Accounts (rows) containing all zeroes are not shown, unless + `-E/--empty' is used. - 3. A historical end balance report: with `--historical/-H', each - column shows the actual historical end balance for that period, - accumulating the changes across periods, and including the balance - from any postings before the report start date. This is useful eg - for a multi-period balance sheet, and when you want to see - balances only after a certain date: + * Amounts with many commodities are shown in abbreviated form, unless + `--no-elide' is used. _(experimental)_ + * Average and/or total columns can be added with the `-A/--average' + and `-T/--row-total' flags. - $ hledger balance ^assets ^liabilities --quarterly --historical --begin 2008/4/1 - Ending balances (historical) in 2008/04/01-2008/12/31: + * The `--transpose' flag can be used to exchange rows and columns. - || 2008/06/30 2008/09/30 2008/12/31 - ======================++===================================== - assets:bank:checking || $1 $1 0 - assets:bank:saving || $1 $1 $1 - assets:cash || $-2 $-2 $-2 - liabilities:debts || 0 0 $1 - ----------------------++------------------------------------- - || 0 0 0 + * The `--pivot FIELD' option causes a different transaction field to + be used as "account name". See PIVOTING. + Multi-period reports with many periods can be too wide for easy +viewing in the terminal. Here are some ways to handle that: - Note that `--cumulative' or `--historical/-H' disable -`--row-total/-T', since summing end balances generally does not make -sense. + * Hide the totals row with `-N/--no-total' - With a reporting interval (like `--quarterly' above), the report -start/end dates will be adjusted if necessary so that they encompass the -displayed report periods. This is so that the first and last periods -will be "full" and comparable to the others. + * Convert to a single currency with `-V' - The `-E/--empty' flag does two things in multicolumn balance -reports: first, the report will show all columns within the specified -report period (without -E, leading and trailing columns with all zeroes -are not shown). Second, all accounts which existed at the report start -date will be considered, not just the ones with activity during the -report period (use -E to include low-activity accounts which would -otherwise would be omitted). + * Maximize the terminal window - The `-T/--row-total' flag adds an additional column showing the -total for each row. + * Reduce the terminal's font size - The `-A/--average' flag adds a column showing the average value in -each row. + * View with a pager like less, eg: `hledger bal -D --color=yes | + less -RS' - Here's an example of all three: + * Output as CSV and use a CSV viewer like visidata (`hledger bal -D + -O csv | vd -f csv'), Emacs' csv-mode (`M-x csv-mode, C-c C-a'), + or a spreadsheet (`hledger bal -D -o a.csv && open a.csv') - -$ hledger balance -Q income expenses --tree -ETA -Balance changes in 2008: - - || 2008q1 2008q2 2008q3 2008q4 Total Average -============++=================================================== - expenses || 0 $2 0 0 $2 $1 - food || 0 $1 0 0 $1 0 - supplies || 0 $1 0 0 $1 0 - income || $-1 $-1 0 0 $-2 $-1 - gifts || 0 $-1 0 0 $-1 0 - salary || $-1 0 0 0 $-1 0 -------------++--------------------------------------------------- - || $-1 $1 0 0 0 0 - -(Average is rounded to the dollar here since all journal amounts are) - - The `--transpose' flag can be used to exchange the rows and columns -of a multicolumn report. - - When showing multicommodity amounts, multicolumn balance reports will -elide any amounts which have more than two commodities, since otherwise -columns could get very wide. The `--no-elide' flag disables this. -Hiding totals with the `-N/--no-total' flag can also help reduce the -width of multicommodity reports. - - When the report is still too wide, a good workaround is to pipe it -into `less -RS' (-R for colour, -S to chop long lines). Eg: `hledger -bal -D --color=yes | less -RS'. + * Output as HTML and view with a browser: `hledger bal -D -o a.html + && open a.html'  -File: hledger.info, Node: Depth limiting, Next: Colour support, Prev: Multi-period balance report, Up: balance +File: hledger.info, Node: Sorting by amount, Next: Percentages, Prev: Multi-period balance report, Up: balance -11.5.4 Depth limiting ---------------------- - -With a `depth:N' query, or `--depth N' option, or just `-N', balance -reports will show accounts only to the specified depth. This is very -useful to hide low-level accounts and get an overview. Eg, limiting to -depth 1 shows the top-level accounts: - - -$ hledger balance -N -1 - $-1 assets - $2 expenses - $-2 income - $1 liabilities - - Accounts at the depth limit will include the balances of any hidden -subaccounts (even in flat mode, which normally shows exclusive -balances). - - You can also drop account name components from the start of account -names, using `--drop N'. This can be useful to hide unwanted top-level -detail. - - -File: hledger.info, Node: Colour support, Next: Sorting by amount, Prev: Depth limiting, Up: balance - -11.5.5 Colour support ---------------------- - -In terminal output, when colour is enabled, the balance command shows -negative amounts in red. - - -File: hledger.info, Node: Sorting by amount, Next: Percentages, Prev: Colour support, Up: balance - -11.5.6 Sorting by amount +11.5.7 Sorting by amount ------------------------ -With `-S'/`--sort-amount', accounts with the largest (most positive) -balances are shown first. For example, `hledger bal expenses -MAS' -shows your biggest averaged monthly expenses first. +With `-S/--sort-amount', accounts with the largest (most positive) +balances are shown first. Eg: `hledger bal expenses -MAS' shows your +biggest averaged monthly expenses first. Revenues and liability balances are typically negative, however, so `-S' shows these in reverse order. To work around this, you can add -`--invert' to flip the signs. Or, use one of the sign-flipping reports -like `balancesheet' or `incomestatement', which also support `-S'. Eg: -`hledger is -MAS'. +`--invert' to flip the signs. (Or, use one of the higher-level reports, +which flip the sign automatically. Eg: `hledger incomestatement -MAS').  -File: hledger.info, Node: Percentages, Next: Customising single-period balance reports, Prev: Sorting by amount, Up: balance +File: hledger.info, Node: Percentages, Next: Balance change end balance, Prev: Sorting by amount, Up: balance -11.5.7 Percentages +11.5.8 Percentages ------------------ -With `-%' or `--percent', balance reports show each account's value -expressed as a percentage of the column's total. This is useful to get -an overview of the relative sizes of account balances. For example to -obtain an overview of expenses: +With `-%/--percent', balance reports show each account's value +expressed as a percentage of the (column) total: -$ hledger balance expenses -% - 100.0 % expenses - 50.0 % food - 50.0 % supplies --------------------- - 100.0 % +$ hledger bal expenses -Q -% +Balance changes in 2008: - Note that `--tree' does not have an effect on `-%'. The percentages -are always relative to the total sum of each column, they are never -relative to the parent account. + || 2008Q1 2008Q2 2008Q3 2008Q4 +===================++================================= + expenses:food || 0 50.0 % 0 0 + expenses:supplies || 0 50.0 % 0 0 +-------------------++--------------------------------- + || 0 100.0 % 0 0 - Since the percentages are relative to the columns sum, it is usually -not useful to calculate percentages if the signs of the amounts are -mixed. Although the results are technically correct, they are most -likely useless. Especially in a balance report that sums up to zero (eg -`hledger balance -B') all percentage values will be zero. + Note it is not useful to calculate percentages if the amounts in a +column have mixed signs. In this case, make a separate report for each +sign, eg: - This flag does not work if the report contains any mixed commodity -accounts. If there are mixed commodity accounts in the report be sure to -use `-V' or `-B' to coerce the report into using a single commodity. + +$ hledger bal -% amt:`>0` +$ hledger bal -% amt:`<0` + + Similarly, if the amounts in a column have mixed commodities, convert +them to one commodity with `-B', `-V', `-X' or `--value', or make a +separate report for each commodity: + + +$ hledger bal -% cur:\\$ +$ hledger bal -% cur:€  -File: hledger.info, Node: Customising single-period balance reports, Next: Budget report, Prev: Percentages, Up: balance +File: hledger.info, Node: Balance change end balance, Next: Balance report types, Prev: Percentages, Up: balance -11.5.8 Customising single-period balance reports ------------------------------------------------- +11.5.9 Balance change, end balance +---------------------------------- -You can customise the layout of single-period balance reports with -`--format FMT', which sets the format of each line. Eg: +It's important to be clear on the meaning of the numbers shown in +balance reports. Here is some terminology we use: + A *_balance change_* is the net amount added to, or removed from, an +account during some period. -$ hledger balance --format "%20(account) %12(total)" - assets $-1 - bank:saving $1 - cash $-2 - expenses $2 - food $1 - supplies $1 - income $-2 - gifts $-1 - salary $-1 - liabilities:debts $1 ---------------------------------- - 0 + An *_end balance_* is the amount accumulated in an account as of +some date (and some time, but hledger doesn't store that; assume end of +day in your timezone). It is the sum of previous balance changes. - The FMT format string (plus a newline) specifies the formatting -applied to each account/balance pair. It may contain any suitable text, -with data fields interpolated like so: + We call it a *_historical end balance_* if it includes all balance +changes since the account was created. For a real world account, this +means it will match the "historical record", eg the balances reported +in your bank statements or bank web UI. (If they are correct!) - `%[MIN][.MAX](FIELDNAME)' + In general, balance changes are what you want to see when reviewing +revenues and expenses, and historical end balances are what you want to +see when reviewing or reconciling asset, liability and equity accounts. - * MIN pads with spaces to at least this width (optional) + `balance' shows balance changes by default. To see accurate +historical end balances: - * MAX truncates at this width (optional) + 1. Initialise account starting balances with an "opening balances" + transaction (a transfer from equity to the account), unless the + journal covers the account's full lifetime. - * FIELDNAME must be enclosed in parentheses, and can be one of: + 2. Include all of of the account's prior postings in the report, by + not specifying a report start date, or by using the + `-H/--historical' flag. (`-H' causes report start date to be + ignored when summing postings.) - * `depth_spacer' - a number of spaces equal to the account's - depth, or if MIN is specified, MIN * depth spaces. - - * `account' - the account's name - - * `total' - the account's balance/posted total, right justified - - - Also, FMT can begin with an optional prefix to control how -multi-commodity amounts are rendered: - - * `%_' - render on multiple lines, bottom-aligned (the default) - - * `%^' - render on multiple lines, top-aligned - - * `%,' - render on one line, comma-separated - - There are some quirks. Eg in one-line mode, `%(depth_spacer)' has no -effect, instead `%(account)' has indentation built in. Experimentation -may be needed to get pleasing results. - - Some example formats: - - * `%(total)' - the account's total - - * `%-20.20(account)' - the account's name, left justified, padded to - 20 characters and clipped at 20 characters - - * `%,%-50(account) %25(total)' - account name padded to 50 - characters, total padded to 20 characters, with multiple - commodities rendered on one line - - * `%20(total) %2(depth_spacer)%-(account)' - the default format for - the single-column balance report  -File: hledger.info, Node: Budget report, Prev: Customising single-period balance reports, Up: balance +File: hledger.info, Node: Balance report types, Next: Useful balance reports, Prev: Balance change end balance, Up: balance -11.5.9 Budget report --------------------- +11.5.10 Balance report types +---------------------------- -There is also a special balance report mode for showing budget -performance. The `--budget' flag activates extra columns showing the -budget goals for each account and period, if any. For this report, -budget goals are defined by periodic transactions. This is very useful -for comparing planned and actual income, expenses, time usage, etc. +For more flexible reporting, there are three important option groups: + + `hledger balance [CALCULATIONTYPE] [ACCUMULATIONTYPE] +[VALUATIONTYPE] ...' + + The first two are the most important: calculation type selects the +basic calculation to perform for each table cell, while accumulation +type says which postings should be included in each cell's calculation. +Typically one or both of these are selected by default, so you don't +need to write them explicitly. A valuation type can be added if you +want to convert the basic report to value or cost. + + *Calculation type:* +The basic calculation to perform for each table cell. It is one of: + + * `--sum' : sum the posting amounts (*default*) + + * `--budget' : like -sum but also show a goal amount + + * `--valuechange' : show the change in period-end historical balance + values + + *Accumulation type:* +Which postings should be included in each cell's calculation. It is one +of: + + * `--change' : postings from column start to column end, ie within + the cell's period. Typically used to see revenues/expenses. + (*default for balance, incomestatement*) + + * `--cumulative' : postings from report start to column end, eg to + show changes accumulated since the report's start date. Rarely + used. + + * `--historical/-H' : postings from journal start to column end, ie + all postings from account creation to the end of the cell's period. + Typically used to see historical end balances of + assets/liabilities/equity. (*default for balancesheet, + balancesheetequity, cashflow*) + + + *Valuation type:* +Which kind of valuation, valuation date(s) and optionally a target +valuation commodity to use. It is one of: + + * no valuation, show amounts in their original commodities + (*default*) + + * `--value=cost[,COMM]' : no valuation, show amounts converted to + cost + + * `--value=then[,COMM]' : show value at transaction dates + + * `--value=end[,COMM]' : show value at period end date(s) (*default + with `--valuechange'*) + + * `--value=now[,COMM]' : show value at today's date + + * `--value=YYYY-MM-DD[,COMM]' : show value at another date + + or one of their aliases: `--cost/-B', `--market/-V' or +`--exchange/-X'. + + Most combinations of these options should produce reasonable reports, +but if you find any that seem wrong or misleading, let us know. The +following restrictions are applied: + + * `--valuechange' implies `--value=end' + + * `--valuechange' makes `--change' the default when used with the + `balancesheet'/`balancesheetequity' commands + + * `--cumulative' or `--historical' disables `--row-total/-T' + + For reference, here is what the combinations of accumulation and +valuation show: + +Valuation:no valuation `--value= then' `--value= end' `--value= +>Accumulation: YYYY-MM-DD +v /now' +------------------------------------------------------------------------------ +`--change'change in period sum of period-end DATE-value of + posting-date value of change change in + market values in in period period + period +`--cumulative'change from sum of period-end DATE-value of + report start to posting-date value of change change from + period end market values from report report start + from report start to period to period end + start to period end + end +`--historicalchange from sum of period-end DATE-value of +/-H' journal start to posting-date value of change change from + period end market values from journal journal start + (historical end from journal start to period to period end + balance) start to period end + end + + +File: hledger.info, Node: Useful balance reports, Next: Budget report, Prev: Balance report types, Up: balance + +11.5.11 Useful balance reports +------------------------------ + +Some frequently used `balance' options/reports are: + + * `bal -M revenues expenses' + Show revenues/expenses in each month. Also available as the + `incomestatement' command. + + * `bal -M -H assets liabilities' + Show historical asset/liability balances at each month end. Also + available as the `balancesheet' command. + + * `bal -M -H assets liabilities equity' + Show historical asset/liability/equity balances at each month end. + Also available as the `balancesheetequity' command. + + * `bal -M assets not:receivable' + Show changes to liquid assets in each month. Also available as the + `cashflow' command. + + + Also: + + * `bal -M expenses -2 -SA' + Show monthly expenses summarised to depth 2 and sorted by average + amount. + + * `bal -M --budget expenses' + Show monthly expenses and budget goals. + + * `bal -M --valuechange investments' + Show monthly change in market value of investment assets. + + * `bal investments --valuechange -D date:lastweek amt:'>1000' -STA + [--invert]' + Show top gainers [or losers] last week + + + +File: hledger.info, Node: Budget report, Next: Customising single-period balance reports, Prev: Useful balance reports, Up: balance + +11.5.12 Budget report +--------------------- + +The `--budget' report type activates extra columns showing any budget +goals for each account and period. The budget goals are defined by +periodic transactions. This is very useful for comparing planned and +actual income, expenses, time usage, etc. For example, you can take average monthly expenses in the common expense categories to construct a minimal monthly budget: @@ -2518,11 +2669,11 @@ Budget performance in 2017/11/01-2017/12/31: goal amounts are shown, and the actual/goal percentage. (Note: budget goals should be in the same commodity as the actual amount.) - * All parent accounts are always shown, even in flat mode. Eg assets, + * All parent accounts are always shown, even in list mode. Eg assets, assets:bank, and expenses above. * Amounts always include all subaccounts, budgeted or unbudgeted, - even in flat mode. + even in list mode. This means that the numbers displayed will not always add up! Eg @@ -2582,8 +2733,8 @@ Budget performance in 2017/11/01-2017/12/31:  File: hledger.info, Node: Budget report start date, Next: Nested budgets, Up: Budget report -11.5.9.1 Budget report start date -................................. +11.5.12.1 Budget report start date +.................................. This might be a bug, but for now: when making budget reports, it's a good idea to explicitly set the report's start date to the first day of @@ -2629,8 +2780,8 @@ Budget performance in 2020-01-01..2020-01-15:  File: hledger.info, Node: Nested budgets, Prev: Budget report start date, Up: Budget report -11.5.9.2 Nested budgets -....................... +11.5.12.2 Nested budgets +........................ You can add budgets to any account in your account hierarchy. If you have budgets on both parent account and some of its children, then @@ -2718,6 +2869,78 @@ Budget performance in 2019/01: ----------------------------------------++------------------------------- || 0 [ 0] + +File: hledger.info, Node: Customising single-period balance reports, Prev: Budget report, Up: balance + +11.5.13 Customising single-period balance reports +------------------------------------------------- + +For single-period balance reports displayed in the terminal (only), you +can use `--format FMT' to customise the format and content of each +line. Eg: + + +$ hledger balance --format "%20(account) %12(total)" + assets $-1 + bank:saving $1 + cash $-2 + expenses $2 + food $1 + supplies $1 + income $-2 + gifts $-1 + salary $-1 + liabilities:debts $1 +--------------------------------- + 0 + + The FMT format string (plus a newline) specifies the formatting +applied to each account/balance pair. It may contain any suitable text, +with data fields interpolated like so: + + `%[MIN][.MAX](FIELDNAME)' + + * MIN pads with spaces to at least this width (optional) + + * MAX truncates at this width (optional) + + * FIELDNAME must be enclosed in parentheses, and can be one of: + + * `depth_spacer' - a number of spaces equal to the account's + depth, or if MIN is specified, MIN * depth spaces. + + * `account' - the account's name + + * `total' - the account's balance/posted total, right justified + + + Also, FMT can begin with an optional prefix to control how +multi-commodity amounts are rendered: + + * `%_' - render on multiple lines, bottom-aligned (the default) + + * `%^' - render on multiple lines, top-aligned + + * `%,' - render on one line, comma-separated + + There are some quirks. Eg in one-line mode, `%(depth_spacer)' has no +effect, instead `%(account)' has indentation built in. Experimentation +may be needed to get pleasing results. + + Some example formats: + + * `%(total)' - the account's total + + * `%-20.20(account)' - the account's name, left justified, padded to + 20 characters and clipped at 20 characters + + * `%,%-50(account) %25(total)' - account name padded to 50 + characters, total padded to 20 characters, with multiple + commodities rendered on one line + + * `%20(total) %2(depth_spacer)%-(account)' - the default format for + the single-column balance report +  File: hledger.info, Node: balancesheet, Next: balancesheetequity, Prev: balance, Up: COMMANDS @@ -2735,9 +2958,6 @@ with the `Asset' or `Cash' or `Liability' type, or otherwise all accounts under a top-level `asset' or `liability' account (case insensitive, plurals allowed). - (This report is essentially similar to "hledger balance -historical -assets liabilities", with liabilities sign-flipped.) - Example: @@ -2760,14 +2980,11 @@ Total: -------------------- 0 - With a reporting interval, multiple columns will be shown, one for -each report period. As with multicolumn balance reports, you can alter -the report mode with `--change'/`--cumulative'/`--historical'. Normally -balancesheet shows historical ending balances, which is what you need -for a balance sheet; note this means it ignores report begin dates (and -`-T/--row-total', since summing end balances generally does not make -sense). Instead of absolute values percentages can be displayed with -`-%'. + This command is a higher-level variant of the `balance' command, and +supports many of that command's features, such as multi-period reports. +It is similar to `hledger balance -H assets liabilities', but with +smarter account detection, and liabilities displayed with their sign +flipped. This command also supports the output destination and output format options The output formats supported are `txt', `csv', `html', and @@ -2789,9 +3006,6 @@ declared with the `Asset', `Cash', `Liability' or `Equity' type, or otherwise all accounts under a top-level `asset', `liability' or `equity' account (case insensitive, plurals allowed). - (This report is essentially similar to "hledger balance -historical -assets liabilities equity", with liabilities and equity sign-flipped.) - Example: @@ -2819,6 +3033,12 @@ Total: -------------------- 0 + This command is a higher-level variant of the `balance' command, and +supports many of that command's features, such as multi-period reports. +It is similar to `hledger balance -H assets liabilities equity', but +with smarter account detection, and liabilities/equity displayed with +their sign flipped. + This command also supports the output destination and output format options The output formats supported are `txt', `csv', `html', and (experimental) `json'. @@ -2839,9 +3059,6 @@ normal positive sign, as in conventional financial statements. account (case insensitive, plural allowed) which do not have `fixed', `investment', `receivable' or `A/R' in their name. - (This report is essentially similar to "hledger balance -change -assets not:fixed not:investment not:receivable".) - Example: @@ -2859,11 +3076,10 @@ Total: -------------------- $-1 - With a reporting interval, multiple columns will be shown, one for -each report period. Normally cashflow shows changes in assets per -period, though as with multicolumn balance reports you can alter the -report mode with `--change'/`--cumulative'/`--historical'. Instead of -absolute values percentages can be displayed with `-%'. + This command is a higher-level variant of the `balance' command, and +supports many of that command's features, such as multi-period reports. +It is similar to `hledger balance assets not:fixed not:investment +not:receivable', but with smarter account detection. This command also supports the output destination and output format options The output formats supported are `txt', `csv', `html', and @@ -2946,13 +3162,11 @@ These checks can be run only by giving their names as arguments to `check'. They are more specialised and not desirable for everyone, therefore optional: - * *ordereddates* - transactions are ordered by date (similar to the - old `check-dates' command) + * *ordereddates* - transactions are ordered by date in each file * *payees* - all payees used by transactions have been declared - * *uniqueleafnames* - all account leaf names are unique (similar to - the old `check-dupes' command). + * *uniqueleafnames* - all account leaf names are unique  @@ -3248,29 +3462,92 @@ the main journal file. Or with -dry-run, just print the transactions that would be added. Or with -catchup, just mark all of the FILEs' transactions as imported, without actually importing any. - The input files are specified as arguments - no need to write -f -before each one. So eg to add new transactions from all CSV files to -the main journal, it's just: `hledger import *.csv' + Unlike other hledger commands, with `import' the journal file is an +output file, and will be modified, though only by appending (existing +data will not be changed). The input files are specified as arguments, +so to import one or more CSV files to your main journal, you will run +`hledger import bank.csv' or perhaps `hledger import *.csv'. - New transactions are detected in the same way as print -new: by -assuming transactions are always added to the input files in increasing -date order, and by saving `.latest.FILE' state files. - - The -dry-run output is in journal format, so you can filter it, eg to -see only uncategorised transactions: - - -$ hledger import --dry ... | hledger -f- print unknown --ignore-assertions + Note you can import from any file format, though CSV files are the +most common import source, and these docs focus on that case. * Menu: +* Deduplication:: +* Import testing:: * Importing balance assignments:: * Commodity display styles::  -File: hledger.info, Node: Importing balance assignments, Next: Commodity display styles, Up: import +File: hledger.info, Node: Deduplication, Next: Import testing, Up: import -11.17.1 Importing balance assignments +11.17.1 Deduplication +--------------------- + +As a convenience `import' does _deduplication_ while reading +transactions. This does not mean "ignore transactions that look the +same", but rather "ignore transactions that have been seen before". This +is intended for when you are periodically importing foreign data which +may contain already-imported transactions. So eg, if every day you +download bank CSV files containing redundant data, you can safely run +`hledger import bank.csv' and only new transactions will be imported. +(`import' is idempotent.) + + Since the items being read (CSV records, eg) often do not come with +unique identifiers, hledger detects new transactions by date, assuming +that: + + 1. new items always have the newest dates + + 2. item dates do not change across reads + + 3. and items with the same date remain in the same relative order + across reads. + + These are often true of CSV files representing transactions, or true +enough so that it works pretty well in practice. 1 is important, but +violations of 2 and 3 amongst the old transactions won't matter (and if +you import often, the new transactions will be few, so less likely to be +the ones affected). + + hledger remembers the latest date processed in each input file by +saving a hidden ".latest" state file in the same directory. Eg when +reading `finance/bank.csv', it will look for and update the +`finance/.latest.bank.csv' state file. The format is simple: one or +more lines containing the same ISO-format date (YYYY-MM-DD), meaning "I +have processed transactions up to this date, and this many of them on +that date." Normally you won't see or manipulate these state files +yourself. But if needed, you can delete them to reset the state (making +all transactions "new"), or you can construct them to "catch up" to a +certain date. + + Note deduplication (and updating of state files) can also be done by +`print --new', but this is less often used. + + +File: hledger.info, Node: Import testing, Next: Importing balance assignments, Prev: Deduplication, Up: import + +11.17.2 Import testing +---------------------- + +With `--dry-run', the transactions that will be imported are printed to +the terminal, without updating your journal or state files. The output +is valid journal format, like the print command, so you can re-parse +it. Eg, to see any importable transactions which CSV rules have not +categorised: + + +$ hledger import --dry bank.csv | hledger -f- -I print unknown + + or (live updating): + + +$ ls bank.csv* | entr bash -c 'echo ====; hledger import --dry bank.csv | hledger -f- -I print unknown' + + +File: hledger.info, Node: Importing balance assignments, Next: Commodity display styles, Prev: Import testing, Up: import + +11.17.3 Importing balance assignments ------------------------------------- Entries added by import will have their posting amounts made explicit @@ -3290,7 +3567,7 @@ please test it and send a pull request.)  File: hledger.info, Node: Commodity display styles, Prev: Importing balance assignments, Up: import -11.17.2 Commodity display styles +11.17.4 Commodity display styles -------------------------------- Imported amounts will be formatted according to the canonical commodity @@ -3312,9 +3589,6 @@ with the `Revenue' or `Expense' type, or otherwise all accounts under a top-level `revenue' or `income' or `expense' account (case insensitive, plurals allowed). - (This report is essentially similar to "hledger balance -change -revenues expenses", with revenues sign-flipped.) - Example: @@ -3339,11 +3613,11 @@ Total: -------------------- 0 - With a reporting interval, multiple columns will be shown, one for -each report period. Normally incomestatement shows revenues/expenses per -period, though as with multicolumn balance reports you can alter the -report mode with `--change'/`--cumulative'/`--historical'. Instead of -absolute values percentages can be displayed with `-%'. + This command is a higher-level variant of the `balance' command, and +supports many of that command's features, such as multi-period reports. +It is similar to `hledger balance '(revenues|income)' expenses', but +with smarter account detection, and revenues/income displayed with +their sign flipped. This command also supports the output destination and output format options The output formats supported are `txt', `csv', `html', and @@ -3499,21 +3773,9 @@ transaction: the one one whose description is most similar to STR, and is most recent. STR should contain at least two characters. If there is no similar-enough match, no transaction will be shown. - With `--new', for each FILE being read, hledger reads (and writes) a -special state file (`.latest.FILE' in the same directory), containing -the latest transaction date(s) that were seen last time FILE was read. -When this file is found, only transactions with newer dates (and new -transactions on the latest date) are printed. This is useful for -ignoring already-seen entries in import data, such as downloaded CSV -files. Eg: - - -$ hledger -f bank1.csv print --new -(shows transactions added since last print --new on this file) - - This assumes that transactions added to FILE always have same or -increasing dates, and that transactions on the same day do not get -reordered. See also the import command. + With `--new', hledger prints only transactions it has not seen on a +previous run. This uses the same deduplication system as the `import' +command. (See import's docs for details.) This command also supports the output destination and output format options The output formats supported are `txt', `csv', and @@ -3897,24 +4159,23 @@ roi Shows the time-weighted (TWR) and money-weighted (IRR) rate of return on your investments. - This command assumes that you have account(s) that hold nothing but -your investments and whenever you record current appraisal/valuation of -these investments you offset unrealized profit and loss into account(s) -that, again, hold nothing but unrealized profit and loss. - - Any transactions affecting balance of investment account(s) and not -originating from unrealized profit and loss account(s) are assumed to be -your investments or withdrawals. - At a minimum, you need to supply a query (which could be just an -account name) to select your investments with `--inv', and another +account name) to select your investment(s) with `--inv', and another query to identify your profit and loss transactions with `--pnl'. + If you do not record changes in the value of your investment +manually, or do not require computation of time-weighted return (TWR), +`--pnl' could be an empty query (`--pnl ""' or `--pnl STR' where `STR' +does not match any of your accounts). + This command will compute and display the internalized rate of return (IRR) and time-weighted rate of return (TWR) for your investments for the time period requested. Both rates of return are annualized before display, regardless of the length of reporting interval. + Price directives will be taken into account if you supply appropriate +`--cost' or `--value' flags (see VALUATION). + Note, in some cases this report can fail, for these reasons: * Error (NotBracketed): No solution for Internal Rate of Return @@ -3927,14 +4188,85 @@ display, regardless of the length of reporting interval. Examples: - * Using roi to report unrealised gains: + * Using roi to compute total return of investment in stocks: https://github.com/simonmichael/hledger/blob/master/examples/roi-unrealised.ledger - More background: + * Cookbook -> Return on Investment - "ROI" stands for "return on investment". Traditionally this was -computed as a difference between current value of investment and its -initial value, expressed in percentage of the initial value. + +* Menu: + +* Semantics of --inv and --pnl:: +* IRR and TWR explained:: + + +File: hledger.info, Node: Semantics of --inv and --pnl, Next: IRR and TWR explained, Up: roi + +11.27.1 Semantics of `--inv' and `--pnl' +---------------------------------------- + +Query supplied to `--inv' has to match all transactions that are +related to your investment. Transactions not matching `--inv' will be +ignored. + + In these transactions, ROI will conside postings that match `--inv' +to be "investment postings" and other postings (not matching `--inv') +will be sorted into two categories: "cash flow" and "profit and loss", +as ROI needs to know which part of the investment value is your +contributions and which is due to the return on investment. + + * "Cash flow" is depositing or withdrawing money, buying or selling + assets, or otherwise converting between your investment commodity + and any other commodity. Example: + + + 2019-01-01 Investing in Snake Oil + assets:cash -$100 + investment:snake oil + + 2020-01-01 Selling my Snake Oil + assets:cash $10 + investment:snake oil = 0 + + * "Profit and loss" is change in the value of your investment: + + + 2019-06-01 Snake Oil falls in value + investment:snake oil = $57 + equity:unrealized profit or loss + + + All non-investment postings are assumed to be "cash flow", unless +they match `--pnl' query. Changes in value of your investment due to +"profit and loss" postings will be considered as part of your investment +return. + + Example: if you use `--inv snake --pnl equity:unrealized', then +postings in the example below would be classifed as: + + +2019-01-01 Snake Oil #1 + assets:cash -$100 ; cash flow posting + investment:snake oil ; investment posting + +2019-03-01 Snake Oil #2 + equity:unrealized pnl -$100 ; profit and loss posting + snake oil ; investment posting + +2019-07-01 Snake Oil #3 + equity:unrealized pnl ; profit and loss posting + cash -$100 ; cash flow posting + snake oil $50 ; investment posting + + +File: hledger.info, Node: IRR and TWR explained, Prev: Semantics of --inv and --pnl, Up: roi + +11.27.2 IRR and TWR explained +----------------------------- + +"ROI" stands for "return on investment". Traditionally this was computed +as a difference between current value of investment and its initial +value, expressed in percentage of the initial value. However, this approach is only practical in simple cases, where investments receives no in-flows or out-flows of money, and where rate @@ -3950,36 +4282,34 @@ percentage of your initial investment, and if you are adding to your investment, you will receive bigger absolute gains (but probably at the same rate of return). IRR is a way to compute rate of return for each period between in-flow or out-flow of money, and then combine them in a -way that gives you an annual rate of return that investment is expected -to generate. +way that gives you a compound annual rate of return that investment is +expected to generate. As mentioned before, in-flows and out-flows would be any cash that you personally put in or withdraw, and for the "roi" command, these are -transactions that involve account(s) matching `--inv' argument and NOT -involve account(s) matching `--pnl' argument. +the postings that match the query in the`--inv' argument and NOT match +the query in the`--pnl' argument. - Presumably, you will also record changes in the value of your -investment, and balance them against "profit and loss" (or "unrealized -gains") account. Note that in order for IRR to compute the precise -effect of your in-flows and out-flows on the rate of return, you will -need to record the value of your investement on or close to the days -when in- or out-flows occur. - - Implementation of IRR in hledger should match the `XIRR' formula in -Excel. - - Second way to compute rate of return that `roi' command implements -is called "time-weighted rate of return" or "TWR". Like IRR, it will -also break the history of your investment into periods between in-flows -and out-flows to compute rate of return per each period and then a -compound rate of return. However, internal workings of TWR are quite -different. + If you manually record changes in the value of your investment as +transactions that balance them against "profit and loss" (or "unrealized +gains") account or use price directives, then in order for IRR to +compute the precise effect of your in-flows and out-flows on the rate of +return, you will need to record the value of your investement on or +close to the days when in- or out-flows occur. In technical terms, IRR uses the same approach as computation of net present value, and tries to find a discount rate that makes net present value of all the cash flows of your investment to add up to zero. This could be hard to wrap your head around, especially if you haven't done -discounted cash flow analysis before. +discounted cash flow analysis before. Implementation of IRR in hledger +should produce results that match the `XIRR' formula in Excel. + + Second way to compute rate of return that `roi' command implements +is called "time-weighted rate of return" or "TWR". Like IRR, it will +also break the history of your investment into periods between in-flows, +out-flows and value changes, to compute rate of return per each period +and then a compound rate of return. However, internal workings of TWR +are quite different. TWR represents your investment as an imaginary "unit fund" where in-flows/ out-flows lead to buying or selling "units" of your investment @@ -3991,171 +4321,6 @@ your investment. Explanation of TWR * Examples of computing IRR and TWR and discussion of the limitations of both metrics - More examples: - - Lets say that we found an investment in Snake Oil that is proising to -give us 10% annually: - - -2019-01-01 Investing in Snake Oil - assets:cash -$100 - investment:snake oil - -2019-12-24 Recording the growth of Snake Oil - investment:snake oil = $110 - equity:unrealized gains - - For now, basic computation of the rate of return, as well as IRR and -TWR, gives us the expected 10%: - - -$ hledger roi -Y --inv investment --pnl "unrealized" -+---++------------+------------++---------------+----------+-------------+-----++--------+--------+ -| || Begin | End || Value (begin) | Cashflow | Value (end) | PnL || IRR | TWR | -+===++============+============++===============+==========+=============+=====++========+========+ -| 1 || 2019-01-01 | 2019-12-31 || 0 | 100 | 110 | 10 || 10.00% | 10.00% | -+---++------------+------------++---------------+----------+-------------+-----++--------+--------+ - - However, lets say that shorty after investing in the Snake Oil we -started to have second thoughs, so we prompty withdrew $90, leaving only -$10 in. Before Christmas, though, we started to get the "fear of mission -out", so we put the $90 back in. So for most of the year, our investment -was just $10 dollars, and it gave us just $1 in growth: - - -2019-01-01 Investing in Snake Oil - assets:cash -$100 - investment:snake oil - -2019-01-02 Buyers remorse - assets:cash $90 - investment:snake oil - -2019-12-30 Fear of missing out - assets:cash -$90 - investment:snake oil - -2019-12-31 Recording the growth of Snake Oil - investment:snake oil = $101 - equity:unrealized gains - - Now IRR and TWR are drastically different: - - -$ hledger roi -Y --inv investment --pnl "unrealized" -+---++------------+------------++---------------+----------+-------------+-----++-------+-------+ -| || Begin | End || Value (begin) | Cashflow | Value (end) | PnL || IRR | TWR | -+===++============+============++===============+==========+=============+=====++=======+=======+ -| 1 || 2019-01-01 | 2019-12-31 || 0 | 100 | 101 | 1 || 9.32% | 1.00% | -+---++------------+------------++---------------+----------+-------------+-----++-------+-------+ - - Here, IRR tells us that we made close to 10% on the $10 dollars that -we had in the account most of the time. And TWR is ... just 1%? Why? - - Based on the transactions in our journal, TWR "think" that we are -buying back $90 worst of Snake Oil at the same price that it had at the -beginning of they year, and then after that our $100 investment gets $1 -increase in value, or 1% of $100. Let's take a closer look at what is -happening here by asking for quarterly reports instead of annual: - - -$ hledger roi -Q --inv investment --pnl "unrealized" -+---++------------+------------++---------------+----------+-------------+-----++--------+-------+ -| || Begin | End || Value (begin) | Cashflow | Value (end) | PnL || IRR | TWR | -+===++============+============++===============+==========+=============+=====++========+=======+ -| 1 || 2019-01-01 | 2019-03-31 || 0 | 10 | 10 | 0 || 0.00% | 0.00% | -| 2 || 2019-04-01 | 2019-06-30 || 10 | 0 | 10 | 0 || 0.00% | 0.00% | -| 3 || 2019-07-01 | 2019-09-30 || 10 | 0 | 10 | 0 || 0.00% | 0.00% | -| 4 || 2019-10-01 | 2019-12-31 || 10 | 90 | 101 | 1 || 37.80% | 4.03% | -+---++------------+------------++---------------+----------+-------------+-----++--------+-------+ - - Now both IRR and TWR are thrown off by the fact that all of the -growth for our investment happens in Q4 2019. This happes because IRR -computation is still yielding 9.32% and TWR is still 1%, but this time -these are rates for three month period instead of twelve, so in order to -get an annual rate they should be multiplied by four! - - Let's try to keep a better record of how Snake Oil grew in value: - - -2019-01-01 Investing in Snake Oil - assets:cash -$100 - investment:snake oil - -2019-01-02 Buyers remorse - assets:cash $90 - investment:snake oil - -2019-02-28 Recording the growth of Snake Oil - investment:snake oil - equity:unrealized gains -$0.25 - -2019-06-30 Recording the growth of Snake Oil - investment:snake oil - equity:unrealized gains -$0.25 - -2019-09-30 Recording the growth of Snake Oil - investment:snake oil - equity:unrealized gains -$0.25 - -2019-12-30 Fear of missing out - assets:cash -$90 - investment:snake oil - -2019-12-31 Recording the growth of Snake Oil - investment:snake oil - equity:unrealized gains -$0.25 - - Would our quartery report look better now? Almost: - - -$ hledger roi -Q --inv investment --pnl "unrealized" -+---++------------+------------++---------------+----------+-------------+------++--------+--------+ -| || Begin | End || Value (begin) | Cashflow | Value (end) | PnL || IRR | TWR | -+===++============+============++===============+==========+=============+======++========+========+ -| 1 || 2019-01-01 | 2019-03-31 || 0 | 10 | 10.25 | 0.25 || 9.53% | 10.53% | -| 2 || 2019-04-01 | 2019-06-30 || 10.25 | 0 | 10.50 | 0.25 || 10.15% | 10.15% | -| 3 || 2019-07-01 | 2019-09-30 || 10.50 | 0 | 10.75 | 0.25 || 9.79% | 9.78% | -| 4 || 2019-10-01 | 2019-12-31 || 10.75 | 90 | 101.00 | 0.25 || 8.05% | 1.00% | -+---++------------+------------++---------------+----------+-------------+------++--------+--------+ - - Something is still wrong with TWR computation for Q4, and if you have -been paying attention you know what it is already: big $90 buy-back is -recorded prior to the only transaction that captures the change of value -of Snake Oil that happened in this time period. Lets combine -transactions from 30th and 31st of Dec into one: - - -2019-12-30 Fear of missing out and growth of Snake Oil - assets:cash -$90 - investment:snake oil - equity:unrealized gains -$0.25 - - Now growth of investment properly affects its price at the time of -buy-back: - - -$ hledger roi -Q --inv investment --pnl "unrealized" -+---++------------+------------++---------------+----------+-------------+------++--------+--------+ -| || Begin | End || Value (begin) | Cashflow | Value (end) | PnL || IRR | TWR | -+===++============+============++===============+==========+=============+======++========+========+ -| 1 || 2019-01-01 | 2019-03-31 || 0 | 10 | 10.25 | 0.25 || 9.53% | 10.53% | -| 2 || 2019-04-01 | 2019-06-30 || 10.25 | 0 | 10.50 | 0.25 || 10.15% | 10.15% | -| 3 || 2019-07-01 | 2019-09-30 || 10.50 | 0 | 10.75 | 0.25 || 9.79% | 9.78% | -| 4 || 2019-10-01 | 2019-12-31 || 10.75 | 90 | 101.00 | 0.25 || 8.05% | 9.57% | -+---++------------+------------++---------------+----------+-------------+------++--------+--------+ - - And for annual report, TWR now reports the exact profitability of our -investment: - - -$ hledger roi -Y --inv investment --pnl "unrealized" -+---++------------+------------++---------------+----------+-------------+------++-------+--------+ -| || Begin | End || Value (begin) | Cashflow | Value (end) | PnL || IRR | TWR | -+===++============+============++===============+==========+=============+======++=======+========+ -| 1 || 2019-01-01 | 2019-12-31 || 0 | 100 | 101.00 | 1.00 || 9.32% | 10.00% | -+---++------------+------------++---------------+----------+-------------+------++-------+--------+ -  File: hledger.info, Node: stats, Next: tags, Prev: roi, Up: COMMANDS @@ -8539,339 +8704,355 @@ Node: aregister and custom posting dates66945 Ref: #aregister-and-custom-posting-dates67111 Node: balance67932 Ref: #balance68051 -Node: Single-period flat balance report69697 -Ref: #single-period-flat-balance-report69905 -Node: Single-period tree-mode balance report70606 -Ref: #single-period-tree-mode-balance-report70860 -Node: Multi-period balance report72301 -Ref: #multi-period-balance-report72514 -Node: Depth limiting78125 -Ref: #depth-limiting78288 -Node: Colour support78982 -Ref: #colour-support79135 -Node: Sorting by amount79231 -Ref: #sorting-by-amount79387 -Node: Percentages79877 -Ref: #percentages80048 -Node: Customising single-period balance reports81181 -Ref: #customising-single-period-balance-reports81408 -Node: Budget report83539 -Ref: #budget-report83690 -Node: Budget report start date88949 -Ref: #budget-report-start-date89116 -Node: Nested budgets90443 -Ref: #nested-budgets90590 -Node: balancesheet93977 -Ref: #balancesheet94115 -Node: balancesheetequity95748 -Ref: #balancesheetequity95899 -Node: cashflow97118 -Ref: #cashflow97242 -Node: check98574 -Ref: #check98679 -Node: Basic checks99312 -Ref: #basic-checks99430 -Node: Strict checks99963 -Ref: #strict-checks100104 -Node: Other checks100408 -Ref: #other-checks100548 -Node: Custom checks100985 -Ref: #custom-checks101105 -Node: close101523 -Ref: #close101627 -Node: close usage103144 -Ref: #close-usage103239 -Node: codes106047 -Ref: #codes106157 -Node: commodities106870 -Ref: #commodities106999 -Node: descriptions107081 -Ref: #descriptions107211 -Node: diff107515 -Ref: #diff107623 -Node: files108668 -Ref: #files108770 -Node: help108916 -Ref: #help109018 -Node: import109741 -Ref: #import109857 -Node: Importing balance assignments110777 -Ref: #importing-balance-assignments110960 -Node: Commodity display styles111607 -Ref: #commodity-display-styles111780 -Node: incomestatement111909 -Ref: #incomestatement112044 -Node: notes113500 -Ref: #notes113615 -Node: payees113982 -Ref: #payees114090 -Node: prices114616 -Ref: #prices114724 -Node: print115063 -Ref: #print115175 -Node: print-unique121005 -Ref: #print-unique121133 -Node: register121419 -Ref: #register121548 -Node: Custom register output125992 -Ref: #custom-register-output126123 -Node: register-match127460 -Ref: #register-match127596 -Node: rewrite127944 -Ref: #rewrite128061 -Node: Re-write rules in a file129967 -Ref: #re-write-rules-in-a-file130130 -Node: Diff output format131280 -Ref: #diff-output-format131463 -Node: rewrite vs print --auto132555 -Ref: #rewrite-vs.-print---auto132715 -Node: roi133265 -Ref: #roi133365 -Node: stats145558 -Ref: #stats145659 -Node: tags146446 -Ref: #tags146546 -Node: test147063 -Ref: #test147179 -Node: About add-on commands147924 -Ref: #about-add-on-commands148061 -Node: JOURNAL FORMAT149194 -Ref: #journal-format149322 -Node: Transactions151502 -Ref: #transactions151617 -Node: Dates152634 -Ref: #dates152750 -Node: Simple dates152815 -Ref: #simple-dates152935 -Node: Secondary dates153442 -Ref: #secondary-dates153590 -Node: Posting dates154924 -Ref: #posting-dates155047 -Node: Status156416 -Ref: #status156533 -Node: Description158238 -Ref: #description158368 -Node: Payee and note158686 -Ref: #payee-and-note158794 -Node: Comments159128 -Ref: #comments159250 -Node: Tags160443 -Ref: #tags-1160554 -Node: Postings161952 -Ref: #postings162076 -Node: Virtual postings163100 -Ref: #virtual-postings163211 -Node: Account names164513 -Ref: #account-names164650 -Node: Amounts165136 -Ref: #amounts165271 -Node: Decimal marks digit group marks166330 -Ref: #decimal-marks-digit-group-marks166519 -Node: Commodity display style167866 -Ref: #commodity-display-style168054 -Node: Rounding170080 -Ref: #rounding170198 -Node: Transaction prices170608 -Ref: #transaction-prices170774 -Node: Lot prices lot dates173204 -Ref: #lot-prices-lot-dates173387 -Node: Balance assertions173874 -Ref: #balance-assertions174052 -Node: Assertions and ordering175082 -Ref: #assertions-and-ordering175264 -Node: Assertions and included files175961 -Ref: #assertions-and-included-files176198 -Node: Assertions and multiple -f options176529 -Ref: #assertions-and-multiple--f-options176779 -Node: Assertions and commodities176910 -Ref: #assertions-and-commodities177136 -Node: Assertions and prices178291 -Ref: #assertions-and-prices178499 -Node: Assertions and subaccounts178940 -Ref: #assertions-and-subaccounts179163 -Node: Assertions and virtual postings179487 -Ref: #assertions-and-virtual-postings179723 -Node: Assertions and precision179864 -Ref: #assertions-and-precision180051 -Node: Balance assignments180316 -Ref: #balance-assignments180486 -Node: Balance assignments and prices181649 -Ref: #balance-assignments-and-prices181815 -Node: Directives182041 -Ref: #directives182204 -Node: Directives and multiple files187609 -Ref: #directives-and-multiple-files187805 -Node: Comment blocks188467 -Ref: #comment-blocks188644 -Node: Including other files188819 -Ref: #including-other-files188993 -Node: Default year189917 -Ref: #default-year190075 -Node: Declaring payees190482 -Ref: #declaring-payees190648 -Node: Declaring commodities190893 -Ref: #declaring-commodities191074 -Node: Commodity error checking192915 -Ref: #commodity-error-checking193065 -Node: Default commodity193321 -Ref: #default-commodity193501 -Node: Declaring market prices194386 -Ref: #declaring-market-prices194575 -Node: Declaring accounts195433 -Ref: #declaring-accounts195613 -Node: Account error checking196820 -Ref: #account-error-checking196986 -Node: Account comments198163 -Ref: #account-comments198347 -Node: Account subdirectives198773 -Ref: #account-subdirectives198958 -Node: Account types199273 -Ref: #account-types199447 -Node: Declaring account types200182 -Ref: #declaring-account-types200361 -Node: Auto-detected account types201012 -Ref: #auto-detected-account-types201253 -Node: Interference from auto-detected account types202152 -Ref: #interference-from-auto-detected-account-types202429 -Node: Old account type syntax202912 -Ref: #old-account-type-syntax203109 -Node: Account display order203410 -Ref: #account-display-order203570 -Node: Rewriting accounts204721 -Ref: #rewriting-accounts204900 -Node: Basic aliases205659 -Ref: #basic-aliases205795 -Node: Regex aliases206497 -Ref: #regex-aliases206659 -Node: Combining aliases207379 -Ref: #combining-aliases207562 -Node: Aliases and multiple files208839 -Ref: #aliases-and-multiple-files209038 -Node: end aliases209619 -Ref: #end-aliases209766 -Node: Default parent account209868 -Ref: #default-parent-account210058 -Node: Periodic transactions210942 -Ref: #periodic-transactions211125 -Node: Periodic rule syntax213042 -Ref: #periodic-rule-syntax213242 -Node: Two spaces between period expression and description!213945 -Ref: #two-spaces-between-period-expression-and-description214258 -Node: Forecasting with periodic transactions214943 -Ref: #forecasting-with-periodic-transactions215242 -Node: Budgeting with periodic transactions217288 -Ref: #budgeting-with-periodic-transactions217521 -Node: Auto postings217928 -Ref: #auto-postings218064 -Node: Auto postings and multiple files220247 -Ref: #auto-postings-and-multiple-files220445 -Node: Auto postings and dates220653 -Ref: #auto-postings-and-dates220921 -Node: Auto postings and transaction balancing / inferred amounts / balance assertions221096 -Ref: #auto-postings-and-transaction-balancing-inferred-amounts-balance-assertions221442 -Node: Auto posting tags221787 -Ref: #auto-posting-tags221996 -Node: CSV FORMAT222633 -Ref: #csv-format222761 -Node: Examples225342 -Ref: #examples225445 -Node: Basic225652 -Ref: #basic225754 -Node: Bank of Ireland226298 -Ref: #bank-of-ireland226435 -Node: Amazon227900 -Ref: #amazon228020 -Node: Paypal229741 -Ref: #paypal229837 -Node: CSV rules237485 -Ref: #csv-rules237603 -Node: skip237915 -Ref: #skip238010 -Node: fields238382 -Ref: #fields238506 -Node: Transaction field names239667 -Ref: #transaction-field-names239829 -Node: Posting field names239940 -Ref: #posting-field-names240094 -Node: field assignment242455 -Ref: #field-assignment242600 -Node: separator243414 -Ref: #separator243551 -Node: if block244093 -Ref: #if-block244220 -Node: Matching the whole record244618 -Ref: #matching-the-whole-record244795 -Node: Matching individual fields245599 -Ref: #matching-individual-fields245805 -Node: Combining matchers246029 -Ref: #combining-matchers246227 -Node: Rules applied on successful match246541 -Ref: #rules-applied-on-successful-match246734 -Node: if table247391 -Ref: #if-table247512 -Node: end249248 -Ref: #end249362 -Node: date-format249586 -Ref: #date-format249720 -Node: decimal-mark250470 -Ref: #decimal-mark250615 -Node: newest-first250952 -Ref: #newest-first251095 -Node: include251778 -Ref: #include251911 -Node: balance-type252353 -Ref: #balance-type252475 -Node: Tips253175 -Ref: #tips253266 -Node: Rapid feedback253565 -Ref: #rapid-feedback253684 -Node: Valid CSV254143 -Ref: #valid-csv254275 -Node: File Extension254467 -Ref: #file-extension254621 -Node: Reading multiple CSV files255050 -Ref: #reading-multiple-csv-files255237 -Node: Valid transactions255477 -Ref: #valid-transactions255657 -Node: Deduplicating importing256285 -Ref: #deduplicating-importing256466 -Node: Setting amounts257498 -Ref: #setting-amounts257655 -Node: Amount signs259874 -Ref: #amount-signs260028 -Node: Setting currency/commodity260715 -Ref: #setting-currencycommodity260903 -Node: Amount decimal places262083 -Ref: #amount-decimal-places262275 -Node: Referencing other fields262587 -Ref: #referencing-other-fields262786 -Node: How CSV rules are evaluated263684 -Ref: #how-csv-rules-are-evaluated263859 -Node: TIMECLOCK FORMAT265308 -Ref: #timeclock-format265448 -Node: TIMEDOT FORMAT267516 -Ref: #timedot-format267654 -Node: COMMON TASKS271917 -Ref: #common-tasks272046 -Node: Getting help272453 -Ref: #getting-help272587 -Node: Constructing command lines273138 -Ref: #constructing-command-lines273332 -Node: Starting a journal file274031 -Ref: #starting-a-journal-file274231 -Node: Setting opening balances275418 -Ref: #setting-opening-balances275616 -Node: Recording transactions278749 -Ref: #recording-transactions278931 -Node: Reconciling279488 -Ref: #reconciling279633 -Node: Reporting281878 -Ref: #reporting282020 -Node: Migrating to a new file285940 -Ref: #migrating-to-a-new-file286090 -Node: LIMITATIONS286388 -Ref: #limitations286516 -Node: TROUBLESHOOTING287257 -Ref: #troubleshooting287372 +Node: balance features68964 +Ref: #balance-features69104 +Node: Simple balance report70774 +Ref: #simple-balance-report70956 +Node: Filtered balance report72404 +Ref: #filtered-balance-report72591 +Node: List or tree mode72888 +Ref: #list-or-tree-mode73056 +Node: Depth limiting74373 +Ref: #depth-limiting74539 +Node: Multi-period balance report75297 +Ref: #multi-period-balance-report75489 +Node: Sorting by amount77745 +Ref: #sorting-by-amount77914 +Node: Percentages78376 +Ref: #percentages78532 +Node: Balance change end balance79464 +Ref: #balance-change-end-balance79655 +Node: Balance report types81079 +Ref: #balance-report-types81269 +Node: Useful balance reports85433 +Ref: #useful-balance-reports85614 +Node: Budget report86698 +Ref: #budget-report86882 +Node: Budget report start date92051 +Ref: #budget-report-start-date92220 +Node: Nested budgets93547 +Ref: #nested-budgets93696 +Node: Customising single-period balance reports97083 +Ref: #customising-single-period-balance-reports97292 +Node: balancesheet99449 +Ref: #balancesheet99587 +Node: balancesheetequity100885 +Ref: #balancesheetequity101036 +Node: cashflow102416 +Ref: #cashflow102540 +Node: check103686 +Ref: #check103791 +Node: Basic checks104424 +Ref: #basic-checks104542 +Node: Strict checks105075 +Ref: #strict-checks105216 +Node: Other checks105520 +Ref: #other-checks105660 +Node: Custom checks106013 +Ref: #custom-checks106133 +Node: close106551 +Ref: #close106655 +Node: close usage108172 +Ref: #close-usage108267 +Node: codes111075 +Ref: #codes111185 +Node: commodities111898 +Ref: #commodities112027 +Node: descriptions112109 +Ref: #descriptions112239 +Node: diff112543 +Ref: #diff112651 +Node: files113696 +Ref: #files113798 +Node: help113944 +Ref: #help114046 +Node: import114769 +Ref: #import114885 +Node: Deduplication115747 +Ref: #deduplication115872 +Node: Import testing117760 +Ref: #import-testing117925 +Node: Importing balance assignments118415 +Ref: #importing-balance-assignments118621 +Node: Commodity display styles119268 +Ref: #commodity-display-styles119441 +Node: incomestatement119570 +Ref: #incomestatement119705 +Node: notes121006 +Ref: #notes121121 +Node: payees121488 +Ref: #payees121596 +Node: prices122122 +Ref: #prices122230 +Node: print122569 +Ref: #print122681 +Node: print-unique127991 +Ref: #print-unique128119 +Node: register128405 +Ref: #register128534 +Node: Custom register output132978 +Ref: #custom-register-output133109 +Node: register-match134446 +Ref: #register-match134582 +Node: rewrite134930 +Ref: #rewrite135047 +Node: Re-write rules in a file136953 +Ref: #re-write-rules-in-a-file137116 +Node: Diff output format138266 +Ref: #diff-output-format138449 +Node: rewrite vs print --auto139541 +Ref: #rewrite-vs.-print---auto139701 +Node: roi140251 +Ref: #roi140351 +Node: Semantics of --inv and --pnl141986 +Ref: #semantics-of---inv-and---pnl142168 +Node: IRR and TWR explained144014 +Ref: #irr-and-twr-explained144174 +Node: stats147236 +Ref: #stats147337 +Node: tags148124 +Ref: #tags148224 +Node: test148741 +Ref: #test148857 +Node: About add-on commands149602 +Ref: #about-add-on-commands149739 +Node: JOURNAL FORMAT150872 +Ref: #journal-format151000 +Node: Transactions153180 +Ref: #transactions153295 +Node: Dates154312 +Ref: #dates154428 +Node: Simple dates154493 +Ref: #simple-dates154613 +Node: Secondary dates155120 +Ref: #secondary-dates155268 +Node: Posting dates156602 +Ref: #posting-dates156725 +Node: Status158094 +Ref: #status158211 +Node: Description159916 +Ref: #description160046 +Node: Payee and note160364 +Ref: #payee-and-note160472 +Node: Comments160806 +Ref: #comments160928 +Node: Tags162121 +Ref: #tags-1162232 +Node: Postings163630 +Ref: #postings163754 +Node: Virtual postings164778 +Ref: #virtual-postings164889 +Node: Account names166191 +Ref: #account-names166328 +Node: Amounts166814 +Ref: #amounts166949 +Node: Decimal marks digit group marks168008 +Ref: #decimal-marks-digit-group-marks168197 +Node: Commodity display style169544 +Ref: #commodity-display-style169732 +Node: Rounding171758 +Ref: #rounding171876 +Node: Transaction prices172286 +Ref: #transaction-prices172452 +Node: Lot prices lot dates174882 +Ref: #lot-prices-lot-dates175065 +Node: Balance assertions175552 +Ref: #balance-assertions175730 +Node: Assertions and ordering176760 +Ref: #assertions-and-ordering176942 +Node: Assertions and included files177639 +Ref: #assertions-and-included-files177876 +Node: Assertions and multiple -f options178207 +Ref: #assertions-and-multiple--f-options178457 +Node: Assertions and commodities178588 +Ref: #assertions-and-commodities178814 +Node: Assertions and prices179969 +Ref: #assertions-and-prices180177 +Node: Assertions and subaccounts180618 +Ref: #assertions-and-subaccounts180841 +Node: Assertions and virtual postings181165 +Ref: #assertions-and-virtual-postings181401 +Node: Assertions and precision181542 +Ref: #assertions-and-precision181729 +Node: Balance assignments181994 +Ref: #balance-assignments182164 +Node: Balance assignments and prices183327 +Ref: #balance-assignments-and-prices183493 +Node: Directives183719 +Ref: #directives183882 +Node: Directives and multiple files189287 +Ref: #directives-and-multiple-files189483 +Node: Comment blocks190145 +Ref: #comment-blocks190322 +Node: Including other files190497 +Ref: #including-other-files190671 +Node: Default year191595 +Ref: #default-year191753 +Node: Declaring payees192160 +Ref: #declaring-payees192326 +Node: Declaring commodities192571 +Ref: #declaring-commodities192752 +Node: Commodity error checking194593 +Ref: #commodity-error-checking194743 +Node: Default commodity194999 +Ref: #default-commodity195179 +Node: Declaring market prices196064 +Ref: #declaring-market-prices196253 +Node: Declaring accounts197111 +Ref: #declaring-accounts197291 +Node: Account error checking198498 +Ref: #account-error-checking198664 +Node: Account comments199841 +Ref: #account-comments200025 +Node: Account subdirectives200451 +Ref: #account-subdirectives200636 +Node: Account types200951 +Ref: #account-types201125 +Node: Declaring account types201860 +Ref: #declaring-account-types202039 +Node: Auto-detected account types202690 +Ref: #auto-detected-account-types202931 +Node: Interference from auto-detected account types203830 +Ref: #interference-from-auto-detected-account-types204107 +Node: Old account type syntax204590 +Ref: #old-account-type-syntax204787 +Node: Account display order205088 +Ref: #account-display-order205248 +Node: Rewriting accounts206399 +Ref: #rewriting-accounts206578 +Node: Basic aliases207337 +Ref: #basic-aliases207473 +Node: Regex aliases208175 +Ref: #regex-aliases208337 +Node: Combining aliases209057 +Ref: #combining-aliases209240 +Node: Aliases and multiple files210517 +Ref: #aliases-and-multiple-files210716 +Node: end aliases211297 +Ref: #end-aliases211444 +Node: Default parent account211546 +Ref: #default-parent-account211736 +Node: Periodic transactions212620 +Ref: #periodic-transactions212803 +Node: Periodic rule syntax214720 +Ref: #periodic-rule-syntax214920 +Node: Two spaces between period expression and description!215623 +Ref: #two-spaces-between-period-expression-and-description215936 +Node: Forecasting with periodic transactions216621 +Ref: #forecasting-with-periodic-transactions216920 +Node: Budgeting with periodic transactions218966 +Ref: #budgeting-with-periodic-transactions219199 +Node: Auto postings219606 +Ref: #auto-postings219742 +Node: Auto postings and multiple files221925 +Ref: #auto-postings-and-multiple-files222123 +Node: Auto postings and dates222331 +Ref: #auto-postings-and-dates222599 +Node: Auto postings and transaction balancing / inferred amounts / balance assertions222774 +Ref: #auto-postings-and-transaction-balancing-inferred-amounts-balance-assertions223120 +Node: Auto posting tags223465 +Ref: #auto-posting-tags223674 +Node: CSV FORMAT224311 +Ref: #csv-format224439 +Node: Examples227020 +Ref: #examples227123 +Node: Basic227330 +Ref: #basic227432 +Node: Bank of Ireland227976 +Ref: #bank-of-ireland228113 +Node: Amazon229578 +Ref: #amazon229698 +Node: Paypal231419 +Ref: #paypal231515 +Node: CSV rules239163 +Ref: #csv-rules239281 +Node: skip239593 +Ref: #skip239688 +Node: fields240060 +Ref: #fields240184 +Node: Transaction field names241345 +Ref: #transaction-field-names241507 +Node: Posting field names241618 +Ref: #posting-field-names241772 +Node: field assignment244133 +Ref: #field-assignment244278 +Node: separator245092 +Ref: #separator245229 +Node: if block245771 +Ref: #if-block245898 +Node: Matching the whole record246296 +Ref: #matching-the-whole-record246473 +Node: Matching individual fields247277 +Ref: #matching-individual-fields247483 +Node: Combining matchers247707 +Ref: #combining-matchers247905 +Node: Rules applied on successful match248219 +Ref: #rules-applied-on-successful-match248412 +Node: if table249069 +Ref: #if-table249190 +Node: end250926 +Ref: #end251040 +Node: date-format251264 +Ref: #date-format251398 +Node: decimal-mark252148 +Ref: #decimal-mark252293 +Node: newest-first252630 +Ref: #newest-first252773 +Node: include253456 +Ref: #include253589 +Node: balance-type254031 +Ref: #balance-type254153 +Node: Tips254853 +Ref: #tips254944 +Node: Rapid feedback255243 +Ref: #rapid-feedback255362 +Node: Valid CSV255821 +Ref: #valid-csv255953 +Node: File Extension256145 +Ref: #file-extension256299 +Node: Reading multiple CSV files256728 +Ref: #reading-multiple-csv-files256915 +Node: Valid transactions257155 +Ref: #valid-transactions257335 +Node: Deduplicating importing257963 +Ref: #deduplicating-importing258144 +Node: Setting amounts259176 +Ref: #setting-amounts259333 +Node: Amount signs261552 +Ref: #amount-signs261706 +Node: Setting currency/commodity262393 +Ref: #setting-currencycommodity262581 +Node: Amount decimal places263761 +Ref: #amount-decimal-places263953 +Node: Referencing other fields264265 +Ref: #referencing-other-fields264464 +Node: How CSV rules are evaluated265362 +Ref: #how-csv-rules-are-evaluated265537 +Node: TIMECLOCK FORMAT266986 +Ref: #timeclock-format267126 +Node: TIMEDOT FORMAT269194 +Ref: #timedot-format269332 +Node: COMMON TASKS273595 +Ref: #common-tasks273724 +Node: Getting help274131 +Ref: #getting-help274265 +Node: Constructing command lines274816 +Ref: #constructing-command-lines275010 +Node: Starting a journal file275709 +Ref: #starting-a-journal-file275909 +Node: Setting opening balances277096 +Ref: #setting-opening-balances277294 +Node: Recording transactions280427 +Ref: #recording-transactions280609 +Node: Reconciling281166 +Ref: #reconciling281311 +Node: Reporting283556 +Ref: #reporting283698 +Node: Migrating to a new file287618 +Ref: #migrating-to-a-new-file287768 +Node: LIMITATIONS288066 +Ref: #limitations288194 +Node: TROUBLESHOOTING288935 +Ref: #troubleshooting289050  End Tag Table diff --git a/hledger/hledger.txt b/hledger/hledger.txt index 6df7b0488..63d181710 100644 --- a/hledger/hledger.txt +++ b/hledger/hledger.txt @@ -1680,40 +1680,90 @@ COMMANDS balance, bal Show accounts and their balances. - The balance command is hledger's most versatile command. Note, despite - the name, it is not always used for showing real-world account bal- - ances; the more accounting-aware balancesheet and incomestatement may - be more convenient for that. + balance is one of hledger's oldest and most versatile commands, for + listing account balances, balance changes, values, value changes and + more, during one time period or many. Generally it shows a table, with + rows representing accounts, and columns representing periods. - By default, it displays all accounts, and each account's change in bal- - ance during the entire period of the journal. Balance changes are cal- - culated by adding up the postings in each account. You can limit the - postings matched, by a query, to see fewer accounts, changes over a - different time period, changes from only cleared transactions, etc. + Note there are some higher-level variants of the balance command with + convenient defaults, which can be simpler to use: balancesheet, bal- + ancesheetequity, cashflow and incomestatement. When you need more con- + trol, then use balance. - If you include an account's complete history of postings in the report, - the balance change is equivalent to the account's current ending bal- - ance. For a real-world account, typically you won't have all transac- - tions in the journal; instead you'll have all transactions after a cer- - tain date, and an "opening balances" transaction setting the correct - starting balance on that date. Then the balance command will show - real-world account balances. In some cases the -H/--historical flag is - used to ensure this (more below). + balance features + Here's a quick overview of the balance command's features, followed by + more detailed descriptions and examples. Many of these work with the + higher-level commands as well. - This command also supports the output destination and output format - options The output formats supported are (in most modes): txt, csv, - html, and json. + balance can show.. - The balance command can produce several styles of report: + o accounts as a list (-l) or a tree (-t) + o optionally depth-limited (-[1-9]) - Single-period flat balance report - This is the default for hledger's balance command: a flat list of all - (or with a query, matched) accounts, showing full account names. - Accounts are sorted by declaration order if any, and then by account - name. Accounts which have zero balance are not shown unless -E/--empty - is used. The reported balances' total is shown as the last line, - unless disabled by -N/--no-total. + o sorted by declaration order and name, or by amount + + ..and their.. + + o balance changes (the default) + + o or actual and planned balance changes (--budget) + + o or value of balance changes (-V) + + o or change of balance values (--valuechange) + + ..in.. + + o one time period (the whole journal period by default) + + o or multiple periods (-D, -W, -M, -Q, -Y, -p INTERVAL) + + ..either.. + + o per period (the default) + + o or accumulated since report start date (--cumulative) + + o or accumulated since account creation (--historical/-H) + + ..possibly converted to.. + + o cost (--value=cost[,COMM]/--cost/-B) + + o or market value, as of transaction dates (--value=then[,COMM]) + + o or at period ends (--value=end[,COMM]) + + o or now (--value=now) + + o or at some other date (--value=YYYY-MM-DD) + + ..with.. + + o totals (-T), averages (-A), percentages (-%), inverted sign + (--invert) + + o rows and columns swapped (--transpose) + + o another field used as account name (--pivot) + + o custom-formatted line items (single-period reports only) (--format) + + This command supports the output destination and output format options, + with output formats txt, csv, json, and (multi-period reports only:) + html. In txt output in a colour-supporting terminal, negative amounts + are shown in red. + + Simple balance report + With no arguments, balance shows a list of all accounts and their + change of balance - ie, the sum of posting amounts, both inflows and + outflows - during the entire period of the journal. For real-world + accounts, this should also match their end balance at the end of the + journal period (more on this below). + + Accounts are sorted by declaration order if any, and then alphabeti- + cally by account name. For instance, using examples/sample.journal: $ hledger bal $1 assets:bank:saving @@ -1726,11 +1776,41 @@ COMMANDS -------------------- 0 + Accounts with a zero balance (and no non-zero subaccounts, in tree mode + - see below) are hidden by default. Use -E/--empty to show them + (revealing assets:bank:checking here): - Single-period tree-mode balance report - With the -t/--tree flag, accounts are displayed hierarchically, showing - subaccounts as short names indented below their parent. (This is the - default style in Ledger and in older hledger versions.) + $ hledger -f examples/sample.journal bal -E + 0 assets:bank:checking + $1 assets:bank:saving + $-2 assets:cash + $1 expenses:food + $1 expenses:supplies + $-1 income:gifts + $-1 income:salary + $1 liabilities:debts + -------------------- + 0 + + The total of the amounts displayed is shown as the last line, unless + -N/--no-total is used. + + Filtered balance report + You can show fewer accounts, a different time period, totals from + cleared transactions only, etc. by using query arguments or options to + limit the postings being matched. Eg: + + $ hledger bal --cleared assets date:200806 + $-2 assets:cash + -------------------- + $-2 + + List or tree mode + By default, or with -l/--flat, accounts are shown as a flat list with + their full names visible, as in the examples above. + + With -t/--tree, the account hierarchy is shown, with subaccounts' + "leaf" names indented below their parent: $ hledger balance $-1 assets @@ -1746,142 +1826,28 @@ COMMANDS -------------------- 0 - For more compact output, "boring" accounts containing a single inter- - esting subaccount and no balance of their own (assets:bank and liabili- - ties here) are elided into the following line, unless --no-elide is - used. And accounts which have zero balance and no non-zero subaccounts - are omitted, unless -E/--empty is used. + Notes: - Account balances in tree mode are "inclusive" - they include the bal- - ances of any subaccounts. Eg, the assets $-1 balance here includes the - $1 from assets:bank:saving and the $-2 from assets:cash. (And it would - include balance posted to the assets account itself, if there was any). - Note this causes some repetition, and the final total (0) is the sum of - the top-level balances, not of all the balances shown. + o "Boring" accounts are combined with their subaccount for more compact + output, unless --no-elide is used. Boring accounts have no balance + of their own and just one subaccount (eg assets:bank and liabilities + above). - Each group of sibling accounts is sorted separately, by declaration - order and then by account name. + o All balances shown are "inclusive", ie including the balances from + all subaccounts. Note this means some repetition in the output, + which requires explanation when sharing reports with non-plaintextac- + counting-users. A tree mode report's final total is the sum of the + top-level balances shown, not of all the balances shown. - Multi-period balance report - Multi-period balance reports are a very useful hledger feature, acti- - vated if you provide one of the reporting interval flags, such as - -M/--monthly. They are similar to single-period balance reports, but - they show the report as a table, with columns representing one or more - successive time periods. This is the usually the preferred style of - balance report in hledger (even for a single period). - - Multi-period balance reports come in several types, showing different - information: - - 1. A balance change report: by default, each column shows the sum of - postings in that period, ie the account's change of balance in that - period. This is useful eg for a monthly income statement: - - $ hledger balance --quarterly income expenses -E - Balance changes in 2008: - - || 2008q1 2008q2 2008q3 2008q4 - ===================++================================= - expenses:food || 0 $1 0 0 - expenses:supplies || 0 $1 0 0 - income:gifts || 0 $-1 0 0 - income:salary || $-1 0 0 0 - -------------------++--------------------------------- - || $-1 $1 0 0 - - 2. A cumulative end balance report: with --cumulative, each column - shows the end balance for that period, accumulating the changes - across periods, starting from 0 at the report start date: - - $ hledger balance --quarterly income expenses -E --cumulative - Ending balances (cumulative) in 2008: - - || 2008/03/31 2008/06/30 2008/09/30 2008/12/31 - ===================++================================================= - expenses:food || 0 $1 $1 $1 - expenses:supplies || 0 $1 $1 $1 - income:gifts || 0 $-1 $-1 $-1 - income:salary || $-1 $-1 $-1 $-1 - -------------------++------------------------------------------------- - || $-1 0 0 0 - - 3. A historical end balance report: with --historical/-H, each column - shows the actual historical end balance for that period, accumulat- - ing the changes across periods, and including the balance from any - postings before the report start date. This is useful eg for a - multi-period balance sheet, and when you want to see balances only - after a certain date: - - $ hledger balance ^assets ^liabilities --quarterly --historical --begin 2008/4/1 - Ending balances (historical) in 2008/04/01-2008/12/31: - - || 2008/06/30 2008/09/30 2008/12/31 - ======================++===================================== - assets:bank:checking || $1 $1 0 - assets:bank:saving || $1 $1 $1 - assets:cash || $-2 $-2 $-2 - liabilities:debts || 0 0 $1 - ----------------------++------------------------------------- - || 0 0 0 - - Note that --cumulative or --historical/-H disable --row-total/-T, since - summing end balances generally does not make sense. - - With a reporting interval (like --quarterly above), the report - start/end dates will be adjusted if necessary so that they encompass - the displayed report periods. This is so that the first and last peri- - ods will be "full" and comparable to the others. - - The -E/--empty flag does two things in multicolumn balance reports: - first, the report will show all columns within the specified report - period (without -E, leading and trailing columns with all zeroes are - not shown). Second, all accounts which existed at the report start - date will be considered, not just the ones with activity during the - report period (use -E to include low-activity accounts which would oth- - erwise would be omitted). - - The -T/--row-total flag adds an additional column showing the total for - each row. - - The -A/--average flag adds a column showing the average value in each - row. - - Here's an example of all three: - - $ hledger balance -Q income expenses --tree -ETA - Balance changes in 2008: - - || 2008q1 2008q2 2008q3 2008q4 Total Average - ============++=================================================== - expenses || 0 $2 0 0 $2 $1 - food || 0 $1 0 0 $1 0 - supplies || 0 $1 0 0 $1 0 - income || $-1 $-1 0 0 $-2 $-1 - gifts || 0 $-1 0 0 $-1 0 - salary || $-1 0 0 0 $-1 0 - ------------++--------------------------------------------------- - || $-1 $1 0 0 0 0 - - (Average is rounded to the dollar here since all journal amounts are) - - The --transpose flag can be used to exchange the rows and columns of a - multicolumn report. - - When showing multicommodity amounts, multicolumn balance reports will - elide any amounts which have more than two commodities, since otherwise - columns could get very wide. The --no-elide flag disables this. Hid- - ing totals with the -N/--no-total flag can also help reduce the width - of multicommodity reports. - - When the report is still too wide, a good workaround is to pipe it into - less -RS (-R for colour, -S to chop long lines). Eg: hledger bal -D - --color=yes | less -RS. + o Each group of sibling accounts (ie, under a common parent) is sorted + separately. Depth limiting - With a depth:N query, or --depth N option, or just -N, balance reports - will show accounts only to the specified depth. This is very useful to - hide low-level accounts and get an overview. Eg, limiting to depth 1 - shows the top-level accounts: + With a depth:N query, or --depth N option, or just -N, balance reports + will show accounts only to the specified depth, hiding the deeper sub- + accounts. Account balances at the depth limit always include the bal- + ances from any hidden subaccounts (even in list mode). This can be + useful for getting an overview. Eg, limiting to depth 1: $ hledger balance -N -1 $-1 assets @@ -1889,127 +1855,283 @@ COMMANDS $-2 income $1 liabilities - Accounts at the depth limit will include the balances of any hidden - subaccounts (even in flat mode, which normally shows exclusive bal- - ances). + You can also hide top-level account name parts, using --drop N. This + can be useful for hiding repetitive top-level account names: - You can also drop account name components from the start of account - names, using --drop N. This can be useful to hide unwanted top-level - detail. + $ hledger bal expenses --drop 1 + $1 food + $1 supplies + -------------------- + $2 - Colour support - In terminal output, when colour is enabled, the balance command shows - negative amounts in red. + + Multi-period balance report + With a report interval (set by the -D/--daily, -W/--weekly, + -M/--monthly, -Q/--quarterly, -Y/--yearly, or -p/--period flag), bal- + ance shows a tabular report, with columns representing successive time + periods (and a title): + + $ hledger balance --quarterly income expenses -E + Balance changes in 2008: + + || 2008q1 2008q2 2008q3 2008q4 + ===================++================================= + expenses:food || 0 $1 0 0 + expenses:supplies || 0 $1 0 0 + income:gifts || 0 $-1 0 0 + income:salary || $-1 0 0 0 + -------------------++--------------------------------- + || $-1 $1 0 0 + + Notes: + + o The report's start/end dates will be expanded, if necessary, to fully + encompass the displayed subperiods (so that the first and last subpe- + riods have the same duration as the others). + + o Leading and trailing periods (columns) containing all zeroes are not + shown, unless -E/--empty is used. + + o Accounts (rows) containing all zeroes are not shown, unless + -E/--empty is used. + + o Amounts with many commodities are shown in abbreviated form, unless + --no-elide is used. (experimental) + + o Average and/or total columns can be added with the -A/--average and + -T/--row-total flags. + + o The --transpose flag can be used to exchange rows and columns. + + o The --pivot FIELD option causes a different transaction field to be + used as "account name". See PIVOTING. + + Multi-period reports with many periods can be too wide for easy viewing + in the terminal. Here are some ways to handle that: + + o Hide the totals row with -N/--no-total + + o Convert to a single currency with -V + + o Maximize the terminal window + + o Reduce the terminal's font size + + o View with a pager like less, eg: hledger bal -D --color=yes | less + -RS + + o Output as CSV and use a CSV viewer like visidata (hledger bal -D -O + csv | vd -f csv), Emacs' csv-mode (M-x csv-mode, C-c C-a), or a + spreadsheet (hledger bal -D -o a.csv && open a.csv) + + o Output as HTML and view with a browser: hledger bal -D -o a.html && + open a.html Sorting by amount - With -S/--sort-amount, accounts with the largest (most positive) bal- - ances are shown first. For example, hledger bal expenses -MAS shows - your biggest averaged monthly expenses first. + With -S/--sort-amount, accounts with the largest (most positive) bal- + ances are shown first. Eg: hledger bal expenses -MAS shows your big- + gest averaged monthly expenses first. + + Revenues and liability balances are typically negative, however, so -S + shows these in reverse order. To work around this, you can add + --invert to flip the signs. (Or, use one of the higher-level reports, + which flip the sign automatically. Eg: hledger incomestatement -MAS). - Revenues and liability balances are typically negative, however, so -S - shows these in reverse order. To work around this, you can add - --invert to flip the signs. Or, use one of the sign-flipping reports - like balancesheet or incomestatement, which also support -S. Eg: - hledger is -MAS. Percentages - With -% or --percent, balance reports show each account's value - expressed as a percentage of the column's total. This is useful to get - an overview of the relative sizes of account balances. For example to - obtain an overview of expenses: + With -%/--percent, balance reports show each account's value expressed + as a percentage of the (column) total: - $ hledger balance expenses -% - 100.0 % expenses - 50.0 % food - 50.0 % supplies - -------------------- - 100.0 % + $ hledger bal expenses -Q -% + Balance changes in 2008: - Note that --tree does not have an effect on -%. The percentages are - always relative to the total sum of each column, they are never rela- - tive to the parent account. + || 2008Q1 2008Q2 2008Q3 2008Q4 + ===================++================================= + expenses:food || 0 50.0 % 0 0 + expenses:supplies || 0 50.0 % 0 0 + -------------------++--------------------------------- + || 0 100.0 % 0 0 - Since the percentages are relative to the columns sum, it is usually - not useful to calculate percentages if the signs of the amounts are - mixed. Although the results are technically correct, they are most - likely useless. Especially in a balance report that sums up to zero - (eg hledger balance -B) all percentage values will be zero. + Note it is not useful to calculate percentages if the amounts in a col- + umn have mixed signs. In this case, make a separate report for each + sign, eg: - This flag does not work if the report contains any mixed commodity - accounts. If there are mixed commodity accounts in the report be sure - to use -V or -B to coerce the report into using a single commodity. + $ hledger bal -% amt:`>0` + $ hledger bal -% amt:`<0` + + Similarly, if the amounts in a column have mixed commodities, convert + them to one commodity with -B, -V, -X or --value, or make a separate + report for each commodity: + + $ hledger bal -% cur:\\$ + $ hledger bal -% cur:EUR + + Balance change, end balance + It's important to be clear on the meaning of the numbers shown in bal- + ance reports. Here is some terminology we use: + + A balance change is the net amount added to, or removed from, an + account during some period. + + An end balance is the amount accumulated in an account as of some date + (and some time, but hledger doesn't store that; assume end of day in + your timezone). It is the sum of previous balance changes. + + We call it a historical end balance if it includes all balance changes + since the account was created. For a real world account, this means it + will match the "historical record", eg the balances reported in your + bank statements or bank web UI. (If they are correct!) + + In general, balance changes are what you want to see when reviewing + revenues and expenses, and historical end balances are what you want to + see when reviewing or reconciling asset, liability and equity accounts. + + balance shows balance changes by default. To see accurate historical + end balances: + + 1. Initialise account starting balances with an "opening balances" + transaction (a transfer from equity to the account), unless the + journal covers the account's full lifetime. + + 2. Include all of of the account's prior postings in the report, by not + specifying a report start date, or by using the -H/--historical + flag. (-H causes report start date to be ignored when summing post- + ings.) + + Balance report types + For more flexible reporting, there are three important option groups: + + hledger balance [CALCULATIONTYPE] [ACCUMULATIONTYPE] [VALUATIONTYPE] + ... + + The first two are the most important: calculation type selects the + basic calculation to perform for each table cell, while accumulation + type says which postings should be included in each cell's calculation. + Typically one or both of these are selected by default, so you don't + need to write them explicitly. A valuation type can be added if you + want to convert the basic report to value or cost. + + Calculation type: + The basic calculation to perform for each table cell. It is one of: + + o --sum : sum the posting amounts (default) + + o --budget : like --sum but also show a goal amount + + o --valuechange : show the change in period-end historical balance val- + ues + + Accumulation type: + Which postings should be included in each cell's calculation. It is + one of: + + o --change : postings from column start to column end, ie within the + cell's period. Typically used to see revenues/expenses. (default + for balance, incomestatement) + + o --cumulative : postings from report start to column end, eg to show + changes accumulated since the report's start date. Rarely used. + + o --historical/-H : postings from journal start to column end, ie all + postings from account creation to the end of the cell's period. Typ- + ically used to see historical end balances of assets/liabili- + ties/equity. (default for balancesheet, balancesheetequity, cash- + flow) + + Valuation type: + Which kind of valuation, valuation date(s) and optionally a target val- + uation commodity to use. It is one of: + + o no valuation, show amounts in their original commodities (default) + + o --value=cost[,COMM] : no valuation, show amounts converted to cost + + o --value=then[,COMM] : show value at transaction dates + + o --value=end[,COMM] : show value at period end date(s) (default with + --valuechange) + + o --value=now[,COMM] : show value at today's date + + o --value=YYYY-MM-DD[,COMM] : show value at another date + + or one of their aliases: --cost/-B, --market/-V or --exchange/-X. + + Most combinations of these options should produce reasonable reports, + but if you find any that seem wrong or misleading, let us know. The + following restrictions are applied: + + o --valuechange implies --value=end + + o --valuechange makes --change the default when used with the bal- + ancesheet/balancesheetequity commands + + o --cumulative or --historical disables --row-total/-T + + For reference, here is what the combinations of accumulation and valua- + tion show: - Customising single-period balance reports - You can customise the layout of single-period balance reports with - --format FMT, which sets the format of each line. Eg: + Valua- no valuation --value= then --value= end --value= YYYY- + tion: MM-DD /now + >Accumu- + lation: + v + ------------------------------------------------------------------------------------ + --change change in period sum of posting- period-end DATE-value of + date market val- value of change change in + ues in period in period period + --cumu- change from sum of posting- period-end DATE-value of + lative report start to date market val- value of change change from + period end ues from report from report report start + start to period start to period to period end + end end + --his- change from sum of posting- period-end DATE-value of + torical journal start to date market val- value of change change from + /-H period end (his- ues from journal from journal journal start + torical end bal- start to period start to period to period end + ance) end end - $ hledger balance --format "%20(account) %12(total)" - assets $-1 - bank:saving $1 - cash $-2 - expenses $2 - food $1 - supplies $1 - income $-2 - gifts $-1 - salary $-1 - liabilities:debts $1 - --------------------------------- - 0 + Useful balance reports + Some frequently used balance options/reports are: - The FMT format string (plus a newline) specifies the formatting applied - to each account/balance pair. It may contain any suitable text, with - data fields interpolated like so: + o bal -M revenues expenses + Show revenues/expenses in each month. Also available as the incomes- + tatement command. - %[MIN][.MAX](FIELDNAME) + o bal -M -H assets liabilities + Show historical asset/liability balances at each month end. Also + available as the balancesheet command. - o MIN pads with spaces to at least this width (optional) + o bal -M -H assets liabilities equity + Show historical asset/liability/equity balances at each month end. + Also available as the balancesheetequity command. - o MAX truncates at this width (optional) + o bal -M assets not:receivable + Show changes to liquid assets in each month. Also available as the + cashflow command. - o FIELDNAME must be enclosed in parentheses, and can be one of: + Also: - o depth_spacer - a number of spaces equal to the account's depth, or - if MIN is specified, MIN * depth spaces. + o bal -M expenses -2 -SA + Show monthly expenses summarised to depth 2 and sorted by average + amount. - o account - the account's name + o bal -M --budget expenses + Show monthly expenses and budget goals. - o total - the account's balance/posted total, right justified + o bal -M --valuechange investments + Show monthly change in market value of investment assets. - Also, FMT can begin with an optional prefix to control how multi-com- - modity amounts are rendered: - - o %_ - render on multiple lines, bottom-aligned (the default) - - o %^ - render on multiple lines, top-aligned - - o %, - render on one line, comma-separated - - There are some quirks. Eg in one-line mode, %(depth_spacer) has no - effect, instead %(account) has indentation built in. Experimentation - may be needed to get pleasing results. - - Some example formats: - - o %(total) - the account's total - - o %-20.20(account) - the account's name, left justified, padded to 20 - characters and clipped at 20 characters - - o %,%-50(account) %25(total) - account name padded to 50 characters, - total padded to 20 characters, with multiple commodities rendered on - one line - - o %20(total) %2(depth_spacer)%-(account) - the default format for the - single-column balance report + o bal investments --valuechange -D date:lastweek amt:'>1000' -STA + [--invert] + Show top gainers [or losers] last week Budget report - There is also a special balance report mode for showing budget perfor- - mance. The --budget flag activates extra columns showing the budget - goals for each account and period, if any. For this report, budget - goals are defined by periodic transactions. This is very useful for - comparing planned and actual income, expenses, time usage, etc. + The --budget report type activates extra columns showing any budget + goals for each account and period. The budget goals are defined by + periodic transactions. This is very useful for comparing planned and + actual income, expenses, time usage, etc. For example, you can take average monthly expenses in the common expense categories to construct a minimal monthly budget: @@ -2065,11 +2187,11 @@ COMMANDS goal amounts are shown, and the actual/goal percentage. (Note: bud- get goals should be in the same commodity as the actual amount.) - o All parent accounts are always shown, even in flat mode. Eg assets, + o All parent accounts are always shown, even in list mode. Eg assets, assets:bank, and expenses above. o Amounts always include all subaccounts, budgeted or unbudgeted, even - in flat mode. + in list mode. This means that the numbers displayed will not always add up! Eg above, the expenses actual amount includes the gifts and supplies transac- @@ -2240,6 +2362,71 @@ COMMANDS ----------------------------------------++------------------------------- || 0 [ 0] + Customising single-period balance reports + For single-period balance reports displayed in the terminal (only), you + can use --format FMT to customise the format and content of each line. + Eg: + + $ hledger balance --format "%20(account) %12(total)" + assets $-1 + bank:saving $1 + cash $-2 + expenses $2 + food $1 + supplies $1 + income $-2 + gifts $-1 + salary $-1 + liabilities:debts $1 + --------------------------------- + 0 + + The FMT format string (plus a newline) specifies the formatting applied + to each account/balance pair. It may contain any suitable text, with + data fields interpolated like so: + + %[MIN][.MAX](FIELDNAME) + + o MIN pads with spaces to at least this width (optional) + + o MAX truncates at this width (optional) + + o FIELDNAME must be enclosed in parentheses, and can be one of: + + o depth_spacer - a number of spaces equal to the account's depth, or + if MIN is specified, MIN * depth spaces. + + o account - the account's name + + o total - the account's balance/posted total, right justified + + Also, FMT can begin with an optional prefix to control how multi-com- + modity amounts are rendered: + + o %_ - render on multiple lines, bottom-aligned (the default) + + o %^ - render on multiple lines, top-aligned + + o %, - render on one line, comma-separated + + There are some quirks. Eg in one-line mode, %(depth_spacer) has no + effect, instead %(account) has indentation built in. Experimentation + may be needed to get pleasing results. + + Some example formats: + + o %(total) - the account's total + + o %-20.20(account) - the account's name, left justified, padded to 20 + characters and clipped at 20 characters + + o %,%-50(account) %25(total) - account name padded to 50 characters, + total padded to 20 characters, with multiple commodities rendered on + one line + + o %20(total) %2(depth_spacer)%-(account) - the default format for the + single-column balance report + balancesheet balancesheet, bs This command displays a balance sheet, showing historical ending bal- @@ -2252,9 +2439,6 @@ COMMANDS top-level asset or liability account (case insensitive, plurals allowed). - (This report is essentially similar to "hledger balance --historical - assets liabilities", with liabilities sign-flipped.) - Example: $ hledger balancesheet @@ -2276,14 +2460,11 @@ COMMANDS -------------------- 0 - With a reporting interval, multiple columns will be shown, one for each - report period. As with multicolumn balance reports, you can alter the - report mode with --change/--cumulative/--historical. Normally bal- - ancesheet shows historical ending balances, which is what you need for - a balance sheet; note this means it ignores report begin dates (and - -T/--row-total, since summing end balances generally does not make - sense). Instead of absolute values percentages can be displayed with - -%. + This command is a higher-level variant of the balance command, and sup- + ports many of that command's features, such as multi-period reports. + It is similar to hledger balance -H assets liabilities, but with + smarter account detection, and liabilities displayed with their sign + flipped. This command also supports the output destination and output format options The output formats supported are txt, csv, html, and (experi- @@ -2300,9 +2481,6 @@ COMMANDS all accounts under a top-level asset, liability or equity account (case insensitive, plurals allowed). - (This report is essentially similar to "hledger balance --historical - assets liabilities equity", with liabilities and equity sign-flipped.) - Example: $ hledger balancesheetequity @@ -2329,6 +2507,12 @@ COMMANDS -------------------- 0 + This command is a higher-level variant of the balance command, and sup- + ports many of that command's features, such as multi-period reports. + It is similar to hledger balance -H assets liabilities equity, but with + smarter account detection, and liabilities/equity displayed with their + sign flipped. + This command also supports the output destination and output format options The output formats supported are txt, csv, html, and (experi- mental) json. @@ -2344,9 +2528,6 @@ COMMANDS insensitive, plural allowed) which do not have fixed, investment, receivable or A/R in their name. - (This report is essentially similar to "hledger balance --change assets - not:fixed not:investment not:receivable".) - Example: $ hledger cashflow @@ -2363,11 +2544,10 @@ COMMANDS -------------------- $-1 - With a reporting interval, multiple columns will be shown, one for each - report period. Normally cashflow shows changes in assets per period, - though as with multicolumn balance reports you can alter the report - mode with --change/--cumulative/--historical. Instead of absolute val- - ues percentages can be displayed with -%. + This command is a higher-level variant of the balance command, and sup- + ports many of that command's features, such as multi-period reports. + It is similar to hledger balance assets not:fixed not:investment + not:receivable, but with smarter account detection. This command also supports the output destination and output format options The output formats supported are txt, csv, html, and (experi- @@ -2418,13 +2598,11 @@ COMMANDS check. They are more specialised and not desirable for everyone, therefore optional: - o ordereddates - transactions are ordered by date (similar to the old - check-dates command) + o ordereddates - transactions are ordered by date in each file o payees - all payees used by transactions have been declared - o uniqueleafnames - all account leaf names are unique (similar to the - old check-dupes command). + o uniqueleafnames - all account leaf names are unique Custom checks A few more checks are are available as separate add-on commands, in @@ -2652,18 +2830,68 @@ COMMANDS tions that would be added. Or with --catchup, just mark all of the FILEs' transactions as imported, without actually importing any. - The input files are specified as arguments - no need to write -f before - each one. So eg to add new transactions from all CSV files to the main - journal, it's just: hledger import *.csv + Unlike other hledger commands, with import the journal file is an out- + put file, and will be modified, though only by appending (existing data + will not be changed). The input files are specified as arguments, so + to import one or more CSV files to your main journal, you will run + hledger import bank.csv or perhaps hledger import *.csv. - New transactions are detected in the same way as print --new: by assum- - ing transactions are always added to the input files in increasing date - order, and by saving .latest.FILE state files. + Note you can import from any file format, though CSV files are the most + common import source, and these docs focus on that case. - The --dry-run output is in journal format, so you can filter it, eg to - see only uncategorised transactions: + Deduplication + As a convenience import does deduplication while reading transactions. + This does not mean "ignore transactions that look the same", but rather + "ignore transactions that have been seen before". This is intended for + when you are periodically importing foreign data which may contain + already-imported transactions. So eg, if every day you download bank + CSV files containing redundant data, you can safely run hledger import + bank.csv and only new transactions will be imported. (import is idem- + potent.) - $ hledger import --dry ... | hledger -f- print unknown --ignore-assertions + Since the items being read (CSV records, eg) often do not come with + unique identifiers, hledger detects new transactions by date, assuming + that: + + 1. new items always have the newest dates + + 2. item dates do not change across reads + + 3. and items with the same date remain in the same relative order + across reads. + + These are often true of CSV files representing transactions, or true + enough so that it works pretty well in practice. 1 is important, but + violations of 2 and 3 amongst the old transactions won't matter (and if + you import often, the new transactions will be few, so less likely to + be the ones affected). + + hledger remembers the latest date processed in each input file by sav- + ing a hidden ".latest" state file in the same directory. Eg when read- + ing finance/bank.csv, it will look for and update the finance/.lat- + est.bank.csv state file. The format is simple: one or more lines con- + taining the same ISO-format date (YYYY-MM-DD), meaning "I have pro- + cessed transactions up to this date, and this many of them on that + date." Normally you won't see or manipulate these state files yourself. + But if needed, you can delete them to reset the state (making all + transactions "new"), or you can construct them to "catch up" to a cer- + tain date. + + Note deduplication (and updating of state files) can also be done by + print --new, but this is less often used. + + Import testing + With --dry-run, the transactions that will be imported are printed to + the terminal, without updating your journal or state files. The output + is valid journal format, like the print command, so you can re-parse + it. Eg, to see any importable transactions which CSV rules have not + categorised: + + $ hledger import --dry bank.csv | hledger -f- -I print unknown + + or (live updating): + + $ ls bank.csv* | entr bash -c 'echo ====; hledger import --dry bank.csv | hledger -f- -I print unknown' Importing balance assignments Entries added by import will have their posting amounts made explicit @@ -2695,9 +2923,6 @@ COMMANDS level revenue or income or expense account (case insensitive, plurals allowed). - (This report is essentially similar to "hledger balance --change rev- - enues expenses", with revenues sign-flipped.) - Example: $ hledger incomestatement @@ -2721,23 +2946,23 @@ COMMANDS -------------------- 0 - With a reporting interval, multiple columns will be shown, one for each - report period. Normally incomestatement shows revenues/expenses per - period, though as with multicolumn balance reports you can alter the - report mode with --change/--cumulative/--historical. Instead of abso- - lute values percentages can be displayed with -%. + This command is a higher-level variant of the balance command, and sup- + ports many of that command's features, such as multi-period reports. + It is similar to hledger balance '(revenues|income)' expenses, but with + smarter account detection, and revenues/income displayed with their + sign flipped. - This command also supports the output destination and output format - options The output formats supported are txt, csv, html, and (experi- + This command also supports the output destination and output format + options The output formats supported are txt, csv, html, and (experi- mental) json. notes notes List the unique notes that appear in transactions. - This command lists the unique notes that appear in transactions, in - alphabetic order. You can add a query to select a subset of transac- - tions. The note is the part of the transaction description after a | + This command lists the unique notes that appear in transactions, in + alphabetic order. You can add a query to select a subset of transac- + tions. The note is the part of the transaction description after a | character (or if there is no |, the whole description). Example: @@ -2750,14 +2975,14 @@ COMMANDS payees List the unique payee/payer names that appear in transactions. - This command lists unique payee/payer names which have been declared - with payee directives (--declared), used in transaction descriptions + This command lists unique payee/payer names which have been declared + with payee directives (--declared), used in transaction descriptions (--used), or both (the default). - The payee/payer is the part of the transaction description before a | + The payee/payer is the part of the transaction description before a | character (or if there is no |, the whole description). - You can add query arguments to select a subset of transactions. This + You can add query arguments to select a subset of transactions. This implies --used. Example: @@ -2769,10 +2994,10 @@ COMMANDS prices prices - Print market price directives from the journal. With --costs, also - print synthetic market prices based on transaction prices. With + Print market price directives from the journal. With --costs, also + print synthetic market prices based on transaction prices. With --inverted-costs, also print inverse prices based on transaction - prices. Prices (and postings providing prices) can be filtered by a + prices. Prices (and postings providing prices) can be filtered by a query. Price amounts are always displayed with their full precision. print @@ -2782,17 +3007,17 @@ COMMANDS The print command displays full journal entries (transactions) from the journal file, sorted by date (or with --date2, by secondary date). - Amounts are shown mostly normalised to commodity display style, eg the - placement of commodity symbols will be consistent. All of their deci- + Amounts are shown mostly normalised to commodity display style, eg the + placement of commodity symbols will be consistent. All of their deci- mal places are shown, as in the original journal entry (with one alter- ation: in some cases trailing zeroes are added.) Amounts are shown right-aligned within each transaction (but not across all transactions). - Directives and inter-transaction comments are not shown, currently. + Directives and inter-transaction comments are not shown, currently. This means the print command is somewhat lossy, and if you are using it - to reformat your journal you should take care to also copy over the + to reformat your journal you should take care to also copy over the directives and file-level comments. Eg: @@ -2819,7 +3044,7 @@ COMMANDS liabilities:debts $1 assets:bank:checking $-1 - print's output is usually a valid hledger journal, and you can process + print's output is usually a valid hledger journal, and you can process it again with a second hledger command. This can be useful for certain kinds of search, eg: @@ -2829,50 +3054,39 @@ COMMANDS There are some situations where print's output can become unparseable: - o Valuation affects posting amounts but not balance assertion or bal- + o Valuation affects posting amounts but not balance assertion or bal- ance assignment amounts, potentially causing those to fail. o Auto postings can generate postings with too many missing amounts. Normally, the journal entry's explicit or implicit amount style is pre- served. For example, when an amount is omitted in the journal, it will - not appear in the output. Similarly, when a transaction price is + not appear in the output. Similarly, when a transaction price is implied but not written, it will not appear in the output. You can use - the -x/--explicit flag to make all amounts and transaction prices - explicit, which can be useful for troubleshooting or for making your + the -x/--explicit flag to make all amounts and transaction prices + explicit, which can be useful for troubleshooting or for making your journal more readable and robust against data entry errors. -x is also implied by using any of -B,-V,-X,--value. - Note, -x/--explicit will cause postings with a multi-commodity amount - (these can arise when a multi-commodity transaction has an implicit - amount) to be split into multiple single-commodity postings, keeping + Note, -x/--explicit will cause postings with a multi-commodity amount + (these can arise when a multi-commodity transaction has an implicit + amount) to be split into multiple single-commodity postings, keeping the output parseable. - With -B/--cost, amounts with transaction prices are converted to cost + With -B/--cost, amounts with transaction prices are converted to cost using that price. This can be used for troubleshooting. - With -m/--match and a STR argument, print will show at most one trans- - action: the one one whose description is most similar to STR, and is - most recent. STR should contain at least two characters. If there is + With -m/--match and a STR argument, print will show at most one trans- + action: the one one whose description is most similar to STR, and is + most recent. STR should contain at least two characters. If there is no similar-enough match, no transaction will be shown. - With --new, for each FILE being read, hledger reads (and writes) a spe- - cial state file (.latest.FILE in the same directory), containing the - latest transaction date(s) that were seen last time FILE was read. - When this file is found, only transactions with newer dates (and new - transactions on the latest date) are printed. This is useful for - ignoring already-seen entries in import data, such as downloaded CSV - files. Eg: + With --new, hledger prints only transactions it has not seen on a pre- + vious run. This uses the same deduplication system as the import com- + mand. (See import's docs for details.) - $ hledger -f bank1.csv print --new - (shows transactions added since last print --new on this file) - - This assumes that transactions added to FILE always have same or - increasing dates, and that transactions on the same day do not get - reordered. See also the import command. - - This command also supports the output destination and output format - options The output formats supported are txt, csv, and (experimental) + This command also supports the output destination and output format + options The output formats supported are txt, csv, and (experimental) json and sql. Here's an example of print's CSV output: @@ -2891,20 +3105,20 @@ COMMANDS "5","2008/12/31","","*","","pay off","","liabilities:debts","1","$","","1","","" "5","2008/12/31","","*","","pay off","","assets:bank:checking","-1","$","1","","","" - o There is one CSV record per posting, with the parent transaction's + o There is one CSV record per posting, with the parent transaction's fields repeated. o The "txnidx" (transaction index) field shows which postings belong to - the same transaction. (This number might change if transactions are - reordered within the file, files are parsed/included in a different + the same transaction. (This number might change if transactions are + reordered within the file, files are parsed/included in a different order, etc.) - o The amount is separated into "commodity" (the symbol) and "amount" + o The amount is separated into "commodity" (the symbol) and "amount" (numeric quantity) fields. o The numeric amount is repeated in either the "credit" or "debit" col- - umn, for convenience. (Those names are not accurate in the account- - ing sense; it just puts negative amounts under credit and zero or + umn, for convenience. (Those names are not accurate in the account- + ing sense; it just puts negative amounts under credit and zero or greater amounts under debit.) print-unique @@ -2928,14 +3142,14 @@ COMMANDS Show postings and their running total. The register command displays matched postings, across all accounts, in - date order, with their running total or running historical balance. - (See also the aregister command, which shows matched transactions in a + date order, with their running total or running historical balance. + (See also the aregister command, which shows matched transactions in a specific account.) register normally shows line per posting, but note that multi-commodity amounts will occupy multiple lines (one line per commodity). - It is typically used with a query selecting a particular account, to + It is typically used with a query selecting a particular account, to see that account's activity: $ hledger register checking @@ -2946,8 +3160,8 @@ COMMANDS With --date2, it shows and sorts by secondary date instead. - The --historical/-H flag adds the balance from any undisplayed prior - postings to the running total. This is useful when you want to see + The --historical/-H flag adds the balance from any undisplayed prior + postings to the running total. This is useful when you want to see only recent activity, with a historically accurate running balance: $ hledger register checking -b 2008/6 --historical @@ -2957,30 +3171,30 @@ COMMANDS The --depth option limits the amount of sub-account detail displayed. - The --average/-A flag shows the running average posting amount instead + The --average/-A flag shows the running average posting amount instead of the running total (so, the final number displayed is the average for - the whole report period). This flag implies --empty (see below). It - is affected by --historical. It works best when showing just one + the whole report period). This flag implies --empty (see below). It + is affected by --historical. It works best when showing just one account and one commodity. - The --related/-r flag shows the other postings in the transactions of + The --related/-r flag shows the other postings in the transactions of the postings which would normally be shown. - The --invert flag negates all amounts. For example, it can be used on + The --invert flag negates all amounts. For example, it can be used on an income account where amounts are normally displayed as negative num- - bers. It's also useful to show postings on the checking account + bers. It's also useful to show postings on the checking account together with the related account: $ hledger register --related --invert assets:checking - With a reporting interval, register shows summary postings, one per + With a reporting interval, register shows summary postings, one per interval, aggregating the postings to each account: $ hledger register --monthly income 2008/01 income:salary $-1 $-1 2008/06 income:gifts $-1 $-2 - Periods with no activity, and summary postings with a zero amount, are + Periods with no activity, and summary postings with a zero amount, are not shown by default; use the --empty/-E flag to see them: $ hledger register --monthly income -E @@ -2997,7 +3211,7 @@ COMMANDS 2008/11 0 $-2 2008/12 0 $-2 - Often, you'll want to see just one line per interval. The --depth + Often, you'll want to see just one line per interval. The --depth option helps with this, causing subaccounts to be aggregated: $ hledger register --monthly assets --depth 1h @@ -3005,19 +3219,19 @@ COMMANDS 2008/06 assets $-1 0 2008/12 assets $-1 $-1 - Note when using report intervals, if you specify start/end dates these - will be adjusted outward if necessary to contain a whole number of - intervals. This ensures that the first and last intervals are full + Note when using report intervals, if you specify start/end dates these + will be adjusted outward if necessary to contain a whole number of + intervals. This ensures that the first and last intervals are full length and comparable to the others in the report. Custom register output - register uses the full terminal width by default, except on windows. - You can override this by setting the COLUMNS environment variable (not + register uses the full terminal width by default, except on windows. + You can override this by setting the COLUMNS environment variable (not a bash shell variable) or by using the --width/-w option. - The description and account columns normally share the space equally - (about half of (width - 40) each). You can adjust this by adding a - description width as part of --width's argument, comma-separated: + The description and account columns normally share the space equally + (about half of (width - 40) each). You can adjust this by adding a + description width as part of --width's argument, comma-separated: --width W,D . Here's a diagram (won't display correctly in --help): <--------------------------------- width (W) ----------------------------------> @@ -3033,28 +3247,28 @@ COMMANDS $ hledger reg -w 100,40 # set overall width 100, description width 40 $ hledger reg -w $COLUMNS,40 # use terminal width, & description width 40 - This command also supports the output destination and output format - options The output formats supported are txt, csv, and (experimental) + This command also supports the output destination and output format + options The output formats supported are txt, csv, and (experimental) json. register-match register-match Print the one posting whose transaction description is closest to DESC, - in the style of the register command. If there are multiple equally - good matches, it shows the most recent. Query options (options, not - arguments) can be used to restrict the search space. Helps ledger- + in the style of the register command. If there are multiple equally + good matches, it shows the most recent. Query options (options, not + arguments) can be used to restrict the search space. Helps ledger- autosync detect already-seen transactions when importing. rewrite rewrite Print all transactions, rewriting the postings of matched transactions. - For now the only rewrite available is adding new postings, like print + For now the only rewrite available is adding new postings, like print --auto. This is a start at a generic rewriter of transaction entries. It reads - the default journal and prints the transactions, like print, but adds + the default journal and prints the transactions, like print, but adds one or more specified postings to any transactions matching QUERY. The - posting amounts can be fixed, or a multiplier of the existing transac- + posting amounts can be fixed, or a multiplier of the existing transac- tion's first posting amount. Examples: @@ -3070,7 +3284,7 @@ COMMANDS (reserve:grocery) *0.25 ; reserve 25% for grocery (reserve:) *0.25 ; reserve 25% for grocery - Note the single quotes to protect the dollar sign from bash, and the + Note the single quotes to protect the dollar sign from bash, and the two spaces between account and amount. More: @@ -3080,16 +3294,16 @@ COMMANDS $ hledger rewrite -- expenses:gifts --add-posting '(budget:gifts) *-1"' $ hledger rewrite -- ^income --add-posting '(budget:foreign currency) *0.25 JPY; diversify' - Argument for --add-posting option is a usual posting of transaction - with an exception for amount specification. More precisely, you can + Argument for --add-posting option is a usual posting of transaction + with an exception for amount specification. More precisely, you can use '*' (star symbol) before the amount to indicate that that this is a - factor for an amount of original matched posting. If the amount - includes a commodity name, the new posting amount will be in the new - commodity; otherwise, it will be in the matched posting amount's com- + factor for an amount of original matched posting. If the amount + includes a commodity name, the new posting amount will be in the new + commodity; otherwise, it will be in the matched posting amount's com- modity. Re-write rules in a file - During the run this tool will execute so called "Automated Transac- + During the run this tool will execute so called "Automated Transac- tions" found in any journal it process. I.e instead of specifying this operations in command line you can put them in a journal file. @@ -3104,7 +3318,7 @@ COMMANDS budget:gifts *-1 assets:budget *1 - Note that '=' (equality symbol) that is used instead of date in trans- + Note that '=' (equality symbol) that is used instead of date in trans- actions you usually write. It indicates the query by which you want to match the posting to add new ones. @@ -3117,12 +3331,12 @@ COMMANDS --add-posting 'assets:budget *1' \ > rewritten-tidy-output.journal - It is important to understand that relative order of such entries in - journal is important. You can re-use result of previously added post- + It is important to understand that relative order of such entries in + journal is important. You can re-use result of previously added post- ings. Diff output format - To use this tool for batch modification of your journal files you may + To use this tool for batch modification of your journal files you may find useful output in form of unified diff. $ hledger rewrite -- --diff -f examples/sample.journal '^income' --add-posting '(liabilities:tax) *.33' @@ -3146,10 +3360,10 @@ COMMANDS If you'll pass this through patch tool you'll get transactions contain- ing the posting that matches your query be updated. Note that multiple - files might be update according to list of input files specified via + files might be update according to list of input files specified via --file options and include directives inside of these files. - Be careful. Whole transaction being re-formatted in a style of output + Be careful. Whole transaction being re-formatted in a style of output from hledger print. See also: @@ -3157,42 +3371,41 @@ COMMANDS https://github.com/simonmichael/hledger/issues/99 rewrite vs. print --auto - This command predates print --auto, and currently does much the same + This command predates print --auto, and currently does much the same thing, but with these differences: - o with multiple files, rewrite lets rules in any file affect all other - files. print --auto uses standard directive scoping; rules affect + o with multiple files, rewrite lets rules in any file affect all other + files. print --auto uses standard directive scoping; rules affect only child files. - o rewrite's query limits which transactions can be rewritten; all are + o rewrite's query limits which transactions can be rewritten; all are printed. print --auto's query limits which transactions are printed. - o rewrite applies rules specified on command line or in the journal. + o rewrite applies rules specified on command line or in the journal. print --auto applies rules specified in the journal. roi roi - Shows the time-weighted (TWR) and money-weighted (IRR) rate of return + Shows the time-weighted (TWR) and money-weighted (IRR) rate of return on your investments. - This command assumes that you have account(s) that hold nothing but - your investments and whenever you record current appraisal/valuation of - these investments you offset unrealized profit and loss into account(s) - that, again, hold nothing but unrealized profit and loss. - - Any transactions affecting balance of investment account(s) and not - originating from unrealized profit and loss account(s) are assumed to - be your investments or withdrawals. - At a minimum, you need to supply a query (which could be just an - account name) to select your investments with --inv, and another query - to identify your profit and loss transactions with --pnl. + account name) to select your investment(s) with --inv, and another + query to identify your profit and loss transactions with --pnl. - This command will compute and display the internalized rate of return - (IRR) and time-weighted rate of return (TWR) for your investments for - the time period requested. Both rates of return are annualized before + If you do not record changes in the value of your investment manually, + or do not require computation of time-weighted return (TWR), --pnl + could be an empty query (--pnl "" or --pnl STR where STR does not match + any of your accounts). + + This command will compute and display the internalized rate of return + (IRR) and time-weighted rate of return (TWR) for your investments for + the time period requested. Both rates of return are annualized before display, regardless of the length of reporting interval. + Price directives will be taken into account if you supply appropriate + --cost or --value flags (see VALUATION). + Note, in some cases this report can fail, for these reasons: o Error (NotBracketed): No solution for Internal Rate of Return (IRR). @@ -3205,11 +3418,62 @@ COMMANDS Examples: - o Using roi to report unrealised gains: https://github.com/simon- - michael/hledger/blob/master/examples/roi-unrealised.ledger + o Using roi to compute total return of investment in stocks: + https://github.com/simonmichael/hledger/blob/master/examples/roi- + unrealised.ledger - More background: + o Cookbook -> Return on Investment + Semantics of --inv and --pnl + Query supplied to --inv has to match all transactions that are related + to your investment. Transactions not matching --inv will be ignored. + + In these transactions, ROI will conside postings that match --inv to be + "investment postings" and other postings (not matching --inv) will be + sorted into two categories: "cash flow" and "profit and loss", as ROI + needs to know which part of the investment value is your contributions + and which is due to the return on investment. + + o "Cash flow" is depositing or withdrawing money, buying or selling + assets, or otherwise converting between your investment commodity and + any other commodity. Example: + + 2019-01-01 Investing in Snake Oil + assets:cash -$100 + investment:snake oil + + 2020-01-01 Selling my Snake Oil + assets:cash $10 + investment:snake oil = 0 + + o "Profit and loss" is change in the value of your investment: + + 2019-06-01 Snake Oil falls in value + investment:snake oil = $57 + equity:unrealized profit or loss + + All non-investment postings are assumed to be "cash flow", unless they + match --pnl query. Changes in value of your investment due to "profit + and loss" postings will be considered as part of your investment + return. + + Example: if you use --inv snake --pnl equity:unrealized, then postings + in the example below would be classifed as: + + 2019-01-01 Snake Oil #1 + assets:cash -$100 ; cash flow posting + investment:snake oil ; investment posting + + 2019-03-01 Snake Oil #2 + equity:unrealized pnl -$100 ; profit and loss posting + snake oil ; investment posting + + 2019-07-01 Snake Oil #3 + equity:unrealized pnl ; profit and loss posting + cash -$100 ; cash flow posting + snake oil $50 ; investment posting + + IRR and TWR explained "ROI" stands for "return on investment". Traditionally this was com- puted as a difference between current value of investment and its ini- tial value, expressed in percentage of the initial value. @@ -3228,35 +3492,34 @@ COMMANDS ment, you will receive bigger absolute gains (but probably at the same rate of return). IRR is a way to compute rate of return for each period between in-flow or out-flow of money, and then combine them in a - way that gives you an annual rate of return that investment is expected - to generate. + way that gives you a compound annual rate of return that investment is + expected to generate. As mentioned before, in-flows and out-flows would be any cash that you - personally put in or withdraw, and for the "roi" command, these are - transactions that involve account(s) matching --inv argument and NOT - involve account(s) matching --pnl argument. + personally put in or withdraw, and for the "roi" command, these are the + postings that match the query in the--inv argument and NOT match the + query in the--pnl argument. - Presumably, you will also record changes in the value of your invest- - ment, and balance them against "profit and loss" (or "unrealized - gains") account. Note that in order for IRR to compute the precise - effect of your in-flows and out-flows on the rate of return, you will - need to record the value of your investement on or close to the days - when in- or out-flows occur. - - Implementation of IRR in hledger should match the XIRR formula in - Excel. - - Second way to compute rate of return that roi command implements is - called "time-weighted rate of return" or "TWR". Like IRR, it will also - break the history of your investment into periods between in-flows and - out-flows to compute rate of return per each period and then a compound - rate of return. However, internal workings of TWR are quite different. + If you manually record changes in the value of your investment as + transactions that balance them against "profit and loss" (or "unreal- + ized gains") account or use price directives, then in order for IRR to + compute the precise effect of your in-flows and out-flows on the rate + of return, you will need to record the value of your investement on or + close to the days when in- or out-flows occur. In technical terms, IRR uses the same approach as computation of net present value, and tries to find a discount rate that makes net present value of all the cash flows of your investment to add up to zero. This could be hard to wrap your head around, especially if you haven't done - discounted cash flow analysis before. + discounted cash flow analysis before. Implementation of IRR in hledger + should produce results that match the XIRR formula in Excel. + + Second way to compute rate of return that roi command implements is + called "time-weighted rate of return" or "TWR". Like IRR, it will also + break the history of your investment into periods between in-flows, + out-flows and value changes, to compute rate of return per each period + and then a compound rate of return. However, internal workings of TWR + are quite different. TWR represents your investment as an imaginary "unit fund" where in- flows/ out-flows lead to buying or selling "units" of your investment @@ -3268,167 +3531,12 @@ COMMANDS Explanation of TWR * Examples of computing IRR and TWR and discussion of the limitations of both metrics - More examples: - - Lets say that we found an investment in Snake Oil that is proising to - give us 10% annually: - - 2019-01-01 Investing in Snake Oil - assets:cash -$100 - investment:snake oil - - 2019-12-24 Recording the growth of Snake Oil - investment:snake oil = $110 - equity:unrealized gains - - For now, basic computation of the rate of return, as well as IRR and - TWR, gives us the expected 10%: - - $ hledger roi -Y --inv investment --pnl "unrealized" - +---++------------+------------++---------------+----------+-------------+-----++--------+--------+ - | || Begin | End || Value (begin) | Cashflow | Value (end) | PnL || IRR | TWR | - +===++============+============++===============+==========+=============+=====++========+========+ - | 1 || 2019-01-01 | 2019-12-31 || 0 | 100 | 110 | 10 || 10.00% | 10.00% | - +---++------------+------------++---------------+----------+-------------+-----++--------+--------+ - - However, lets say that shorty after investing in the Snake Oil we - started to have second thoughs, so we prompty withdrew $90, leaving - only $10 in. Before Christmas, though, we started to get the "fear of - mission out", so we put the $90 back in. So for most of the year, our - investment was just $10 dollars, and it gave us just $1 in growth: - - 2019-01-01 Investing in Snake Oil - assets:cash -$100 - investment:snake oil - - 2019-01-02 Buyers remorse - assets:cash $90 - investment:snake oil - - 2019-12-30 Fear of missing out - assets:cash -$90 - investment:snake oil - - 2019-12-31 Recording the growth of Snake Oil - investment:snake oil = $101 - equity:unrealized gains - - Now IRR and TWR are drastically different: - - $ hledger roi -Y --inv investment --pnl "unrealized" - +---++------------+------------++---------------+----------+-------------+-----++-------+-------+ - | || Begin | End || Value (begin) | Cashflow | Value (end) | PnL || IRR | TWR | - +===++============+============++===============+==========+=============+=====++=======+=======+ - | 1 || 2019-01-01 | 2019-12-31 || 0 | 100 | 101 | 1 || 9.32% | 1.00% | - +---++------------+------------++---------------+----------+-------------+-----++-------+-------+ - - Here, IRR tells us that we made close to 10% on the $10 dollars that we - had in the account most of the time. And TWR is ... just 1%? Why? - - Based on the transactions in our journal, TWR "think" that we are buy- - ing back $90 worst of Snake Oil at the same price that it had at the - beginning of they year, and then after that our $100 investment gets $1 - increase in value, or 1% of $100. Let's take a closer look at what is - happening here by asking for quarterly reports instead of annual: - - $ hledger roi -Q --inv investment --pnl "unrealized" - +---++------------+------------++---------------+----------+-------------+-----++--------+-------+ - | || Begin | End || Value (begin) | Cashflow | Value (end) | PnL || IRR | TWR | - +===++============+============++===============+==========+=============+=====++========+=======+ - | 1 || 2019-01-01 | 2019-03-31 || 0 | 10 | 10 | 0 || 0.00% | 0.00% | - | 2 || 2019-04-01 | 2019-06-30 || 10 | 0 | 10 | 0 || 0.00% | 0.00% | - | 3 || 2019-07-01 | 2019-09-30 || 10 | 0 | 10 | 0 || 0.00% | 0.00% | - | 4 || 2019-10-01 | 2019-12-31 || 10 | 90 | 101 | 1 || 37.80% | 4.03% | - +---++------------+------------++---------------+----------+-------------+-----++--------+-------+ - - Now both IRR and TWR are thrown off by the fact that all of the growth - for our investment happens in Q4 2019. This happes because IRR compu- - tation is still yielding 9.32% and TWR is still 1%, but this time these - are rates for three month period instead of twelve, so in order to get - an annual rate they should be multiplied by four! - - Let's try to keep a better record of how Snake Oil grew in value: - - 2019-01-01 Investing in Snake Oil - assets:cash -$100 - investment:snake oil - - 2019-01-02 Buyers remorse - assets:cash $90 - investment:snake oil - - 2019-02-28 Recording the growth of Snake Oil - investment:snake oil - equity:unrealized gains -$0.25 - - 2019-06-30 Recording the growth of Snake Oil - investment:snake oil - equity:unrealized gains -$0.25 - - 2019-09-30 Recording the growth of Snake Oil - investment:snake oil - equity:unrealized gains -$0.25 - - 2019-12-30 Fear of missing out - assets:cash -$90 - investment:snake oil - - 2019-12-31 Recording the growth of Snake Oil - investment:snake oil - equity:unrealized gains -$0.25 - - Would our quartery report look better now? Almost: - - $ hledger roi -Q --inv investment --pnl "unrealized" - +---++------------+------------++---------------+----------+-------------+------++--------+--------+ - | || Begin | End || Value (begin) | Cashflow | Value (end) | PnL || IRR | TWR | - +===++============+============++===============+==========+=============+======++========+========+ - | 1 || 2019-01-01 | 2019-03-31 || 0 | 10 | 10.25 | 0.25 || 9.53% | 10.53% | - | 2 || 2019-04-01 | 2019-06-30 || 10.25 | 0 | 10.50 | 0.25 || 10.15% | 10.15% | - | 3 || 2019-07-01 | 2019-09-30 || 10.50 | 0 | 10.75 | 0.25 || 9.79% | 9.78% | - | 4 || 2019-10-01 | 2019-12-31 || 10.75 | 90 | 101.00 | 0.25 || 8.05% | 1.00% | - +---++------------+------------++---------------+----------+-------------+------++--------+--------+ - - Something is still wrong with TWR computation for Q4, and if you have - been paying attention you know what it is already: big $90 buy-back is - recorded prior to the only transaction that captures the change of - value of Snake Oil that happened in this time period. Lets combine - transactions from 30th and 31st of Dec into one: - - 2019-12-30 Fear of missing out and growth of Snake Oil - assets:cash -$90 - investment:snake oil - equity:unrealized gains -$0.25 - - Now growth of investment properly affects its price at the time of buy- - back: - - $ hledger roi -Q --inv investment --pnl "unrealized" - +---++------------+------------++---------------+----------+-------------+------++--------+--------+ - | || Begin | End || Value (begin) | Cashflow | Value (end) | PnL || IRR | TWR | - +===++============+============++===============+==========+=============+======++========+========+ - | 1 || 2019-01-01 | 2019-03-31 || 0 | 10 | 10.25 | 0.25 || 9.53% | 10.53% | - | 2 || 2019-04-01 | 2019-06-30 || 10.25 | 0 | 10.50 | 0.25 || 10.15% | 10.15% | - | 3 || 2019-07-01 | 2019-09-30 || 10.50 | 0 | 10.75 | 0.25 || 9.79% | 9.78% | - | 4 || 2019-10-01 | 2019-12-31 || 10.75 | 90 | 101.00 | 0.25 || 8.05% | 9.57% | - +---++------------+------------++---------------+----------+-------------+------++--------+--------+ - - And for annual report, TWR now reports the exact profitability of our - investment: - - $ hledger roi -Y --inv investment --pnl "unrealized" - +---++------------+------------++---------------+----------+-------------+------++-------+--------+ - | || Begin | End || Value (begin) | Cashflow | Value (end) | PnL || IRR | TWR | - +===++============+============++===============+==========+=============+======++=======+========+ - | 1 || 2019-01-01 | 2019-12-31 || 0 | 100 | 101.00 | 1.00 || 9.32% | 10.00% | - +---++------------+------------++---------------+----------+-------------+------++-------+--------+ - stats stats Show some journal statistics. - The stats command displays summary information for the whole journal, - or a matched part of it. With a reporting interval, it shows a report + The stats command displays summary information for the whole journal, + or a matched part of it. With a reporting interval, it shows a report for each report period. Example: @@ -3446,35 +3554,35 @@ COMMANDS Commodities : 1 ($) Market prices : 12 ($) - This command also supports output destination and output format selec- + This command also supports output destination and output format selec- tion. tags tags - List the unique tag names used in the journal. With a TAGREGEX argu- + List the unique tag names used in the journal. With a TAGREGEX argu- ment, only tag names matching the regular expression (case insensitive) - are shown. With QUERY arguments, only transactions matching the query + are shown. With QUERY arguments, only transactions matching the query are considered. With the --values flag, the tags' unique values are listed instead. - With --parsed flag, all tags or values are shown in the order they are + With --parsed flag, all tags or values are shown in the order they are parsed from the input data, including duplicates. - With -E/--empty, any blank/empty values will also be shown, otherwise + With -E/--empty, any blank/empty values will also be shown, otherwise they are omitted. test test Run built-in unit tests. - This command runs the unit tests built in to hledger and hledger-lib, - printing the results on stdout. If any test fails, the exit code will + This command runs the unit tests built in to hledger and hledger-lib, + printing the results on stdout. If any test fails, the exit code will be non-zero. - This is mainly used by hledger developers, but you can also use it to - sanity-check the installed hledger executable on your platform. All - tests are expected to pass - if you ever see a failure, please report + This is mainly used by hledger developers, but you can also use it to + sanity-check the installed hledger executable on your platform. All + tests are expected to pass - if you ever see a failure, please report as a bug! This command also accepts tasty test runner options, written after a -- @@ -3483,7 +3591,7 @@ COMMANDS $ hledger test -- -pData.Amount --color=never - For help on these, see https://github.com/feuerbach/tasty#options (-- + For help on these, see https://github.com/feuerbach/tasty#options (-- --help currently doesn't show them). About add-on commands @@ -3491,16 +3599,16 @@ COMMANDS o whose name starts with hledger- - o whose name ends with a recognised file extension: .bat,.com,.exe, + o whose name ends with a recognised file extension: .bat,.com,.exe, .hs,.lhs,.pl,.py,.rb,.rkt,.sh or none o and (on unix, mac) which are executable by the current user. - Add-ons are a relatively easy way to add local features or experiment - with new ideas. They can be written in any language, but haskell - scripts have a big advantage: they can use the same hledger library - functions that built-in commands use for command-line options, parsing - and reporting. Some experimental/example add-on scripts can be found + Add-ons are a relatively easy way to add local features or experiment + with new ideas. They can be written in any language, but haskell + scripts have a big advantage: they can use the same hledger library + functions that built-in commands use for command-line options, parsing + and reporting. Some experimental/example add-on scripts can be found in the hledger repo's bin/ directory. Note in a hledger command line, add-on command flags must have a double @@ -3524,17 +3632,17 @@ COMMANDS JOURNAL FORMAT hledger's default file format, representing a General Journal. - hledger's usual data source is a plain text file containing journal - entries in hledger journal format. This file represents a standard - accounting general journal. I use file names ending in .journal, but + hledger's usual data source is a plain text file containing journal + entries in hledger journal format. This file represents a standard + accounting general journal. I use file names ending in .journal, but that's not required. The journal file contains a number of transaction entries, each describing a transfer of money (or any commodity) between two or more named accounts, in a simple format readable by both hledger and humans. - hledger's journal format is a compatible subset, mostly, of ledger's - journal format, so hledger can work with compatible ledger journal - files as well. It's safe, and encouraged, to run both hledger and + hledger's journal format is a compatible subset, mostly, of ledger's + journal format, so hledger can work with compatible ledger journal + files as well. It's safe, and encouraged, to run both hledger and ledger on the same journal file, eg to validate the results you're get- ting. @@ -3542,25 +3650,25 @@ JOURNAL FORMAT the add or web or import commands to create and update it. Many users, though, edit the journal file with a text editor, and track - changes with a version control system such as git. Editor addons such - as ledger-mode or hledger-mode for Emacs, vim-ledger for Vim, and + changes with a version control system such as git. Editor addons such + as ledger-mode or hledger-mode for Emacs, vim-ledger for Vim, and hledger-vscode for Visual Studio Code, make this easier, adding colour, formatting, tab completion, and useful commands. See Editor configura- tion at hledger.org for the full list. - Here's a description of each part of the file format (and hledger's - data model). These are mostly in the order you'll use them, but in - some cases related concepts have been grouped together for easy refer- - ence, or linked before they are introduced, so feel free to skip over + Here's a description of each part of the file format (and hledger's + data model). These are mostly in the order you'll use them, but in + some cases related concepts have been grouped together for easy refer- + ence, or linked before they are introduced, so feel free to skip over anything that looks unnecessary right now. Transactions - Transactions are the main unit of information in a journal file. They - represent events, typically a movement of some quantity of commodities + Transactions are the main unit of information in a journal file. They + represent events, typically a movement of some quantity of commodities between two or more named accounts. - Each transaction is recorded as a journal entry, beginning with a sim- - ple date in column 0. This can be followed by any of the following + Each transaction is recorded as a journal entry, beginning with a sim- + ple date in column 0. This can be followed by any of the following optional fields, separated by spaces: o a status character (empty, !, or *) @@ -3569,11 +3677,11 @@ JOURNAL FORMAT o a description (any remaining text until end of line or a semicolon) - o a comment (any remaining text following a semicolon until end of + o a comment (any remaining text following a semicolon until end of line, and any following indented lines beginning with a semicolon) o 0 or more indented posting lines, describing what was transferred and - the accounts involved (indented comment lines are also allowed, but + the accounts involved (indented comment lines are also allowed, but not blank lines or non-indented lines). Here's a simple journal file containing one transaction: @@ -3584,35 +3692,35 @@ JOURNAL FORMAT Dates Simple dates - Dates in the journal file use simple dates format: YYYY-MM-DD or + Dates in the journal file use simple dates format: YYYY-MM-DD or YYYY/MM/DD or YYYY.MM.DD, with leading zeros optional. The year may be - omitted, in which case it will be inferred from the context: the cur- - rent transaction, the default year set with a default year directive, - or the current date when the command is run. Some examples: + omitted, in which case it will be inferred from the context: the cur- + rent transaction, the default year set with a default year directive, + or the current date when the command is run. Some examples: 2010-01-31, 2010/01/31, 2010.1.31, 1/31. - (The UI also accepts simple dates, as well as the more flexible smart + (The UI also accepts simple dates, as well as the more flexible smart dates documented in the hledger manual.) Secondary dates - Real-life transactions sometimes involve more than one date - eg the + Real-life transactions sometimes involve more than one date - eg the date you write a cheque, and the date it clears in your bank. When you - want to model this, for more accurate daily balances, you can specify + want to model this, for more accurate daily balances, you can specify individual posting dates. - Or, you can use the older secondary date feature (Ledger calls it aux- - iliary date or effective date). Note: we support this for compatibil- - ity, but I usually recommend avoiding this feature; posting dates are + Or, you can use the older secondary date feature (Ledger calls it aux- + iliary date or effective date). Note: we support this for compatibil- + ity, but I usually recommend avoiding this feature; posting dates are almost always clearer and simpler. A secondary date is written after the primary date, following an equals - sign. If the year is omitted, the primary date's year is assumed. - When running reports, the primary (left) date is used by default, but - with the --date2 flag (or --aux-date or --effective), the secondary + sign. If the year is omitted, the primary date's year is assumed. + When running reports, the primary (left) date is used by default, but + with the --date2 flag (or --aux-date or --effective), the secondary (right) date will be used instead. - The meaning of secondary dates is up to you, but it's best to follow a - consistent rule. Eg "primary = the bank's clearing date, secondary = + The meaning of secondary dates is up to you, but it's best to follow a + consistent rule. Eg "primary = the bank's clearing date, secondary = date the transaction was initiated, if different", as shown here: 2010/2/23=2/19 movie ticket @@ -3626,11 +3734,11 @@ JOURNAL FORMAT 2010-02-19 movie ticket assets:checking $-10 $-10 Posting dates - You can give individual postings a different date from their parent - transaction, by adding a posting comment containing a tag (see below) + You can give individual postings a different date from their parent + transaction, by adding a posting comment containing a tag (see below) like date:DATE. This is probably the best way to control posting dates - precisely. Eg in this example the expense should appear in May - reports, and the deduction from checking should be reported on 6/1 for + precisely. Eg in this example the expense should appear in May + reports, and the deduction from checking should be reported on 6/1 for easy bank reconciliation: 2015/5/30 @@ -3643,22 +3751,22 @@ JOURNAL FORMAT $ hledger -f t.j register checking 2015-06-01 assets:checking $-10 $-10 - DATE should be a simple date; if the year is not specified it will use - the year of the transaction's date. You can set the secondary date - similarly, with date2:DATE2. The date: or date2: tags must have a - valid simple date value if they are present, eg a date: tag with no + DATE should be a simple date; if the year is not specified it will use + the year of the transaction's date. You can set the secondary date + similarly, with date2:DATE2. The date: or date2: tags must have a + valid simple date value if they are present, eg a date: tag with no value is not allowed. Ledger's earlier, more compact bracketed date syntax is also supported: - [DATE], [DATE=DATE2] or [=DATE2]. hledger will attempt to parse any + [DATE], [DATE=DATE2] or [=DATE2]. hledger will attempt to parse any square-bracketed sequence of the 0123456789/-.= characters in this way. - With this syntax, DATE infers its year from the transaction and DATE2 + With this syntax, DATE infers its year from the transaction and DATE2 infers its year from DATE. Status - Transactions, or individual postings within a transaction, can have a - status mark, which is a single character before the transaction - description or posting account name, separated from it by a space, + Transactions, or individual postings within a transaction, can have a + status mark, which is a single character before the transaction + description or posting account name, separated from it by a space, indicating one of three statuses: @@ -3668,23 +3776,23 @@ JOURNAL FORMAT ! pending * cleared - When reporting, you can filter by status with the -U/--unmarked, - -P/--pending, and -C/--cleared flags; or the status:, status:!, and + When reporting, you can filter by status with the -U/--unmarked, + -P/--pending, and -C/--cleared flags; or the status:, status:!, and status:* queries; or the U, P, C keys in hledger-ui. - Note, in Ledger and in older versions of hledger, the "unmarked" state - is called "uncleared". As of hledger 1.3 we have renamed it to + Note, in Ledger and in older versions of hledger, the "unmarked" state + is called "uncleared". As of hledger 1.3 we have renamed it to unmarked for clarity. - To replicate Ledger and old hledger's behaviour of also matching pend- + To replicate Ledger and old hledger's behaviour of also matching pend- ing, combine -U and -P. - Status marks are optional, but can be helpful eg for reconciling with + Status marks are optional, but can be helpful eg for reconciling with real-world accounts. Some editor modes provide highlighting and short- - cuts for working with status. Eg in Emacs ledger-mode, you can toggle + cuts for working with status. Eg in Emacs ledger-mode, you can toggle transaction status with C-c C-e, or posting status with C-c C-c. - What "uncleared", "pending", and "cleared" actually mean is up to you. + What "uncleared", "pending", and "cleared" actually mean is up to you. Here's one suggestion: @@ -3696,35 +3804,35 @@ JOURNAL FORMAT cleared complete, reconciled as far as possible, and considered cor- rect - With this scheme, you would use -PC to see the current balance at your - bank, -U to see things which will probably hit your bank soon (like + With this scheme, you would use -PC to see the current balance at your + bank, -U to see things which will probably hit your bank soon (like uncashed checks), and no flags to see the most up-to-date state of your finances. Description - A transaction's description is the rest of the line following the date - and status mark (or until a comment begins). Sometimes called the + A transaction's description is the rest of the line following the date + and status mark (or until a comment begins). Sometimes called the "narration" in traditional bookkeeping, it can be used for whatever you - wish, or left blank. Transaction descriptions can be queried, unlike + wish, or left blank. Transaction descriptions can be queried, unlike comments. Payee and note You can optionally include a | (pipe) character in descriptions to sub- divide the description into separate fields for payee/payer name on the - left (up to the first |) and an additional note field on the right - (after the first |). This may be worthwhile if you need to do more + left (up to the first |) and an additional note field on the right + (after the first |). This may be worthwhile if you need to do more precise querying and pivoting by payee or by note. Comments Lines in the journal beginning with a semicolon (;) or hash (#) or star - (*) are comments, and will be ignored. (Star comments cause org-mode - nodes to be ignored, allowing emacs users to fold and navigate their + (*) are comments, and will be ignored. (Star comments cause org-mode + nodes to be ignored, allowing emacs users to fold and navigate their journals with org-mode or orgstruct-mode.) - You can attach comments to a transaction by writing them after the - description and/or indented on the following lines (before the post- - ings). Similarly, you can attach comments to an individual posting by - writing them after the amount and/or indented on the following lines. + You can attach comments to a transaction by writing them after the + description and/or indented on the following lines (before the post- + ings). Similarly, you can attach comments to an individual posting by + writing them after the amount and/or indented on the following lines. Transaction and posting comments must begin with a semicolon (;). Some examples: @@ -3747,24 +3855,24 @@ JOURNAL FORMAT ; another comment line for posting 2 ; a file comment (because not indented) - You can also comment larger regions of a file using comment and end + You can also comment larger regions of a file using comment and end comment directives. Tags - Tags are a way to add extra labels or labelled data to postings and + Tags are a way to add extra labels or labelled data to postings and transactions, which you can then search or pivot on. - A simple tag is a word (which may contain hyphens) followed by a full + A simple tag is a word (which may contain hyphens) followed by a full colon, written inside a transaction or posting comment line: 2017/1/16 bought groceries ; sometag: - Tags can have a value, which is the text after the colon, up to the + Tags can have a value, which is the text after the colon, up to the next comma or end of line, with leading/trailing whitespace removed: expenses:food $10 ; a-posting-tag: the tag value - Note this means hledger's tag values can not contain commas or new- + Note this means hledger's tag values can not contain commas or new- lines. Ending at commas means you can write multiple short tags on one line, comma separated: @@ -3778,57 +3886,57 @@ JOURNAL FORMAT o "tag2" is another tag, whose value is "some value ..." - Tags in a transaction comment affect the transaction and all of its - postings, while tags in a posting comment affect only that posting. - For example, the following transaction has three tags (A, TAG2, third- + Tags in a transaction comment affect the transaction and all of its + postings, while tags in a posting comment affect only that posting. + For example, the following transaction has three tags (A, TAG2, third- tag) and the posting has four (those plus posting-tag): 1/1 a transaction ; A:, TAG2: ; third-tag: a third transaction tag, <- with a value (a) $1 ; posting-tag: - Tags are like Ledger's metadata feature, except hledger's tag values + Tags are like Ledger's metadata feature, except hledger's tag values are simple strings. Postings - A posting is an addition of some amount to, or removal of some amount - from, an account. Each posting line begins with at least one space or + A posting is an addition of some amount to, or removal of some amount + from, an account. Each posting line begins with at least one space or tab (2 or 4 spaces is common), followed by: o (optional) a status character (empty, !, or *), followed by a space - o (required) an account name (any text, optionally containing single + o (required) an account name (any text, optionally containing single spaces, until end of line or a double space) o (optional) two or more spaces or tabs followed by an amount. - Positive amounts are being added to the account, negative amounts are + Positive amounts are being added to the account, negative amounts are being removed. The amounts within a transaction must always sum up to zero. As a con- - venience, one amount may be left blank; it will be inferred so as to + venience, one amount may be left blank; it will be inferred so as to balance the transaction. - Be sure to note the unusual two-space delimiter between account name - and amount. This makes it easy to write account names containing spa- - ces. But if you accidentally leave only one space (or tab) before the + Be sure to note the unusual two-space delimiter between account name + and amount. This makes it easy to write account names containing spa- + ces. But if you accidentally leave only one space (or tab) before the amount, the amount will be considered part of the account name. Virtual postings A posting with a parenthesised account name is called a virtual posting - or unbalanced posting, which means it is exempt from the usual rule + or unbalanced posting, which means it is exempt from the usual rule that a transaction's postings must balance add up to zero. - This is not part of double entry accounting, so you might choose to - avoid this feature. Or you can use it sparingly for certain special - cases where it can be convenient. Eg, you could set opening balances + This is not part of double entry accounting, so you might choose to + avoid this feature. Or you can use it sparingly for certain special + cases where it can be convenient. Eg, you could set opening balances without using a balancing equity account: 1/1 opening balances (assets:checking) $1000 (assets:savings) $2000 - A posting with a bracketed account name is called a balanced virtual + A posting with a bracketed account name is called a balanced virtual posting. The balanced virtual postings in a transaction must add up to zero (separately from other postings). Eg: @@ -3840,34 +3948,34 @@ JOURNAL FORMAT [assets:checking:available] $10 ; <- (something:else) $5 ; <- not required to balance - Ordinary non-parenthesised, non-bracketed postings are called real - postings. You can exclude virtual postings from reports with the + Ordinary non-parenthesised, non-bracketed postings are called real + postings. You can exclude virtual postings from reports with the -R/--real flag or real:1 query. Account names - Account names typically have several parts separated by a full colon, - from which hledger derives a hierarchical chart of accounts. They can - be anything you like, but in finance there are traditionally five top- + Account names typically have several parts separated by a full colon, + from which hledger derives a hierarchical chart of accounts. They can + be anything you like, but in finance there are traditionally five top- level accounts: assets, liabilities, revenue, expenses, and equity. - Account names may contain single spaces, eg: assets:accounts receiv- - able. Because of this, they must always be followed by two or more + Account names may contain single spaces, eg: assets:accounts receiv- + able. Because of this, they must always be followed by two or more spaces (or newline). Account names can be aliased. Amounts - After the account name, there is usually an amount. (Important: + After the account name, there is usually an amount. (Important: between account name and amount, there must be two or more spaces.) - hledger's amount format is flexible, supporting several international - formats. Here are some examples. Amounts have a number (the "quan- + hledger's amount format is flexible, supporting several international + formats. Here are some examples. Amounts have a number (the "quan- tity"): 1 - ..and usually a currency or commodity name (the "commodity"). This is - a symbol, word, or phrase, to the left or right of the quantity, with + ..and usually a currency or commodity name (the "commodity"). This is + a symbol, word, or phrase, to the left or right of the quantity, with or without a separating space: $1 @@ -3879,13 +3987,13 @@ JOURNAL FORMAT 3 "no. 42 green apples" Amounts can be preceded by a minus sign (or a plus sign, though plus is - the default), The sign can be written before or after a left-side com- + the default), The sign can be written before or after a left-side com- modity symbol: -$1 $-1 - One or more spaces between the sign and the number are acceptable when + One or more spaces between the sign and the number are acceptable when parsing (but they won't be displayed in output): + $1 @@ -3902,8 +4010,8 @@ JOURNAL FORMAT 1.23 1,23456780000009 - In the integer part of the quantity (left of the decimal mark), groups - of digits can optionally be separated by a "digit group mark" - a + In the integer part of the quantity (left of the decimal mark), groups + of digits can optionally be separated by a "digit group mark" - a space, comma, or period (different from the decimal mark): $1,000,000.00 @@ -3917,11 +4025,11 @@ JOURNAL FORMAT 1,000 1.000 - If you don't tell it otherwise, hledger will assume both of the above + If you don't tell it otherwise, hledger will assume both of the above are decimal marks, parsing both numbers as 1. To prevent confusion and - undetected typos, especially if your data contains digit group marks, - we recommend you explicitly declare the decimal mark (and optionally a - digit group mark), for each commodity, using commodity directives + undetected typos, especially if your data contains digit group marks, + we recommend you explicitly declare the decimal mark (and optionally a + digit group mark), for each commodity, using commodity directives (described below): # number formats for $, EUR, INR and the no-symbol commodity: @@ -3930,55 +4038,55 @@ JOURNAL FORMAT commodity INR 9,99,99,999.00 commodity 1 000 000.9455 - Note, commodity directives declare both the number format for parsing - input, and the display style for showing output. For the former, they - are position-sensitive, affecting only following amounts, so commodity - directives should be at the top of your journal file. This is dis- + Note, commodity directives declare both the number format for parsing + input, and the display style for showing output. For the former, they + are position-sensitive, affecting only following amounts, so commodity + directives should be at the top of your journal file. This is dis- cussed more on #793. Commodity display style For the amounts in each commodity, hledger chooses a consistent display - style to use in most reports. (Except for price amounts, which are - always displayed as written). The display style is inferred as fol- + style to use in most reports. (Except for price amounts, which are + always displayed as written). The display style is inferred as fol- lows. - First, if a default commodity is declared with D, this commodity and + First, if a default commodity is declared with D, this commodity and its style is applied to any no-symbol amounts in the journal. - Then each commodity's style is inferred from one of the following, in + Then each commodity's style is inferred from one of the following, in order of preference: - o The commodity directive for that commodity (including the no-symbol + o The commodity directive for that commodity (including the no-symbol commodity), if any. - o The amounts in that commodity seen in the journal's transactions. + o The amounts in that commodity seen in the journal's transactions. (Posting amounts only; prices and periodic or auto rules are ignored, currently.) - o The built-in fallback style, which looks like this: $1000.00. (Sym- + o The built-in fallback style, which looks like this: $1000.00. (Sym- bol on the left, period decimal mark, two decimal places.) A style is inferred from journal amounts as follows: - o Use the general style (decimal mark, symbol placement) of the first + o Use the general style (decimal mark, symbol placement) of the first amount - o Use the first-seen digit group style (digit group mark, digit group + o Use the first-seen digit group style (digit group mark, digit group sizes), if any o Use the maximum number of decimal places of all. - Transaction price amounts don't affect the commodity display style - directly, but occasionally they can do so indirectly (eg when a post- - ing's amount is inferred using a transaction price). If you find this + Transaction price amounts don't affect the commodity display style + directly, but occasionally they can do so indirectly (eg when a post- + ing's amount is inferred using a transaction price). If you find this causing problems, use a commodity directive to fix the display style. - To summarise: each commodity's amounts will be normalised to (a) the - style declared by a commodity directive, or (b) the style of the first - posting amount in the journal, with the first-seen digit group style - and the maximum-seen number of decimal places. So if your reports are - showing amounts in a way you don't like, eg with too many decimal + To summarise: each commodity's amounts will be normalised to (a) the + style declared by a commodity directive, or (b) the style of the first + posting amount in the journal, with the first-seen digit group style + and the maximum-seen number of decimal places. So if your reports are + showing amounts in a way you don't like, eg with too many decimal places, use a commodity directive. Some examples: # declare euro, dollar, bitcoin and no-symbol commodities and set their @@ -3990,17 +4098,17 @@ JOURNAL FORMAT Rounding Amounts are stored internally as decimal numbers with up to 255 decimal - places, and displayed with the number of decimal places specified by - the commodity display style. Note, hledger uses banker's rounding: it - rounds to the nearest even number, eg 0.5 displayed with zero decimal - places is "0"). (Guaranteed since hledger 1.17.1; in older versions + places, and displayed with the number of decimal places specified by + the commodity display style. Note, hledger uses banker's rounding: it + rounds to the nearest even number, eg 0.5 displayed with zero decimal + places is "0"). (Guaranteed since hledger 1.17.1; in older versions this could vary if hledger was built with Decimal < 0.5.1.) Transaction prices Within a transaction, you can note an amount's price in another commod- - ity. This can be used to document the cost (in a purchase) or selling - price (in a sale). For example, transaction prices are useful to - record purchases of a foreign currency. Note transaction prices are + ity. This can be used to document the cost (in a purchase) or selling + price (in a sale). For example, transaction prices are useful to + record purchases of a foreign currency. Note transaction prices are fixed at the time of the transaction, and do not change over time. See also market prices, which represent prevailing exchange rates on a cer- tain date. @@ -4026,14 +4134,14 @@ JOURNAL FORMAT assets:euros EUR100 ; one hundred euros purchased assets:dollars $-135 ; for $135 - 4. Like 1, but the @ is parenthesised, i.e. (@); this is for compati- - bility with Ledger journals (Virtual posting costs), and is equiva- + 4. Like 1, but the @ is parenthesised, i.e. (@); this is for compati- + bility with Ledger journals (Virtual posting costs), and is equiva- lent to 1 in hledger. 5. Like 2, but as in 4 the @@ is parenthesised, i.e. (@@); in hledger, this is equivalent to 2. - Use the -B/--cost flag to convert amounts to their transaction price's + Use the -B/--cost flag to convert amounts to their transaction price's commodity, if any. (mnemonic: "B" is from "cost Basis", as in Ledger). Eg here is how -B affects the balance report for the example above: @@ -4044,8 +4152,8 @@ JOURNAL FORMAT $-135 assets:dollars $135 assets:euros # <- the euros' cost - Note -B is sensitive to the order of postings when a transaction price - is inferred: the inferred price will be in the commodity of the last + Note -B is sensitive to the order of postings when a transaction price + is inferred: the inferred price will be in the commodity of the last amount. So if example 3's postings are reversed, while the transaction is equivalent, -B shows something different: @@ -4058,18 +4166,18 @@ JOURNAL FORMAT EUR100 assets:euros Lot prices, lot dates - Ledger allows another kind of price, lot price (four variants: {UNIT- + Ledger allows another kind of price, lot price (four variants: {UNIT- PRICE}, {{TOTALPRICE}}, {=FIXEDUNITPRICE}, {{=FIXEDTOTALPRICE}}), and/or a lot date ([DATE]) to be specified. These are normally used to - select a lot when selling investments. hledger will parse these, for - compatibility with Ledger journals, but currently ignores them. A - transaction price, lot price and/or lot date may appear in any order, + select a lot when selling investments. hledger will parse these, for + compatibility with Ledger journals, but currently ignores them. A + transaction price, lot price and/or lot date may appear in any order, after the posting amount and before the balance assertion if any. Balance assertions - hledger supports Ledger-style balance assertions in journal files. - These look like, for example, = EXPECTEDBALANCE following a posting's - amount. Eg here we assert the expected dollar balance in accounts a + hledger supports Ledger-style balance assertions in journal files. + These look like, for example, = EXPECTEDBALANCE following a posting's + amount. Eg here we assert the expected dollar balance in accounts a and b after each posting: 2013/1/1 @@ -4081,32 +4189,32 @@ JOURNAL FORMAT b $-1 =$-2 After reading a journal file, hledger will check all balance assertions - and report an error if any of them fail. Balance assertions can pro- - tect you from, eg, inadvertently disrupting reconciled balances while - cleaning up old entries. You can disable them temporarily with the + and report an error if any of them fail. Balance assertions can pro- + tect you from, eg, inadvertently disrupting reconciled balances while + cleaning up old entries. You can disable them temporarily with the -I/--ignore-assertions flag, which can be useful for troubleshooting or - for reading Ledger files. (Note: this flag currently does not disable + for reading Ledger files. (Note: this flag currently does not disable balance assignments, below). Assertions and ordering - hledger sorts an account's postings and assertions first by date and - then (for postings on the same day) by parse order. Note this is dif- + hledger sorts an account's postings and assertions first by date and + then (for postings on the same day) by parse order. Note this is dif- ferent from Ledger, which sorts assertions only by parse order. (Also, - Ledger assertions do not see the accumulated effect of repeated post- + Ledger assertions do not see the accumulated effect of repeated post- ings to the same account within a transaction.) So, hledger balance assertions keep working if you reorder differently- - dated transactions within the journal. But if you reorder same-dated - transactions or postings, assertions might break and require updating. + dated transactions within the journal. But if you reorder same-dated + transactions or postings, assertions might break and require updating. This order dependence does bring an advantage: precise control over the order of postings and assertions within a day, so you can assert intra- day balances. Assertions and included files - With included files, things are a little more complicated. Including - preserves the ordering of postings and assertions. If you have multi- - ple postings to an account on the same day, split across different - files, and you also want to assert the account's balance on the same + With included files, things are a little more complicated. Including + preserves the ordering of postings and assertions. If you have multi- + ple postings to an account on the same day, split across different + files, and you also want to assert the account's balance on the same day, you'll have to put the assertion in the right file. Assertions and multiple -f options @@ -4114,15 +4222,15 @@ JOURNAL FORMAT -f options. Use include or concatenate the files instead. Assertions and commodities - The asserted balance must be a simple single-commodity amount, and in - fact the assertion checks only this commodity's balance within the - (possibly multi-commodity) account balance. This is how assertions + The asserted balance must be a simple single-commodity amount, and in + fact the assertion checks only this commodity's balance within the + (possibly multi-commodity) account balance. This is how assertions work in Ledger also. We could call this a "partial" balance assertion. To assert the balance of more than one commodity in an account, you can write multiple postings, each asserting one commodity's balance. - You can make a stronger "total" balance assertion by writing a double + You can make a stronger "total" balance assertion by writing a double equals sign (== EXPECTEDBALANCE). This asserts that there are no other unasserted commodities in the account (or, that their balance is 0). @@ -4142,7 +4250,7 @@ JOURNAL FORMAT a 0 == $1 It's not yet possible to make a complete assertion about a balance that - has multiple commodities. One workaround is to isolate each commodity + has multiple commodities. One workaround is to isolate each commodity into its own subaccount: 2013/1/1 @@ -4156,21 +4264,21 @@ JOURNAL FORMAT a:euro 0 == 1EUR Assertions and prices - Balance assertions ignore transaction prices, and should normally be + Balance assertions ignore transaction prices, and should normally be written without one: 2019/1/1 (a) $1 @ EUR1 = $1 - We do allow prices to be written there, however, and print shows them, - even though they don't affect whether the assertion passes or fails. - This is for backward compatibility (hledger's close command used to - generate balance assertions with prices), and because balance assign- + We do allow prices to be written there, however, and print shows them, + even though they don't affect whether the assertion passes or fails. + This is for backward compatibility (hledger's close command used to + generate balance assertions with prices), and because balance assign- ments do use them (see below). Assertions and subaccounts - The balance assertions above (= and ==) do not count the balance from - subaccounts; they check the account's exclusive balance only. You can + The balance assertions above (= and ==) do not count the balance from + subaccounts; they check the account's exclusive balance only. You can assert the balance including subaccounts by writing =* or ==*, eg: 2019/1/1 @@ -4184,16 +4292,16 @@ JOURNAL FORMAT tual. They are not affected by the --real/-R flag or real: query. Assertions and precision - Balance assertions compare the exactly calculated amounts, which are - not always what is shown by reports. Eg a commodity directive may - limit the display precision, but this will not affect balance asser- + Balance assertions compare the exactly calculated amounts, which are + not always what is shown by reports. Eg a commodity directive may + limit the display precision, but this will not affect balance asser- tions. Balance assertion failure messages show exact amounts. Balance assignments - Ledger-style balance assignments are also supported. These are like - balance assertions, but with no posting amount on the left side of the - equals sign; instead it is calculated automatically so as to satisfy - the assertion. This can be a convenience during data entry, eg when + Ledger-style balance assignments are also supported. These are like + balance assertions, but with no posting amount on the left side of the + equals sign; instead it is calculated automatically so as to satisfy + the assertion. This can be a convenience during data entry, eg when setting opening balances: ; starting a new journal, set asset account balances @@ -4211,14 +4319,14 @@ JOURNAL FORMAT expenses:misc The calculated amount depends on the account's balance in the commodity - at that point (which depends on the previously-dated postings of the - commodity to that account since the last balance assertion or assign- + at that point (which depends on the previously-dated postings of the + commodity to that account since the last balance assertion or assign- ment). Note that using balance assignments makes your journal a little less explicit; to know the exact amount posted, you have to run hledger or do the calculations yourself, instead of just reading it. Balance assignments and prices - A transaction price in a balance assignment will cause the calculated + A transaction price in a balance assignment will cause the calculated amount to have that price attached: 2019/1/1 @@ -4229,70 +4337,71 @@ JOURNAL FORMAT (a) $1 @ EUR2 = $1 @ EUR2 Directives - A directive is a line in the journal beginning with a special keyword, + A directive is a line in the journal beginning with a special keyword, that influences how the journal is processed. hledger's directives are based on a subset of Ledger's, but there are many differences (and also some differences between hledger versions). Directives' behaviour and interactions can get a little bit complex, so - here is a table summarising the directives and their effects, with - links to more detailed docs. Note part of this table is hidden when + here is a table summarising the directives and their effects, with + links to more detailed docs. Note part of this table is hidden when viewed in a web browser - scroll it sideways to see more. - direc- end subdi- purpose can affect (as of + direc- end subdi- purpose can affect (as of tive directive rec- 2018/06) tives ------------------------------------------------------------------------------------ - account any document account names, all entries in all - text declare account types & dis- files, before or + account any document account names, all entries in all + text declare account types & dis- files, before or play order after alias end rewrite account names following entries - aliases until end of cur- + aliases until end of cur- rent file or end directive - apply end apply prepend a common parent to following entries - account account account names until end of cur- + apply end apply prepend a common parent to following entries + account account account names until end of cur- rent file or end directive comment end com- ignore part of journal following entries - ment until end of cur- + ment until end of cur- rent file or end directive - commod- format declare a commodity and its number notation: + commod- format declare a commodity and its number notation: ity number notation & display following entries style in that commodity in all files ; dis- play style: amounts of that commodity in reports - D declare a commodity to be default commodity: + D declare a commodity to be default commodity: used for commodityless following commod- - amounts, and its number ityless entries - notation & display style until end of cur- + amounts, and its number ityless entries + notation & display style until end of cur- rent file; number notation: following entries in that commodity until end - of current file; + of current file; display style: amounts of that commodity in reports include include entries/directives what the included from another file directives affect + [payee] declare a payee name following entries - until end of cur- + until end of cur- rent file P declare a market price for a amounts of that commodity commodity in reports, when -V is used - Y declare a year for yearless following entries - dates until end of cur- + Y declare a year for yearless following entries + dates until end of cur- rent file - = declare an auto posting all entries in par- - rule, adding postings to ent/current/child + = declare an auto posting all entries in par- + rule, adding postings to ent/current/child other transactions files (but not sib- ling files, see #1212) @@ -4300,55 +4409,53 @@ JOURNAL FORMAT And some definitions: - subdi- optional indented directive line immediately following a parent + subdi- optional indented directive line immediately following a parent rec- directive tive - - number how to interpret numbers when parsing journal entries (the iden- - nota- tity of the decimal separator character). (Currently each com- + nota- tity of the decimal separator character). (Currently each com- tion modity can have its own notation, even in the same file.) - dis- how to display amounts of a commodity in reports (symbol side + dis- how to display amounts of a commodity in reports (symbol side play and spacing, digit groups, decimal separator, decimal places) style - direc- which entries and (when there are multiple files) which files + direc- which entries and (when there are multiple files) which files tive are affected by a directive scope As you can see, directives vary in which journal entries and files they - affect, and whether they are focussed on input (parsing) or output + affect, and whether they are focussed on input (parsing) or output (reports). Some directives have multiple effects. Directives and multiple files - If you use multiple -f/--file options, or the include directive, - hledger will process multiple input files. But note that directives + If you use multiple -f/--file options, or the include directive, + hledger will process multiple input files. But note that directives which affect input (see above) typically last only until the end of the file in which they occur. This may seem inconvenient, but it's intentional; it makes reports sta- - ble and deterministic, independent of the order of input. Otherwise - you could see different numbers if you happened to write -f options in - a different order, or if you moved includes around while cleaning up + ble and deterministic, independent of the order of input. Otherwise + you could see different numbers if you happened to write -f options in + a different order, or if you moved includes around while cleaning up your files. - It can be surprising though; for example, it means that alias direc- + It can be surprising though; for example, it means that alias direc- tives do not affect parent or sibling files (see below). Comment blocks - A line containing just comment starts a commented region of the file, + A line containing just comment starts a commented region of the file, and a line containing just end comment (or the end of the current file) ends it. See also comments. Including other files - You can pull in the content of additional files by writing an include + You can pull in the content of additional files by writing an include directive, like this: include FILEPATH - Only journal files can include, and only journal, timeclock or timedot + Only journal files can include, and only journal, timeclock or timedot files can be included (not CSV files, currently). - If the file path does not begin with a slash, it is relative to the + If the file path does not begin with a slash, it is relative to the current file's folder. A tilde means home directory, eg: include ~/main.journal. @@ -4356,18 +4463,18 @@ JOURNAL FORMAT The path may contain glob patterns to match multiple files, eg: include *.journal. - There is limited support for recursive wildcards: **/ (the slash is - required) matches 0 or more subdirectories. It's not super convenient - since you have to avoid include cycles and including directories, but + There is limited support for recursive wildcards: **/ (the slash is + required) matches 0 or more subdirectories. It's not super convenient + since you have to avoid include cycles and including directories, but this can be done, eg: include */**/*.journal. The path may also be prefixed to force a specific file format, overrid- - ing the file extension (as described in hledger.1 -> Input files): + ing the file extension (as described in hledger.1 -> Input files): include timedot:~/notes/2020*.md. Default year - You can set a default year to be used for subsequent dates which don't - specify a year. This is a line beginning with Y followed by the year. + You can set a default year to be used for subsequent dates which don't + specify a year. This is a line beginning with Y followed by the year. Eg: Y2009 ; set default year to 2009 @@ -4387,9 +4494,9 @@ JOURNAL FORMAT assets Declaring payees - The payee directive can be used to declare a limited set of payees - which may appear in transaction descriptions. The "payees" check will - report an error if any transaction refers to a payee that has not been + The payee directive can be used to declare a limited set of payees + which may appear in transaction descriptions. The "payees" check will + report an error if any transaction refers to a payee that has not been declared. Eg: payee Whole Foods @@ -4397,19 +4504,19 @@ JOURNAL FORMAT Declaring commodities The commodity directive has several functions: - 1. It declares commodities which may be used in the journal. This is + 1. It declares commodities which may be used in the journal. This is currently not enforced, but can serve as documentation. - 2. It declares what decimal mark character (period or comma) to expect - when parsing input - useful to disambiguate international number - formats in your data. (Without this, hledger will parse both 1,000 + 2. It declares what decimal mark character (period or comma) to expect + when parsing input - useful to disambiguate international number + formats in your data. (Without this, hledger will parse both 1,000 and 1.000 as 1). - 3. It declares a commodity's display style in output - decimal and + 3. It declares a commodity's display style in output - decimal and digit group marks, number of decimal places, symbol placement etc. - You are likely to run into one of the problems solved by commodity - directives, sooner or later, so it's a good idea to just always use + You are likely to run into one of the problems solved by commodity + directives, sooner or later, so it's a good idea to just always use them to declare your commodities. A commodity directive is just the word commodity followed by an amount. @@ -4422,8 +4529,8 @@ JOURNAL FORMAT ; separating thousands with comma. commodity 1,000.0000 AAAA - or on multiple lines, using the "format" subdirective. (In this case - the commodity symbol appears twice and should be the same in both + or on multiple lines, using the "format" subdirective. (In this case + the commodity symbol appears twice and should be the same in both places.): ; commodity SYMBOL @@ -4436,28 +4543,28 @@ JOURNAL FORMAT format INR 1,00,00,000.00 The quantity of the amount does not matter; only the format is signifi- - cant. The number must include a decimal mark: either a period or a + cant. The number must include a decimal mark: either a period or a comma, followed by 0 or more decimal digits. - Note hledger normally uses banker's rounding, so 0.5 displayed with + Note hledger normally uses banker's rounding, so 0.5 displayed with zero decimal digits is "0". (More at Commodity display style.) Commodity error checking - In strict mode, enabled with the -s/--strict flag, hledger will report - an error if a commodity symbol is used that has not been declared by a - commodity directive. This works similarly to account error checking, + In strict mode, enabled with the -s/--strict flag, hledger will report + an error if a commodity symbol is used that has not been declared by a + commodity directive. This works similarly to account error checking, see the notes there for more details. Default commodity - The D directive sets a default commodity, to be used for amounts with- - out a commodity symbol (ie, plain numbers). This commodity will be - applied to all subsequent commodity-less amounts, or until the next D + The D directive sets a default commodity, to be used for amounts with- + out a commodity symbol (ie, plain numbers). This commodity will be + applied to all subsequent commodity-less amounts, or until the next D directive. (Note, this is different from Ledger's D.) - For compatibility/historical reasons, D also acts like a commodity + For compatibility/historical reasons, D also acts like a commodity directive, setting the commodity's display style (for output) and deci- - mal mark (for parsing input). As with commodity, the amount must - always be written with a decimal mark (period or comma). If both + mal mark (for parsing input). As with commodity, the amount must + always be written with a decimal mark (period or comma). If both directives are used, commodity's style takes precedence. The syntax is D AMOUNT. Eg: @@ -4471,9 +4578,9 @@ JOURNAL FORMAT b Declaring market prices - The P directive declares a market price, which is an exchange rate + The P directive declares a market price, which is an exchange rate between two commodities on a certain date. (In Ledger, they are called - "historical prices".) These are often obtained from a stock exchange, + "historical prices".) These are often obtained from a stock exchange, cryptocurrency exchange, or the foreign exchange market. Here is the format: @@ -4484,78 +4591,78 @@ JOURNAL FORMAT o COMMODITYA is the symbol of the commodity being priced - o COMMODITYBAMOUNT is an amount (symbol and quantity) in a second com- + o COMMODITYBAMOUNT is an amount (symbol and quantity) in a second com- modity, giving the price in commodity B of one unit of commodity A. - These two market price directives say that one euro was worth 1.35 US + These two market price directives say that one euro was worth 1.35 US dollars during 2009, and $1.40 from 2010 onward: P 2009/1/1 EUR $1.35 P 2010/1/1 EUR $1.40 - The -V, -X and --value flags use these market prices to show amount + The -V, -X and --value flags use these market prices to show amount values in another commodity. See Valuation. Declaring accounts account directives can be used to declare accounts (ie, the places that - amounts are transferred from and to). Though not required, these dec- + amounts are transferred from and to). Though not required, these dec- larations can provide several benefits: o They can document your intended chart of accounts, providing a refer- ence. - o They can help hledger know your accounts' types (asset, liability, - equity, revenue, expense), useful for reports like balancesheet and + o They can help hledger know your accounts' types (asset, liability, + equity, revenue, expense), useful for reports like balancesheet and incomestatement. - o They control account display order in reports, allowing non-alpha- + o They control account display order in reports, allowing non-alpha- betic sorting (eg Revenues to appear above Expenses). - o They can store extra information about accounts (account numbers, + o They can store extra information about accounts (account numbers, notes, etc.) - o They help with account name completion in the add command, hledger- + o They help with account name completion in the add command, hledger- iadd, hledger-web, ledger-mode etc. - o In strict mode, they restrict which accounts may be posted to by + o In strict mode, they restrict which accounts may be posted to by transactions, which helps detect typos. - The simplest form is just the word account followed by a hledger-style + The simplest form is just the word account followed by a hledger-style account name, eg this account directive declares the assets:bank:check- ing account: account assets:bank:checking Account error checking - By default, accounts come into existence when a transaction references - them by name. This is convenient, but it means hledger can't warn you + By default, accounts come into existence when a transaction references + them by name. This is convenient, but it means hledger can't warn you when you mis-spell an account name in the journal. Usually you'll find - the error later, as an extra account in balance reports, or an incor- + the error later, as an extra account in balance reports, or an incor- rect balance when reconciling. - In strict mode, enabled with the -s/--strict flag, hledger will report - an error if any transaction uses an account name that has not been + In strict mode, enabled with the -s/--strict flag, hledger will report + an error if any transaction uses an account name that has not been declared by an account directive. Some notes: - o The declaration is case-sensitive; transactions must use the correct + o The declaration is case-sensitive; transactions must use the correct account name capitalisation. - o The account directive's scope is "whole file and below" (see direc- + o The account directive's scope is "whole file and below" (see direc- tives). This means it affects all of the current file, and any files - it includes, but not parent or sibling files. The position of + it includes, but not parent or sibling files. The position of account directives within the file does not matter, though it's usual to put them at the top. - o Accounts can only be declared in journal files (but will affect + o Accounts can only be declared in journal files (but will affect included files in other formats). - o It's currently not possible to declare "all possible subaccounts" + o It's currently not possible to declare "all possible subaccounts" with a wildcard; every account posted to must be declared. Account comments Comments, beginning with a semicolon, can be added: - o on the same line, after two or more spaces (because ; is allowed in + o on the same line, after two or more spaces (because ; is allowed in account names) o on the next lines, indented @@ -4569,7 +4676,7 @@ JOURNAL FORMAT Same-line comments are not supported by Ledger, or hledger <1.13. Account subdirectives - We also allow (and ignore) Ledger-style indented subdirectives, just + We also allow (and ignore) Ledger-style indented subdirectives, just for compatibility.: account assets:bank:checking @@ -4582,27 +4689,27 @@ JOURNAL FORMAT [LEDGER-STYLE SUBDIRECTIVES, IGNORED] Account types - hledger recognises five main types of account, corresponding to the + hledger recognises five main types of account, corresponding to the account classes in the accounting equation: Asset, Liability, Equity, Revenue, Expense. These account types are important for controlling which accounts appear - in the balancesheet, balancesheetequity, incomestatement reports (and + in the balancesheet, balancesheetequity, incomestatement reports (and probably for other things in future). - Additionally, we recognise the Cash type, which is also an Asset, and - which causes accounts to appear in the cashflow report. ("Cash" here - means liquid assets, eg bank balances but typically not investments or + Additionally, we recognise the Cash type, which is also an Asset, and + which causes accounts to appear in the cashflow report. ("Cash" here + means liquid assets, eg bank balances but typically not investments or receivables.) Declaring account types Generally, to make these reports work you should declare your top-level accounts and their types, using account directives with type: tags. - The tag's value should be one of: Asset, Liability, Equity, Revenue, - Expense, Cash, A, L, E, R, X, C (all case insensitive). The type is - inherited by all subaccounts except where they override it. Here's a + The tag's value should be one of: Asset, Liability, Equity, Revenue, + Expense, Cash, A, L, E, R, X, C (all case insensitive). The type is + inherited by all subaccounts except where they override it. Here's a complete example: account assets ; type: Asset @@ -4614,8 +4721,8 @@ JOURNAL FORMAT account expenses ; type: Expense Auto-detected account types - If you happen to use common english top-level account names, you may - not need to declare account types, as they will be detected automati- + If you happen to use common english top-level account names, you may + not need to declare account types, as they will be detected automati- cally using the following rules: @@ -4623,7 +4730,6 @@ JOURNAL FORMAT expression: ---------------------------------------------- ^assets?(:|$) Asset - ^(debts?|lia- Liability bilit(y|ies))(:|$) ^equity(:|$) Equity @@ -4631,7 +4737,7 @@ JOURNAL FORMAT ^expenses?(:|$) Expense - If account type is Asset and name does not contain regu- account type + If account type is Asset and name does not contain regu- account type lar expression: is: -------------------------------------------------------------------------- (investment|receivable|:A/R|:fixed) Cash @@ -4641,10 +4747,10 @@ JOURNAL FORMAT Interference from auto-detected account types If you assign any account type, it's a good idea to assign all of them, - to prevent any confusion from mixing declared and auto-detected types. - Although it's unlikely to happen in real life, here's an example: with - the following journal, balancesheetequity shows "liabilities" in both - Liabilities and Equity sections. Declaring another account as + to prevent any confusion from mixing declared and auto-detected types. + Although it's unlikely to happen in real life, here's an example: with + the following journal, balancesheetequity shows "liabilities" in both + Liabilities and Equity sections. Declaring another account as type:Liability would fix it: account liabilities ; type:Equity @@ -4655,8 +4761,8 @@ JOURNAL FORMAT equity -2 Old account type syntax - In some hledger journals you might instead see this old syntax (the - letters ALERX, separated from the account name by two or more spaces); + In some hledger journals you might instead see this old syntax (the + letters ALERX, separated from the account name by two or more spaces); this is deprecated and may be removed soon: account assets A @@ -4666,8 +4772,8 @@ JOURNAL FORMAT account expenses X Account display order - Account directives also set the order in which accounts are displayed, - eg in reports, the hledger-ui accounts screen, and the hledger-web + Account directives also set the order in which accounts are displayed, + eg in reports, the hledger-ui accounts screen, and the hledger-web sidebar. By default accounts are listed in alphabetical order. But if you have these account directives in the journal: @@ -4689,20 +4795,20 @@ JOURNAL FORMAT Undeclared accounts, if any, are displayed last, in alphabetical order. - Note that sorting is done at each level of the account tree (within - each group of sibling accounts under the same parent). And currently, + Note that sorting is done at each level of the account tree (within + each group of sibling accounts under the same parent). And currently, this directive: account other:zoo - would influence the position of zoo among other's subaccounts, but not + would influence the position of zoo among other's subaccounts, but not the position of other among the top-level accounts. This means: - o you will sometimes declare parent accounts (eg account other above) - that you don't intend to post to, just to customize their display + o you will sometimes declare parent accounts (eg account other above) + that you don't intend to post to, just to customize their display order - o sibling accounts stay together (you couldn't display x:y in between + o sibling accounts stay together (you couldn't display x:y in between a:b and a:c). Rewriting accounts @@ -4720,14 +4826,14 @@ JOURNAL FORMAT o customising reports Account aliases also rewrite account names in account directives. They - do not affect account names being entered via hledger add or hledger- + do not affect account names being entered via hledger add or hledger- web. See also Rewrite account names. Basic aliases - To set an account alias, use the alias directive in your journal file. - This affects all subsequent journal entries in the current file or its + To set an account alias, use the alias directive in your journal file. + This affects all subsequent journal entries in the current file or its included files. The spaces around the = are optional: alias OLD = NEW @@ -4735,49 +4841,49 @@ JOURNAL FORMAT Or, you can use the --alias 'OLD=NEW' option on the command line. This affects all entries. It's useful for trying out aliases interactively. - OLD and NEW are case sensitive full account names. hledger will - replace any occurrence of the old account name with the new one. Sub- + OLD and NEW are case sensitive full account names. hledger will + replace any occurrence of the old account name with the new one. Sub- accounts are also affected. Eg: alias checking = assets:bank:wells fargo:checking ; rewrites "checking" to "assets:bank:wells fargo:checking", or "checking:a" to "assets:bank:wells fargo:checking:a" Regex aliases - There is also a more powerful variant that uses a regular expression, + There is also a more powerful variant that uses a regular expression, indicated by the forward slashes: alias /REGEX/ = REPLACEMENT or --alias '/REGEX/=REPLACEMENT'. - REGEX is a case-insensitive regular expression. Anywhere it matches - inside an account name, the matched part will be replaced by REPLACE- - MENT. If REGEX contains parenthesised match groups, these can be ref- + REGEX is a case-insensitive regular expression. Anywhere it matches + inside an account name, the matched part will be replaced by REPLACE- + MENT. If REGEX contains parenthesised match groups, these can be ref- erenced by the usual numeric backreferences in REPLACEMENT. Eg: alias /^(.+):bank:([^:]+):(.*)/ = \1:\2 \3 ; rewrites "assets:bank:wells fargo:checking" to "assets:wells fargo checking" - Also note that REPLACEMENT continues to the end of line (or on command - line, to end of option argument), so it can contain trailing white- + Also note that REPLACEMENT continues to the end of line (or on command + line, to end of option argument), so it can contain trailing white- space. Combining aliases - You can define as many aliases as you like, using journal directives + You can define as many aliases as you like, using journal directives and/or command line options. - Recursive aliases - where an account name is rewritten by one alias, - then by another alias, and so on - are allowed. Each alias sees the + Recursive aliases - where an account name is rewritten by one alias, + then by another alias, and so on - are allowed. Each alias sees the effect of previously applied aliases. - In such cases it can be important to understand which aliases will be - applied and in which order. For (each account name in) each journal + In such cases it can be important to understand which aliases will be + applied and in which order. For (each account name in) each journal entry, we apply: - 1. alias directives preceding the journal entry, most recently parsed + 1. alias directives preceding the journal entry, most recently parsed first (ie, reading upward from the journal entry, bottom to top) - 2. --alias options, in the order they appeared on the command line + 2. --alias options, in the order they appeared on the command line (left to right). In other words, for (an account name in) a given journal entry: @@ -4788,15 +4894,15 @@ JOURNAL FORMAT o aliases defined after/below the entry do not affect it. - This gives nearby aliases precedence over distant ones, and helps pro- - vide semantic stability - aliases will keep working the same way inde- + This gives nearby aliases precedence over distant ones, and helps pro- + vide semantic stability - aliases will keep working the same way inde- pendent of which files are being read and in which order. - In case of trouble, adding --debug=6 to the command line will show + In case of trouble, adding --debug=6 to the command line will show which aliases are being applied when. Aliases and multiple files - As explained at Directives and multiple files, alias directives do not + As explained at Directives and multiple files, alias directives do not affect parent or sibling files. Eg in this command, hledger -f a.aliases -f b.journal @@ -4823,14 +4929,14 @@ JOURNAL FORMAT include c.journal ; also affected end aliases - You can clear (forget) all currently defined aliases with the end + You can clear (forget) all currently defined aliases with the end aliases directive: end aliases Default parent account - You can specify a parent account which will be prepended to all - accounts within a section of the journal. Use the apply account and + You can specify a parent account which will be prepended to all + accounts within a section of the journal. Use the apply account and end apply account directives like so: apply account home @@ -4847,7 +4953,7 @@ JOURNAL FORMAT home:food $10 home:cash $-10 - If end apply account is omitted, the effect lasts to the end of the + If end apply account is omitted, the effect lasts to the end of the file. Included files are also affected, eg: apply account business @@ -4856,49 +4962,49 @@ JOURNAL FORMAT apply account personal include personal.journal - Prior to hledger 1.0, legacy account and end spellings were also sup- + Prior to hledger 1.0, legacy account and end spellings were also sup- ported. - A default parent account also affects account directives. It does not - affect account names being entered via hledger add or hledger-web. If - account aliases are present, they are applied after the default parent + A default parent account also affects account directives. It does not + affect account names being entered via hledger add or hledger-web. If + account aliases are present, they are applied after the default parent account. Periodic transactions - Periodic transaction rules describe transactions that recur. They - allow hledger to generate temporary future transactions to help with - forecasting, so you don't have to write out each one in the journal, + Periodic transaction rules describe transactions that recur. They + allow hledger to generate temporary future transactions to help with + forecasting, so you don't have to write out each one in the journal, and it's easy to try out different forecasts. - Periodic transactions can be a little tricky, so before you use them, + Periodic transactions can be a little tricky, so before you use them, read this whole section - or at least these tips: - 1. Two spaces accidentally added or omitted will cause you trouble - + 1. Two spaces accidentally added or omitted will cause you trouble - read about this below. - 2. For troubleshooting, show the generated transactions with hledger - print --forecast tag:generated or hledger register --forecast + 2. For troubleshooting, show the generated transactions with hledger + print --forecast tag:generated or hledger register --forecast tag:generated. - 3. Forecasted transactions will begin only after the last non-fore- + 3. Forecasted transactions will begin only after the last non-fore- casted transaction's date. - 4. Forecasted transactions will end 6 months from today, by default. + 4. Forecasted transactions will end 6 months from today, by default. See below for the exact start/end rules. - 5. period expressions can be tricky. Their documentation needs + 5. period expressions can be tricky. Their documentation needs improvement, but is worth studying. - 6. Some period expressions with a repeating interval must begin on a - natural boundary of that interval. Eg in weekly from DATE, DATE - must be a monday. ~ weekly from 2019/10/1 (a tuesday) will give an + 6. Some period expressions with a repeating interval must begin on a + natural boundary of that interval. Eg in weekly from DATE, DATE + must be a monday. ~ weekly from 2019/10/1 (a tuesday) will give an error. 7. Other period expressions with an interval are automatically expanded - to cover a whole number of that interval. (This is done to improve + to cover a whole number of that interval. (This is done to improve reports, but it also affects periodic transactions. Yes, it's a bit - inconsistent with the above.) Eg: ~ every 10th day of month from - 2020/01, which is equivalent to ~ every 10th day of month from + inconsistent with the above.) Eg: ~ every 10th day of month from + 2020/01, which is equivalent to ~ every 10th day of month from 2020/01/01, will be adjusted to start on 2019/12/10. Periodic transaction rules also have a second meaning: they are used to @@ -4913,17 +5019,17 @@ JOURNAL FORMAT expenses:rent $2000 assets:bank:checking - There is an additional constraint on the period expression: the start - date must fall on a natural boundary of the interval. Eg monthly from + There is an additional constraint on the period expression: the start + date must fall on a natural boundary of the interval. Eg monthly from 2018/1/1 is valid, but monthly from 2018/1/15 is not. - Partial or relative dates (M/D, D, tomorrow, last week) in the period - expression can work (useful or not). They will be relative to today's - date, unless a Y default year directive is in effect, in which case + Partial or relative dates (M/D, D, tomorrow, last week) in the period + expression can work (useful or not). They will be relative to today's + date, unless a Y default year directive is in effect, in which case they will be relative to Y/1/1. Two spaces between period expression and description! - If the period expression is followed by a transaction description, + If the period expression is followed by a transaction description, these must be separated by two or more spaces. This helps hledger know where the period expression ends, so that descriptions can not acciden- tally alter their meaning, as in this example: @@ -4937,67 +5043,67 @@ JOURNAL FORMAT So, - o Do write two spaces between your period expression and your transac- + o Do write two spaces between your period expression and your transac- tion description, if any. - o Don't accidentally write two spaces in the middle of your period + o Don't accidentally write two spaces in the middle of your period expression. Forecasting with periodic transactions - The --forecast flag activates any periodic transaction rules in the - journal. They will generate temporary recurring transactions, which - are not saved in the journal, but will appear in all reports (eg + The --forecast flag activates any periodic transaction rules in the + journal. They will generate temporary recurring transactions, which + are not saved in the journal, but will appear in all reports (eg print). This can be useful for estimating balances into the future, or - experimenting with different scenarios. Or, it can be used as a data + experimenting with different scenarios. Or, it can be used as a data entry aid: describe recurring transactions, and every so often copy the output of print --forecast into the journal. - These transactions will have an extra tag indicating which periodic + These transactions will have an extra tag indicating which periodic rule generated them: generated-transaction:~ PERIODICEXPR. And a simi- - lar, hidden tag (beginning with an underscore) which, because it's - never displayed by print, can be used to match transactions generated + lar, hidden tag (beginning with an underscore) which, because it's + never displayed by print, can be used to match transactions generated "just now": _generated-transaction:~ PERIODICEXPR. - Periodic transactions are generated within some forecast period. By + Periodic transactions are generated within some forecast period. By default, this o begins on the later of o the report start date if specified with -b/-p/date: - o the day after the latest normal (non-periodic) transaction in the + o the day after the latest normal (non-periodic) transaction in the journal, or today if there are no normal transactions. - o ends on the report end date if specified with -e/-p/date:, or 6 + o ends on the report end date if specified with -e/-p/date:, or 6 months (180 days) from today. - This means that periodic transactions will begin only after the latest - recorded transaction. And a recorded transaction dated in the future - can prevent generation of periodic transactions. (You can avoid that + This means that periodic transactions will begin only after the latest + recorded transaction. And a recorded transaction dated in the future + can prevent generation of periodic transactions. (You can avoid that by writing the future transaction as a one-time periodic rule instead - put tilde before the date, eg ~ YYYY-MM-DD ...). Or, you can set your own arbitrary "forecast period", which can overlap - recorded transactions, and need not be in the future, by providing an - option argument, like --forecast=PERIODEXPR. Note the equals sign is + recorded transactions, and need not be in the future, by providing an + option argument, like --forecast=PERIODEXPR. Note the equals sign is required, a space won't work. PERIODEXPR is a period expression, which - can specify the start date, end date, or both, like in a date: query. - (See also hledger.1 -> Report start & end date). Some examples: + can specify the start date, end date, or both, like in a date: query. + (See also hledger.1 -> Report start & end date). Some examples: --forecast=202001-202004, --forecast=jan-, --forecast=2020. Budgeting with periodic transactions - With the --budget flag, currently supported by the balance command, - each periodic transaction rule declares recurring budget goals for the - specified accounts. Eg the first example above declares a goal of - spending $2000 on rent (and also, a goal of depositing $2000 into - checking) every month. Goals and actual performance can then be com- + With the --budget flag, currently supported by the balance command, + each periodic transaction rule declares recurring budget goals for the + specified accounts. Eg the first example above declares a goal of + spending $2000 on rent (and also, a goal of depositing $2000 into + checking) every month. Goals and actual performance can then be com- pared in budget reports. See also: Budgeting and Forecasting. Auto postings - "Automated postings" or "auto postings" are extra postings which get + "Automated postings" or "auto postings" are extra postings which get added automatically to transactions which match certain queries, defined by "auto posting rules", when you use the --auto flag. @@ -5008,27 +5114,27 @@ JOURNAL FORMAT ... ACCOUNT [AMOUNT] - except the first line is an equals sign (mnemonic: = suggests match- - ing), followed by a query (which matches existing postings), and each - "posting" line describes a posting to be generated, and the posting + except the first line is an equals sign (mnemonic: = suggests match- + ing), followed by a query (which matches existing postings), and each + "posting" line describes a posting to be generated, and the posting amounts can be: - o a normal amount with a commodity symbol, eg $2. This will be used + o a normal amount with a commodity symbol, eg $2. This will be used as-is. o a number, eg 2. The commodity symbol (if any) from the matched post- ing will be added to this. - o a numeric multiplier, eg *2 (a star followed by a number N). The + o a numeric multiplier, eg *2 (a star followed by a number N). The matched posting's amount (and total price, if any) will be multiplied by N. - o a multiplier with a commodity symbol, eg *$2 (a star, number N, and + o a multiplier with a commodity symbol, eg *$2 (a star, number N, and symbol S). The matched posting's amount will be multiplied by N, and its commodity symbol will be replaced with S. - Any query term containing spaces must be enclosed in single or double - quotes, as on the command line. Eg, note the quotes around the second + Any query term containing spaces must be enclosed in single or double + quotes, as on the command line. Eg, note the quotes around the second query term below: = expenses:groceries 'expenses:dining out' @@ -5067,24 +5173,24 @@ JOURNAL FORMAT Auto postings and multiple files An auto posting rule can affect any transaction in the current file, or - in any parent file or child file. Note, currently it will not affect + in any parent file or child file. Note, currently it will not affect sibling files (when multiple -f/--file are used - see #1212). Auto postings and dates - A posting date (or secondary date) in the matched posting, or (taking - precedence) a posting date in the auto posting rule itself, will also + A posting date (or secondary date) in the matched posting, or (taking + precedence) a posting date in the auto posting rule itself, will also be used in the generated posting. Auto postings and transaction balancing / inferred amounts / balance asser- tions Currently, auto postings are added: - o after missing amounts are inferred, and transactions are checked for + o after missing amounts are inferred, and transactions are checked for balancedness, o but before balance assertions are checked. - Note this means that journal entries must be balanced both before and + Note this means that journal entries must be balanced both before and after auto postings are added. This changed in hledger 1.12+; see #893 for background. @@ -5094,11 +5200,11 @@ JOURNAL FORMAT o generated-posting:= QUERY - shows this was generated by an auto post- ing rule, and the query - o _generated-posting:= QUERY - a hidden tag, which does not appear in + o _generated-posting:= QUERY - a hidden tag, which does not appear in hledger's output. This can be used to match postings generated "just now", rather than generated in the past and saved to the journal. - Also, any transaction that has been changed by auto posting rules will + Also, any transaction that has been changed by auto posting rules will have these tags added: o modified: - this transaction was modified @@ -5109,61 +5215,61 @@ JOURNAL FORMAT CSV FORMAT How hledger reads CSV data, and the CSV rules file format. - hledger can read CSV files (Character Separated Value - usually comma, - semicolon, or tab) containing dated records as if they were journal + hledger can read CSV files (Character Separated Value - usually comma, + semicolon, or tab) containing dated records as if they were journal files, automatically converting each CSV record into a transaction. (To learn about writing CSV, see CSV output.) We describe each CSV file's format with a corresponding rules file. By - default this is named like the CSV file with a .rules extension added. - Eg when reading FILE.csv, hledger also looks for FILE.csv.rules in the - same directory as FILE.csv. You can specify a different rules file - with the --rules-file option. If a rules file is not found, hledger + default this is named like the CSV file with a .rules extension added. + Eg when reading FILE.csv, hledger also looks for FILE.csv.rules in the + same directory as FILE.csv. You can specify a different rules file + with the --rules-file option. If a rules file is not found, hledger will create a sample rules file, which you'll need to adjust. - This file contains rules describing the CSV data (header line, fields + This file contains rules describing the CSV data (header line, fields layout, date format etc.), and how to construct hledger journal entries (transactions) from it. Often there will also be a list of conditional rules for categorising transactions based on their descriptions. - Here's an overview of the CSV rules; these are described more fully + Here's an overview of the CSV rules; these are described more fully below, after the examples: skip skip one or more header lines or matched CSV records - fields name CSV fields, assign them to hledger + fields name CSV fields, assign them to hledger fields - field assignment assign a value to one hledger field, + field assignment assign a value to one hledger field, with interpolation separator a custom field separator - if block apply some rules to CSV records matched + if block apply some rules to CSV records matched by patterns - if table apply some rules to CSV records matched + if table apply some rules to CSV records matched by patterns, alternate syntax end skip the remaining CSV records date-format how to parse dates in CSV records decimal-mark the decimal mark used in CSV amounts, if ambiguous - newest-first disambiguate record order when there's + newest-first disambiguate record order when there's only one date include inline another CSV rules file balance-type choose which type of balance assignments to use - Note, for best error messages when reading CSV files, use a .csv, .tsv + Note, for best error messages when reading CSV files, use a .csv, .tsv or .ssv file extension or file prefix - see File Extension below. There's an introductory Convert CSV files tutorial on hledger.org. Examples - Here are some sample hledger CSV rules files. See also the full col- + Here are some sample hledger CSV rules files. See also the full col- lection at: https://github.com/simonmichael/hledger/tree/master/examples/csv Basic - At minimum, the rules file must identify the date and amount fields, - and often it also specifies the date format and how many header lines + At minimum, the rules file must identify the date and amount fields, + and often it also specifies the date format and how many header lines there are. Here's a simple CSV file and a rules file for it: Date, Description, Id, Amount @@ -5182,8 +5288,8 @@ CSV FORMAT Default account names are chosen, since we didn't set them. Bank of Ireland - Here's a CSV with two amount fields (Debit and Credit), and a balance - field, which we can use to add balance assertions, which is not neces- + Here's a CSV with two amount fields (Debit and Credit), and a balance + field, which we can use to add balance assertions, which is not neces- sary but provides extra error checking: Date,Details,Debit,Credit,Balance @@ -5225,13 +5331,13 @@ CSV FORMAT assets:bank:boi:checking EUR-5.0 = EUR126.0 expenses:unknown EUR5.0 - The balance assertions don't raise an error above, because we're read- - ing directly from CSV, but they will be checked if these entries are + The balance assertions don't raise an error above, because we're read- + ing directly from CSV, but they will be checked if these entries are imported into a journal file. Amazon Here we convert amazon.com order history, and use an if block to gener- - ate a third posting if there's a fee. (In practice you'd probably get + ate a third posting if there's a fee. (In practice you'd probably get this data from your bank instead, but it's an example.) "Date","Type","To/From","Name","Status","Amount","Fees","Transaction ID" @@ -5283,7 +5389,7 @@ CSV FORMAT expenses:fees $1.00 Paypal - Here's a real-world rules file for (customised) Paypal CSV, with some + Here's a real-world rules file for (customised) Paypal CSV, with some Paypal-specific rules, and a second rules file included: "Date","Time","TimeZone","Name","Type","Status","Currency","Gross","Fee","Net","From Email Address","To Email Address","Transaction ID","Item Title","Item ID","Reference Txn ID","Receipt ID","Balance","Note" @@ -5438,9 +5544,9 @@ CSV FORMAT skip skip N - The word "skip" followed by a number (or no number, meaning 1) tells - hledger to ignore this many non-empty lines preceding the CSV data. - (Empty/blank lines are skipped automatically.) You'll need this when- + The word "skip" followed by a number (or no number, meaning 1) tells + hledger to ignore this many non-empty lines preceding the CSV data. + (Empty/blank lines are skipped automatically.) You'll need this when- ever your CSV data contains header lines. It also has a second purpose: it can be used inside if blocks to ignore @@ -5449,27 +5555,27 @@ CSV FORMAT fields fields FIELDNAME1, FIELDNAME2, ... - A fields list (the word "fields" followed by comma-separated field - names) is the quick way to assign CSV field values to hledger fields. + A fields list (the word "fields" followed by comma-separated field + names) is the quick way to assign CSV field values to hledger fields. It does two things: - 1. it names the CSV fields. This is optional, but can be convenient + 1. it names the CSV fields. This is optional, but can be convenient later for interpolating them. 2. when you use a standard hledger field name, it assigns the CSV value to that part of the hledger transaction. - Here's an example that says "use the 1st, 2nd and 4th fields as the - transaction's date, description and amount; name the last two fields + Here's an example that says "use the 1st, 2nd and 4th fields as the + transaction's date, description and amount; name the last two fields for later reference; and ignore the others": fields date, description, , amount, , , somefield, anotherfield - Field names may not contain whitespace. Fields you don't care about - can be left unnamed. Currently there must be least two items (there + Field names may not contain whitespace. Fields you don't care about + can be left unnamed. Currently there must be least two items (there must be at least one comma). - Note, always use comma in the fields list, even if your CSV uses + Note, always use comma in the fields list, even if your CSV uses another separator character. Here are the standard hledger field/pseudo-field names. For more about @@ -5482,52 +5588,52 @@ CSV FORMAT Posting field names account - accountN, where N is 1 to 99, causes a posting to be generated, with + accountN, where N is 1 to 99, causes a posting to be generated, with that account name. - Most often there are two postings, so you'll want to set account1 and - account2. Typically account1 is associated with the CSV file, and is - set once with a top-level assignment, while account2 is set based on + Most often there are two postings, so you'll want to set account1 and + account2. Typically account1 is associated with the CSV file, and is + set once with a top-level assignment, while account2 is set based on each transaction's description, and in conditional blocks. - If a posting's account name is left unset but its amount is set (see - below), a default account name will be chosen (like "expenses:unknown" + If a posting's account name is left unset but its amount is set (see + below), a default account name will be chosen (like "expenses:unknown" or "income:unknown"). amount - amountN sets posting N's amount. If the CSV uses separate fields for - inflows and outflows, you can use amountN-in and amountN-out instead. - By assigning to amount1, amount2, ... etc. you can generate anywhere + amountN sets posting N's amount. If the CSV uses separate fields for + inflows and outflows, you can use amountN-in and amountN-out instead. + By assigning to amount1, amount2, ... etc. you can generate anywhere from 0 to 99 postings. - There is also an older, unnumbered form of these names, suitable for + There is also an older, unnumbered form of these names, suitable for 2-posting transactions, which sets both posting 1's and (negated) post- - ing 2's amount: amount, or amount-in and amount-out. This is still - supported because it keeps pre-hledger-1.17 csv rules files working, - and because it can be more succinct, and because it converts posting + ing 2's amount: amount, or amount-in and amount-out. This is still + supported because it keeps pre-hledger-1.17 csv rules files working, + and because it can be more succinct, and because it converts posting 2's amount to cost if there's a transaction price, which can be useful. If you have an existing rules file using the unnumbered form, you might - want to use the numbered form in certain conditional blocks, without - having to update and retest all the old rules. To facilitate this, - posting 1 ignores amount/amount-in/amount-out if any of + want to use the numbered form in certain conditional blocks, without + having to update and retest all the old rules. To facilitate this, + posting 1 ignores amount/amount-in/amount-out if any of amount1/amount1-in/amount1-out are assigned, and posting 2 ignores them - if any of amount2/amount2-in/amount2-out are assigned, avoiding con- + if any of amount2/amount2-in/amount2-out are assigned, avoiding con- flicts. currency If the CSV has the currency symbol in a separate field (ie, not part of - the amount field), you can use currencyN to prepend it to posting N's + the amount field), you can use currencyN to prepend it to posting N's amount. Or, currency with no number affects all postings. balance - balanceN sets a balance assertion amount (or if the posting amount is + balanceN sets a balance assertion amount (or if the posting amount is left empty, a balance assignment) on posting N. - Also, for compatibility with hledger <1.17: balance with no number is + Also, for compatibility with hledger <1.17: balance with no number is equivalent to balance1. - You can adjust the type of assertion/assignment with the balance-type + You can adjust the type of assertion/assignment with the balance-type rule (see below). comment @@ -5539,11 +5645,11 @@ CSV FORMAT field assignment HLEDGERFIELDNAME FIELDVALUE - Instead of or in addition to a fields list, you can use a "field + Instead of or in addition to a fields list, you can use a "field assignment" rule to set the value of a single hledger field, by writing - its name (any of the standard hledger field names above) followed by a - text value. The value may contain interpolated CSV fields, referenced - by their 1-based position in the CSV record (%N), or by the name they + its name (any of the standard hledger field names above) followed by a + text value. The value may contain interpolated CSV fields, referenced + by their 1-based position in the CSV record (%N), or by the name they were given in the fields list (%CSVFIELDNAME). Some examples: # set the amount to the 4th CSV field, with " USD" appended @@ -5552,14 +5658,14 @@ CSV FORMAT # combine three fields to make a comment, containing note: and date: tags comment note: %somefield - %anotherfield, date: %1 - Interpolation strips outer whitespace (so a CSV value like " 1 " - becomes 1 when interpolated) (#1051). See TIPS below for more about + Interpolation strips outer whitespace (so a CSV value like " 1 " + becomes 1 when interpolated) (#1051). See TIPS below for more about referencing other fields. separator - You can use the separator rule to read other kinds of character-sepa- - rated data. The argument is any single separator character, or the - words tab or space (case insensitive). Eg, for comma-separated values + You can use the separator rule to read other kinds of character-sepa- + rated data. The argument is any single separator character, or the + words tab or space (case insensitive). Eg, for comma-separated values (CSV): separator , @@ -5572,7 +5678,7 @@ CSV FORMAT separator TAB - If the input file has a .csv, .ssv or .tsv file extension (or a csv:, + If the input file has a .csv, .ssv or .tsv file extension (or a csv:, ssv:, tsv: prefix), the appropriate separator will be inferred automat- ically, and you won't need this rule. @@ -5587,8 +5693,8 @@ CSV FORMAT RULE RULE - Conditional blocks ("if blocks") are a block of rules that are applied - only to CSV records which match certain patterns. They are often used + Conditional blocks ("if blocks") are a block of rules that are applied + only to CSV records which match certain patterns. They are often used for customising account names based on transaction descriptions. Matching the whole record @@ -5596,17 +5702,17 @@ CSV FORMAT REGEX - REGEX is a case-insensitive regular expression which tries to match - anywhere within the CSV record. It is a POSIX ERE (extended regular - expression) that also supports GNU word boundaries (\b, \B, \<, \>), + REGEX is a case-insensitive regular expression which tries to match + anywhere within the CSV record. It is a POSIX ERE (extended regular + expression) that also supports GNU word boundaries (\b, \B, \<, \>), and nothing else. If you have trouble, be sure to check our https://hledger.org/hledger.html#regular-expressions doc. - Important note: the record that is matched is not the original record, - but a synthetic one, with any enclosing double quotes (but not enclos- + Important note: the record that is matched is not the original record, + but a synthetic one, with any enclosing double quotes (but not enclos- ing whitespace) removed, and always comma-separated (which means that a - field containing a comma will appear like two fields). Eg, if the - original record is 2020-01-01; "Acme, Inc."; 1,000, the REGEX will + field containing a comma will appear like two fields). Eg, if the + original record is 2020-01-01; "Acme, Inc."; 1,000, the REGEX will actually see 2020-01-01,Acme, Inc., 1,000). Matching individual fields @@ -5614,14 +5720,14 @@ CSV FORMAT %CSVFIELD REGEX - which matches just the content of a particular CSV field. CSVFIELD is - a percent sign followed by the field's name or column number, like + which matches just the content of a particular CSV field. CSVFIELD is + a percent sign followed by the field's name or column number, like %date or %1. Combining matchers A single matcher can be written on the same line as the "if"; or multi- ple matchers can be written on the following lines, non-indented. Mul- - tiple matchers are OR'd (any one of them can match), unless one begins + tiple matchers are OR'd (any one of them can match), unless one begins with an & symbol, in which case it is AND'ed with the previous matcher. if @@ -5630,8 +5736,8 @@ CSV FORMAT RULE Rules applied on successful match - After the patterns there should be one or more rules to apply, all - indented by at least one space. Three kinds of rule are allowed in + After the patterns there should be one or more rules to apply, all + indented by at least one space. Three kinds of rule are allowed in conditional blocks: o field assignments (to set a hledger field) @@ -5661,11 +5767,11 @@ CSV FORMAT MATCHER3,VALUE31,VALUE32,...,VALUE3n - Conditional tables ("if tables") are a different syntax to specify - field assignments that will be applied only to CSV records which match + Conditional tables ("if tables") are a different syntax to specify + field assignments that will be applied only to CSV records which match certain patterns. - MATCHER could be either field or record matcher, as described above. + MATCHER could be either field or record matcher, as described above. When MATCHER matches, values from that row would be assigned to the CSV fields named on the if line, in the same order. @@ -5689,17 +5795,17 @@ CSV FORMAT ... CSVFIELDNAMEn VALUE3n - Each line starting with MATCHER should contain enough (possibly empty) + Each line starting with MATCHER should contain enough (possibly empty) values for all the listed fields. - Rules would be checked and applied in the order they are listed in the + Rules would be checked and applied in the order they are listed in the table and, like with if blocks, later rules (in the same or another ta- ble) or if blocks could override the effect of any rule. - Instead of ',' you can use a variety of other non-alphanumeric charac- + Instead of ',' you can use a variety of other non-alphanumeric charac- ters as a separator. First character after if is taken to be the sepa- - rator for the rest of the table. It is the responsibility of the user - to ensure that separator does not occur inside MATCHERs and values - + rator for the rest of the table. It is the responsibility of the user + to ensure that separator does not occur inside MATCHERs and values - there is no way to escape separator. Example: @@ -5710,7 +5816,7 @@ CSV FORMAT 2020/01/12.*Plumbing LLC,expenses:house:upkeep,emergency plumbing call-out end - This rule can be used inside if blocks (only), to make hledger stop + This rule can be used inside if blocks (only), to make hledger stop reading this CSV file and move on to the next input file, or to command execution. Eg: @@ -5721,10 +5827,10 @@ CSV FORMAT date-format date-format DATEFMT - This is a helper for the date (and date2) fields. If your CSV dates - are not formatted like YYYY-MM-DD, YYYY/MM/DD or YYYY.MM.DD, you'll - need to add a date-format rule describing them with a strptime date - parsing pattern, which must parse the CSV date value completely. Some + This is a helper for the date (and date2) fields. If your CSV dates + are not formatted like YYYY-MM-DD, YYYY/MM/DD or YYYY.MM.DD, you'll + need to add a date-format rule describing them with a strptime date + parsing pattern, which must parse the CSV date value completely. Some examples: # MM/DD/YY @@ -5752,22 +5858,22 @@ CSV FORMAT decimal-mark , - hledger automatically accepts either period or comma as a decimal mark - when parsing numbers (cf Amounts). However if any numbers in the CSV - contain digit group marks, such as thousand-separating commas, you - should declare the decimal mark explicitly with this rule, to avoid + hledger automatically accepts either period or comma as a decimal mark + when parsing numbers (cf Amounts). However if any numbers in the CSV + contain digit group marks, such as thousand-separating commas, you + should declare the decimal mark explicitly with this rule, to avoid misparsed numbers. newest-first - hledger always sorts the generated transactions by date. Transactions - on the same date should appear in the same order as their CSV records, - as hledger can usually auto-detect whether the CSV's normal order is + hledger always sorts the generated transactions by date. Transactions + on the same date should appear in the same order as their CSV records, + as hledger can usually auto-detect whether the CSV's normal order is oldest first or newest first. But if all of the following are true: - o the CSV might sometimes contain just one day of data (all records + o the CSV might sometimes contain just one day of data (all records having the same date) - o the CSV records are normally in reverse chronological order (newest + o the CSV records are normally in reverse chronological order (newest at the top) o and you care about preserving the order of same-day transactions @@ -5780,9 +5886,9 @@ CSV FORMAT include include RULESFILE - This includes the contents of another CSV rules file at this point. - RULESFILE is an absolute file path or a path relative to the current - file's directory. This can be useful for sharing common rules between + This includes the contents of another CSV rules file at this point. + RULESFILE is an absolute file path or a path relative to the current + file's directory. This can be useful for sharing common rules between several rules files, eg: # someaccount.csv.rules @@ -5797,10 +5903,10 @@ CSV FORMAT balance-type Balance assertions generated by assigning to balanceN are of the simple - = type by default, which is a single-commodity, subaccount-excluding + = type by default, which is a single-commodity, subaccount-excluding assertion. You may find the subaccount-including variants more useful, - eg if you have created some virtual subaccounts of checking to help - with budgeting. You can select a different type of assertion with the + eg if you have created some virtual subaccounts of checking to help + with budgeting. You can select a different type of assertion with the balance-type rule: # balance assertions will consider all commodities and all subaccounts @@ -5815,19 +5921,19 @@ CSV FORMAT Tips Rapid feedback - It's a good idea to get rapid feedback while creating/troubleshooting + It's a good idea to get rapid feedback while creating/troubleshooting CSV rules. Here's a good way, using entr from http://eradman.com/entr- project : $ ls foo.csv* | entr bash -c 'echo ----; hledger -f foo.csv print desc:SOMEDESC' - A desc: query (eg) is used to select just one, or a few, transactions - of interest. "bash -c" is used to run multiple commands, so we can - echo a separator each time the command re-runs, making it easier to + A desc: query (eg) is used to select just one, or a few, transactions + of interest. "bash -c" is used to run multiple commands, so we can + echo a separator each time the command re-runs, making it easier to read the output. Valid CSV - hledger accepts CSV conforming to RFC 4180. When CSV values are + hledger accepts CSV conforming to RFC 4180. When CSV values are enclosed in quotes, note: o they must be double quotes (not single quotes) @@ -5835,9 +5941,9 @@ CSV FORMAT o spaces outside the quotes are not allowed File Extension - To help hledger identify the format and show the right error messages, - CSV/SSV/TSV files should normally be named with a .csv, .ssv or .tsv - filename extension. Or, the file path should be prefixed with csv:, + To help hledger identify the format and show the right error messages, + CSV/SSV/TSV files should normally be named with a .csv, .ssv or .tsv + filename extension. Or, the file path should be prefixed with csv:, ssv: or tsv:. Eg: $ hledger -f foo.ssv print @@ -5846,48 +5952,48 @@ CSV FORMAT $ cat foo | hledger -f ssv:- foo - You can override the file extension with a separator rule if needed. + You can override the file extension with a separator rule if needed. See also: Input files in the hledger manual. Reading multiple CSV files - If you use multiple -f options to read multiple CSV files at once, - hledger will look for a correspondingly-named rules file for each CSV - file. But if you use the --rules-file option, that rules file will be + If you use multiple -f options to read multiple CSV files at once, + hledger will look for a correspondingly-named rules file for each CSV + file. But if you use the --rules-file option, that rules file will be used for all the CSV files. Valid transactions After reading a CSV file, hledger post-processes and validates the gen- erated journal entries as it would for a journal file - balancing them, - applying balance assignments, and canonicalising amount styles. Any - errors at this stage will be reported in the usual way, displaying the + applying balance assignments, and canonicalising amount styles. Any + errors at this stage will be reported in the usual way, displaying the problem entry. There is one exception: balance assertions, if you have generated them, - will not be checked, since normally these will work only when the CSV - data is part of the main journal. If you do need to check balance + will not be checked, since normally these will work only when the CSV + data is part of the main journal. If you do need to check balance assertions generated from CSV right away, pipe into another hledger: $ hledger -f file.csv print | hledger -f- print Deduplicating, importing - When you download a CSV file periodically, eg to get your latest bank - transactions, the new file may overlap with the old one, containing + When you download a CSV file periodically, eg to get your latest bank + transactions, the new file may overlap with the old one, containing some of the same records. The import command will (a) detect the new transactions, and (b) append just those transactions to your main journal. It is idempotent, so you - don't have to remember how many times you ran it or with which version - of the CSV. (It keeps state in a hidden .latest.FILE.csv file.) This + don't have to remember how many times you ran it or with which version + of the CSV. (It keeps state in a hidden .latest.FILE.csv file.) This is the easiest way to import CSV data. Eg: # download the latest CSV files, then run this command. # Note, no -f flags needed here. $ hledger import *.csv [--dry] - This method works for most CSV files. (Where records have a stable + This method works for most CSV files. (Where records have a stable chronological order, and new records appear only at the new end.) - A number of other tools and workflows, hledger-specific and otherwise, + A number of other tools and workflows, hledger-specific and otherwise, exist for converting, deduplicating, classifying and managing CSV data. See: @@ -5905,8 +6011,8 @@ CSV FORMAT the Nth posting's amount. N is usually 1 or 2 but can go up to 99. 2. If the CSV has separate Debit and Credit amount fields: - Assign to amountN-in and amountN-out. This sets posting N's amount to - whichever of these has a non-zero value, guessing an appropriate sign. + Assign to amountN-in and amountN-out. This sets posting N's amount to + whichever of these has a non-zero value, guessing an appropriate sign. o If hledger guesses the wrong sign: Prepend a minus sign to flip it. Eg: @@ -5916,15 +6022,15 @@ CSV FORMAT o If both fields contain a non-zero value: The amountN-in/amountN-out rules require that each CSV record has a - non-zero value in exactly one of the two fields, so that hledger + non-zero value in exactly one of the two fields, so that hledger knows which to choose. So these would all be rejected: "", "" "0", "0" "1", "none" - If your CSV has amount values like this, use conditional rules - instead. For example, to make hledger to choose the value con- + If your CSV has amount values like this, use conditional rules + instead. For example, to make hledger to choose the value con- taining non-zero digits: fields date, description, in, out @@ -5934,9 +6040,9 @@ CSV FORMAT amount1 %out 3. Using the old numberless syntax: - Assign to amount (or to amount-in and amount-out). This sets posting - 1's and posting 2's amounts (and converts posting 2's amount to cost). - This is supported for backwards compatibility (and occasional conve- + Assign to amount (or to amount-in and amount-out). This sets posting + 1's and posting 2's amounts (and converts posting 2's amount to cost). + This is supported for backwards compatibility (and occasional conve- nience). 4. If the CSV has the balance instead of the transaction amount: @@ -5944,15 +6050,15 @@ CSV FORMAT ance assignment. (Old syntax: balance, equivalent to balance1.) o If hledger guesses the wrong default account name: - When setting the amount via balance assertion, hledger may guess - the wrong default account name. So, set the account name explic- + When setting the amount via balance assertion, hledger may guess + the wrong default account name. So, set the account name explic- itly, eg: fields date, description, balance1 account1 assets:checking Amount signs - There is some special handling for amount signs, to simplify parsing + There is some special handling for amount signs, to simplify parsing and sign-flipping: o If an amount value begins with a plus sign: @@ -5961,17 +6067,17 @@ CSV FORMAT o If an amount value is parenthesised: it will be de-parenthesised and sign-flipped: (AMT) becomes -AMT - o If an amount value has two minus signs (or two sets of parentheses, + o If an amount value has two minus signs (or two sets of parentheses, or a minus sign and parentheses): they cancel out and will be removed: --AMT or -(AMT) becomes AMT - o If an amount value contains just a sign (or just a set of parenthe- + o If an amount value contains just a sign (or just a set of parenthe- ses): - that is removed, making it an empty value. "+" or "-" or "()" becomes + that is removed, making it an empty value. "+" or "-" or "()" becomes "". Setting currency/commodity - If the currency/commodity symbol is included in the CSV's amount + If the currency/commodity symbol is included in the CSV's amount field(s): 2020-01-01,foo,$123.00 @@ -5990,7 +6096,7 @@ CSV FORMAT 2020-01-01,foo,USD,123.00 You can assign that to the currency pseudo-field, which has the special - effect of prepending itself to every amount in the transaction (on the + effect of prepending itself to every amount in the transaction (on the left, with no separating space): fields date,description,currency,amount @@ -5999,7 +6105,7 @@ CSV FORMAT expenses:unknown USD123.00 income:unknown USD-123.00 - Or, you can use a field assignment to construct the amount yourself, + Or, you can use a field assignment to construct the amount yourself, with more control. Eg to put the symbol on the right, and separated by a space: @@ -6010,7 +6116,7 @@ CSV FORMAT expenses:unknown 123.00 USD income:unknown -123.00 USD - Note we used a temporary field name (cur) that is not currency - that + Note we used a temporary field name (cur) that is not currency - that would trigger the prepending effect, which we don't want here. Amount decimal places @@ -6018,13 +6124,13 @@ CSV FORMAT amount1 influence commodity display styles, such as the number of deci- mal places displayed in reports. - The original amounts as written in the CSV file do not affect display + The original amounts as written in the CSV file do not affect display style (because we don't yet reliably know their commodity). Referencing other fields - In field assignments, you can interpolate only CSV fields, not hledger - fields. In the example below, there's both a CSV field and a hledger - field named amount1, but %amount1 always means the CSV field, not the + In field assignments, you can interpolate only CSV fields, not hledger + fields. In the example below, there's both a CSV field and a hledger + field named amount1, but %amount1 always means the CSV field, not the hledger field: # Name the third CSV field "amount1" @@ -6036,7 +6142,7 @@ CSV FORMAT # Set comment to the CSV amount1 (not the amount1 assigned above) comment %amount1 - Here, since there's no CSV amount1 field, %amount1 will produce a lit- + Here, since there's no CSV amount1 field, %amount1 will produce a lit- eral "amount1": fields date,description,csvamount @@ -6044,7 +6150,7 @@ CSV FORMAT # Can't interpolate amount1 here comment %amount1 - When there are multiple field assignments to the same hledger field, + When there are multiple field assignments to the same hledger field, only the last one takes effect. Here, comment's value will be be B, or C if "something" is matched, but never A: @@ -6054,14 +6160,14 @@ CSV FORMAT comment C How CSV rules are evaluated - Here's how to think of CSV rules being evaluated (if you really need + Here's how to think of CSV rules being evaluated (if you really need to). First, - o include - all includes are inlined, from top to bottom, depth first. - (At each include point the file is inlined and scanned for further + o include - all includes are inlined, from top to bottom, depth first. + (At each include point the file is inlined and scanned for further includes, recursively, before proceeding.) - Then "global" rules are evaluated, top to bottom. If a rule is + Then "global" rules are evaluated, top to bottom. If a rule is repeated, the last one wins: o skip (at top level) @@ -6075,33 +6181,33 @@ CSV FORMAT Then for each CSV record in turn: - o test all if blocks. If any of them contain a end rule, skip all + o test all if blocks. If any of them contain a end rule, skip all remaining CSV records. Otherwise if any of them contain a skip rule, - skip that many CSV records. If there are multiple matched skip + skip that many CSV records. If there are multiple matched skip rules, the first one wins. - o collect all field assignments at top level and in matched if blocks. - When there are multiple assignments for a field, keep only the last + o collect all field assignments at top level and in matched if blocks. + When there are multiple assignments for a field, keep only the last one. - o compute a value for each hledger field - either the one that was - assigned to it (and interpolate the %CSVFIELDNAME references), or a + o compute a value for each hledger field - either the one that was + assigned to it (and interpolate the %CSVFIELDNAME references), or a default o generate a synthetic hledger transaction from these values. - This is all part of the CSV reader, one of several readers hledger can - use to parse input files. When all files have been read successfully, - the transactions are passed as input to whichever hledger command the + This is all part of the CSV reader, one of several readers hledger can + use to parse input files. When all files have been read successfully, + the transactions are passed as input to whichever hledger command the user specified. TIMECLOCK FORMAT The time logging format of timeclock.el, as read by hledger. - hledger can read time logs in timeclock format. As with Ledger, these + hledger can read time logs in timeclock format. As with Ledger, these are (a subset of) timeclock.el's format, containing clock-in and clock- - out entries as in the example below. The date is a simple date. The - time format is HH:MM[:SS][+-ZZZZ]. Seconds and timezone are optional. + out entries as in the example below. The date is a simple date. The + time format is HH:MM[:SS][+-ZZZZ]. Seconds and timezone are optional. The timezone, if present, must be four digits and is ignored (currently the time is always interpreted as a local time). @@ -6110,9 +6216,9 @@ TIMECLOCK FORMAT i 2015/03/31 22:21:45 another account o 2015/04/01 02:00:34 - hledger treats each clock-in/clock-out pair as a transaction posting - some number of hours to an account. Or if the session spans more than - one day, it is split into several transactions, one for each day. For + hledger treats each clock-in/clock-out pair as a transaction posting + some number of hours to an account. Or if the session spans more than + one day, it is split into several transactions, one for each day. For the above time log, hledger print generates these journal entries: $ hledger -f t.timeclock print @@ -6133,69 +6239,69 @@ TIMECLOCK FORMAT To generate time logs, ie to clock in and clock out, you could: - o use emacs and the built-in timeclock.el, or the extended timeclock- + o use emacs and the built-in timeclock.el, or the extended timeclock- x.el and perhaps the extras in ledgerutils.el o at the command line, use these bash aliases: shell alias ti="echo - i `date '+%Y-%m-%d %H:%M:%S'` \$* >>$TIMELOG" alias to="echo o + i `date '+%Y-%m-%d %H:%M:%S'` \$* >>$TIMELOG" alias to="echo o `date '+%Y-%m-%d %H:%M:%S'` >>$TIMELOG" o or use the old ti and to scripts in the ledger 2.x repository. These - rely on a "timeclock" executable which I think is just the ledger 2 + rely on a "timeclock" executable which I think is just the ledger 2 executable renamed. TIMEDOT FORMAT hledger's human-friendly time logging format. - Timedot is a plain text format for logging dated, categorised quanti- - ties (of time, usually), supported by hledger. It is convenient for - approximate and retroactive time logging, eg when the real-time clock- - in/out required with a timeclock file is too precise or too interrup- - tive. It can be formatted like a bar chart, making clear at a glance + Timedot is a plain text format for logging dated, categorised quanti- + ties (of time, usually), supported by hledger. It is convenient for + approximate and retroactive time logging, eg when the real-time clock- + in/out required with a timeclock file is too precise or too interrup- + tive. It can be formatted like a bar chart, making clear at a glance where time was spent. - Though called "timedot", this format is read by hledger as commodity- - less quantities, so it could be used to represent dated quantities + Though called "timedot", this format is read by hledger as commodity- + less quantities, so it could be used to represent dated quantities other than time. In the docs below we'll assume it's time. - A timedot file contains a series of day entries. A day entry begins - with a non-indented hledger-style simple date (Y-M-D, Y/M/D, Y.M.D..) - Any additional text on the same line is used as a transaction descrip- + A timedot file contains a series of day entries. A day entry begins + with a non-indented hledger-style simple date (Y-M-D, Y/M/D, Y.M.D..) + Any additional text on the same line is used as a transaction descrip- tion for this day. This is followed by optionally-indented timelog items for that day, one - per line. Each timelog item is a note, usually a - hledger:style:account:name representing a time category, followed by - two or more spaces, and a quantity. Each timelog item generates a + per line. Each timelog item is a note, usually a + hledger:style:account:name representing a time category, followed by + two or more spaces, and a quantity. Each timelog item generates a hledger transaction. Quantities can be written as: - o dots: a sequence of dots (.) representing quarter hours. Spaces may + o dots: a sequence of dots (.) representing quarter hours. Spaces may optionally be used for grouping. Eg: .... .. o an integral or decimal number, representing hours. Eg: 1.5 - o an integral or decimal number immediately followed by a unit symbol - s, m, h, d, w, mo, or y, representing seconds, minutes, hours, days + o an integral or decimal number immediately followed by a unit symbol + s, m, h, d, w, mo, or y, representing seconds, minutes, hours, days weeks, months or years respectively. Eg: 90m. The following equiva- - lencies are assumed, currently: 1m = 60s, 1h = 60m, 1d = 24h, 1w = + lencies are assumed, currently: 1m = 60s, 1h = 60m, 1d = 24h, 1w = 7d, 1mo = 30d, 1y=365d. - There is some flexibility allowing notes and todo lists to be kept + There is some flexibility allowing notes and todo lists to be kept right in the time log, if needed: o Blank lines and lines beginning with # or ; are ignored. o Lines not ending with a double-space and quantity are parsed as items - taking no time, which will not appear in balance reports by default. + taking no time, which will not appear in balance reports by default. (Add -E to see them.) - o Org mode headlines (lines beginning with one or more * followed by a - space) can be used as date lines or timelog items (the stars are - ignored). Also all org headlines before the first date line are - ignored. This means org users can manage their timelog as an org - outline (eg using org-mode/orgstruct-mode in Emacs), for organisa- + o Org mode headlines (lines beginning with one or more * followed by a + space) can be used as date lines or timelog items (the stars are + ignored). Also all org headlines before the first date line are + ignored. This means org users can manage their timelog as an org + outline (eg using org-mode/orgstruct-mode in Emacs), for organisa- tion, faster navigation, controlling visibility etc. Examples: @@ -6260,7 +6366,7 @@ TIMEDOT FORMAT ------------++---------------------------------------- || 7.75 2.25 8.00 - I prefer to use period for separating account components. We can make + I prefer to use period for separating account components. We can make this work with an account alias: 2016/2/4 @@ -6277,9 +6383,9 @@ TIMEDOT FORMAT Here is a sample.timedot. COMMON TASKS - Here are some quick examples of how to do some basic tasks with - hledger. For more details, see the reference section below, the - hledger_journal(5) manual, or the more extensive docs at + Here are some quick examples of how to do some basic tasks with + hledger. For more details, see the reference section below, the + hledger_journal(5) manual, or the more extensive docs at https://hledger.org. Getting help @@ -6295,26 +6401,26 @@ COMMON TASKS https://hledger.org#help-feedback Constructing command lines - hledger has an extensive and powerful command line interface. We + hledger has an extensive and powerful command line interface. We strive to keep it simple and ergonomic, but you may run into one of the confusing real world details described in OPTIONS, below. If that hap- pens, here are some tips that may help: - o command-specific options must go after the command (it's fine to put + o command-specific options must go after the command (it's fine to put all options there) (hledger CMD OPTS ARGS) - o running add-on executables directly simplifies command line parsing + o running add-on executables directly simplifies command line parsing (hledger-ui OPTS ARGS) o enclose "problematic" args in single quotes - o if needed, also add a backslash to hide regular expression metachar- + o if needed, also add a backslash to hide regular expression metachar- acters from the shell o to see how a misbehaving command is being parsed, add --debug=2. Starting a journal file - hledger looks for your accounting data in a journal file, + hledger looks for your accounting data in a journal file, $HOME/.hledger.journal by default: $ hledger stats @@ -6322,9 +6428,9 @@ COMMON TASKS Please create it first, eg with "hledger add" or a text editor. Or, specify an existing journal file with -f or LEDGER_FILE. - You can override this by setting the LEDGER_FILE environment variable. + You can override this by setting the LEDGER_FILE environment variable. It's a good practice to keep this important file under version control, - and to start a new file each year. So you could do something like + and to start a new file each year. So you could do something like this: $ mkdir ~/finance @@ -6348,20 +6454,20 @@ COMMON TASKS Market prices : 0 () Setting opening balances - Pick a starting date for which you can look up the balances of some - real-world assets (bank accounts, wallet..) and liabilities (credit + Pick a starting date for which you can look up the balances of some + real-world assets (bank accounts, wallet..) and liabilities (credit cards..). - To avoid a lot of data entry, you may want to start with just one or - two accounts, like your checking account or cash wallet; and pick a - recent starting date, like today or the start of the week. You can + To avoid a lot of data entry, you may want to start with just one or + two accounts, like your checking account or cash wallet; and pick a + recent starting date, like today or the start of the week. You can always come back later and add more accounts and older transactions, eg going back to january 1st. - Add an opening balances transaction to the journal, declaring the bal- + Add an opening balances transaction to the journal, declaring the bal- ances on this date. Here are two ways to do it: - o The first way: open the journal in any text editor and save an entry + o The first way: open the journal in any text editor and save an entry like this: 2020-01-01 * opening balances @@ -6371,19 +6477,19 @@ COMMON TASKS liabilities:creditcard $-50 = $-50 equity:opening/closing balances - These are start-of-day balances, ie whatever was in the account at + These are start-of-day balances, ie whatever was in the account at the end of the previous day. - The * after the date is an optional status flag. Here it means + The * after the date is an optional status flag. Here it means "cleared & confirmed". - The currency symbols are optional, but usually a good idea as you'll + The currency symbols are optional, but usually a good idea as you'll be dealing with multiple currencies sooner or later. - The = amounts are optional balance assertions, providing extra error + The = amounts are optional balance assertions, providing extra error checking. - o The second way: run hledger add and follow the prompts to record a + o The second way: run hledger add and follow the prompts to record a similar transaction: $ hledger add @@ -6420,18 +6526,18 @@ COMMON TASKS Starting the next transaction (. or ctrl-D/ctrl-C to quit) Date [2020-01-01]: . - If you're using version control, this could be a good time to commit + If you're using version control, this could be a good time to commit the journal. Eg: $ git commit -m 'initial balances' 2020.journal Recording transactions - As you spend or receive money, you can record these transactions using - one of the methods above (text editor, hledger add) or by using the - hledger-iadd or hledger-web add-ons, or by using the import command to + As you spend or receive money, you can record these transactions using + one of the methods above (text editor, hledger add) or by using the + hledger-iadd or hledger-web add-ons, or by using the import command to convert CSV data downloaded from your bank. - Here are some simple transactions, see the hledger_journal(5) manual + Here are some simple transactions, see the hledger_journal(5) manual and hledger.org for more ideas: 2020/1/10 * gift received @@ -6447,22 +6553,22 @@ COMMON TASKS assets:bank:checking $1000 Reconciling - Periodically you should reconcile - compare your hledger-reported bal- - ances against external sources of truth, like bank statements or your - bank's website - to be sure that your ledger accurately represents the - real-world balances (and, that the real-world institutions have not - made a mistake!). This gets easy and fast with (1) practice and (2) - frequency. If you do it daily, it can take 2-10 minutes. If you let - it pile up, expect it to take longer as you hunt down errors and dis- + Periodically you should reconcile - compare your hledger-reported bal- + ances against external sources of truth, like bank statements or your + bank's website - to be sure that your ledger accurately represents the + real-world balances (and, that the real-world institutions have not + made a mistake!). This gets easy and fast with (1) practice and (2) + frequency. If you do it daily, it can take 2-10 minutes. If you let + it pile up, expect it to take longer as you hunt down errors and dis- crepancies. A typical workflow: - 1. Reconcile cash. Count what's in your wallet. Compare with what - hledger reports (hledger bal cash). If they are different, try to - remember the missing transaction, or look for the error in the - already-recorded transactions. A register report can be helpful - (hledger reg cash). If you can't find the error, add an adjustment + 1. Reconcile cash. Count what's in your wallet. Compare with what + hledger reports (hledger bal cash). If they are different, try to + remember the missing transaction, or look for the error in the + already-recorded transactions. A register report can be helpful + (hledger reg cash). If you can't find the error, add an adjustment transaction. Eg if you have $105 after the above, and can't explain the missing $2, it could be: @@ -6472,26 +6578,26 @@ COMMON TASKS 2. Reconcile checking. Log in to your bank's website. Compare today's (cleared) balance with hledger's cleared balance (hledger bal check- - ing -C). If they are different, track down the error or record the - missing transaction(s) or add an adjustment transaction, similar to + ing -C). If they are different, track down the error or record the + missing transaction(s) or add an adjustment transaction, similar to the above. Unlike the cash case, you can usually compare the trans- - action history and running balance from your bank with the one - reported by hledger reg checking -C. This will be easier if you - generally record transaction dates quite similar to your bank's + action history and running balance from your bank with the one + reported by hledger reg checking -C. This will be easier if you + generally record transaction dates quite similar to your bank's clearing dates. 3. Repeat for other asset/liability accounts. - Tip: instead of the register command, use hledger-ui to see a live- + Tip: instead of the register command, use hledger-ui to see a live- updating register while you edit the journal: hledger-ui --watch --reg- ister checking -C - After reconciling, it could be a good time to mark the reconciled - transactions' status as "cleared and confirmed", if you want to track - that, by adding the * marker. Eg in the paycheck transaction above, + After reconciling, it could be a good time to mark the reconciled + transactions' status as "cleared and confirmed", if you want to track + that, by adding the * marker. Eg in the paycheck transaction above, insert * between 2020-01-15 and paycheck - If you're using version control, this can be another good time to com- + If you're using version control, this can be another good time to com- mit: $ git commit -m 'txns' 2020.journal @@ -6563,7 +6669,7 @@ COMMON TASKS -------------------- 0 - Show only asset and liability balances, as a flat list, limited to + Show only asset and liability balances, as a flat list, limited to depth 2: $ hledger bal assets liabilities --flat -2 @@ -6573,7 +6679,7 @@ COMMON TASKS -------------------- $4055 - Show the same thing without negative numbers, formatted as a simple + Show the same thing without negative numbers, formatted as a simple balance sheet: $ hledger bs --flat -2 @@ -6640,15 +6746,15 @@ COMMON TASKS 2020-01-13 **** Migrating to a new file - At the end of the year, you may want to continue your journal in a new + At the end of the year, you may want to continue your journal in a new file, so that old transactions don't slow down or clutter your reports, - and to help ensure the integrity of your accounting history. See the + and to help ensure the integrity of your accounting history. See the close command. If using version control, don't forget to git add the new file. LIMITATIONS - The need to precede add-on command options with -- when invoked from + The need to precede add-on command options with -- when invoked from hledger is awkward. When input data contains non-ascii characters, a suitable system locale @@ -6664,36 +6770,36 @@ LIMITATIONS In a Cygwin/MSYS/Mintty window, the tab key is not supported in hledger add. - Not all of Ledger's journal file syntax is supported. See file format + Not all of Ledger's journal file syntax is supported. See file format differences. - On large data files, hledger is slower and uses more memory than + On large data files, hledger is slower and uses more memory than Ledger. TROUBLESHOOTING - Here are some issues you might encounter when you run hledger (and - remember you can also seek help from the IRC channel, mail list or bug + Here are some issues you might encounter when you run hledger (and + remember you can also seek help from the IRC channel, mail list or bug tracker): Successfully installed, but "No command 'hledger' found" stack and cabal install binaries into a special directory, which should - be added to your PATH environment variable. Eg on unix-like systems, + be added to your PATH environment variable. Eg on unix-like systems, that is ~/.local/bin and ~/.cabal/bin respectively. I set a custom LEDGER_FILE, but hledger is still using the default file - LEDGER_FILE should be a real environment variable, not just a shell - variable. The command env | grep LEDGER_FILE should show it. You may + LEDGER_FILE should be a real environment variable, not just a shell + variable. The command env | grep LEDGER_FILE should show it. You may need to use export. Here's an explanation. - Getting errors like "Illegal byte sequence" or "Invalid or incomplete - multibyte or wide character" or "commitAndReleaseBuffer: invalid argu- + Getting errors like "Illegal byte sequence" or "Invalid or incomplete + multibyte or wide character" or "commitAndReleaseBuffer: invalid argu- ment (invalid character)" Programs compiled with GHC (hledger, haskell build tools, etc.) need to have a UTF-8-aware locale configured in the environment, otherwise they - will fail with these kinds of errors when they encounter non-ascii + will fail with these kinds of errors when they encounter non-ascii characters. - To fix it, set the LANG environment variable to some locale which sup- + To fix it, set the LANG environment variable to some locale which sup- ports UTF-8. The locale you choose must be installed on your system. Here's an example of setting LANG temporarily, on Ubuntu GNU/Linux: @@ -6708,8 +6814,8 @@ TROUBLESHOOTING POSIX $ LANG=en_US.utf8 hledger -f my.journal print # ensure it is used for this command - If available, C.UTF-8 will also work. If your preferred locale isn't - listed by locale -a, you might need to install it. Eg on + If available, C.UTF-8 will also work. If your preferred locale isn't + listed by locale -a, you might need to install it. Eg on Ubuntu/Debian: $ apt-get install language-pack-fr @@ -6729,8 +6835,8 @@ TROUBLESHOOTING $ echo "export LANG=en_US.utf8" >>~/.bash_profile $ bash --login - Exact spelling and capitalisation may be important. Note the differ- - ence on MacOS (UTF-8, not utf8). Some platforms (eg ubuntu) allow + Exact spelling and capitalisation may be important. Note the differ- + ence on MacOS (UTF-8, not utf8). Some platforms (eg ubuntu) allow variant spellings, but others (eg macos) require it to be exact: $ locale -a | grep -iE en_us.*utf @@ -6740,7 +6846,7 @@ TROUBLESHOOTING REPORTING BUGS - Report bugs at http://bugs.hledger.org (or on the #hledger IRC channel + Report bugs at http://bugs.hledger.org (or on the #hledger IRC channel or hledger mail list)