All Projects → sboehler → knut

sboehler / knut

Licence: Apache-2.0 license
knut is an efficient plain text accounting tool with support for multiple currencies and valuation.

Programming Languages

go
31211 projects - #10 most used programming language
Makefile
30231 projects

Projects that are alternatives of or similar to knut

Akaunting
Free and Online Accounting Software
Stars: ✭ 4,599 (+11397.5%)
Mutual labels:  finance, balance, accounting
ledg
Batch modifiable ledger-like written in nodejs
Stars: ✭ 32 (-20%)
Mutual labels:  accounting, ledger, plaintext-accounting
Ledger
Double-entry accounting system with a command-line reporting interface
Stars: ✭ 4,062 (+10055%)
Mutual labels:  accounting, ledger, plaintext-accounting
Transity
Keep track of your 💵, 🕘, 🐖, 🐄, 🍻 on your command line
Stars: ✭ 528 (+1220%)
Mutual labels:  finance, accounting, ledger
nledger
.Net Ledger: Double-Entry Accounting System
Stars: ✭ 141 (+252.5%)
Mutual labels:  accounting, ledger, plaintext-accounting
Hledger
A reliable, user-friendly Plain Text Accounting tool with command line, terminal and web interfaces.
Stars: ✭ 1,887 (+4617.5%)
Mutual labels:  accounting, ledger, plaintext-accounting
awesome-beancount
Awesome Beancount Resources
Stars: ✭ 114 (+185%)
Mutual labels:  finance, accounting, plaintext-accounting
Budget
Get a grip on your finances.
Stars: ✭ 609 (+1422.5%)
Mutual labels:  finance, accounting
Gooderp addons
可能是中国用户数最多的开源ERP
Stars: ✭ 1,315 (+3187.5%)
Mutual labels:  finance, accounting
Moneygo
An accounting web application to track personal finances written in Go and React/Bootstrap
Stars: ✭ 138 (+245%)
Mutual labels:  finance, accounting
Learnpythonforresearch
This repository provides everything you need to get started with Python for (social science) research.
Stars: ✭ 163 (+307.5%)
Mutual labels:  finance, accounting
hledger-iadd
A terminal UI as drop-in replacement for hledger add.
Stars: ✭ 61 (+52.5%)
Mutual labels:  ledger, plaintext-accounting
bankster
Money Creation Made Easy
Stars: ✭ 30 (-25%)
Mutual labels:  finance, ledger
ledgible
Web-based double-entry accounting (ledger-cli frontend)
Stars: ✭ 58 (+45%)
Mutual labels:  ledger, plaintext-accounting
Double entry
A double-entry accounting system for Ruby applications.
Stars: ✭ 276 (+590%)
Mutual labels:  finance, accounting
Django Ledger
A bookkeeping & financial analysis engine for the Django Framework. UNDER ACTIVE DEVELOPMENT & NOT STABLE YET.
Stars: ✭ 253 (+532.5%)
Mutual labels:  finance, accounting
finac
Finac - financial accounting for humans
Stars: ✭ 27 (-32.5%)
Mutual labels:  finance, accounting
ledger2beancount
Ledger to Beancount text-based converter
Stars: ✭ 63 (+57.5%)
Mutual labels:  accounting, ledger
python api client
A Python client for Calcbench's API.
Stars: ✭ 16 (-60%)
Mutual labels:  finance, accounting
beancount-boilerplate-cn
docs.google.com/spreadsheets/d/1jnds3X_-RSTN4ATuOFV-v6tar0KfAla88vC43Vq6ubc/edit#gid=0
Stars: ✭ 186 (+365%)
Mutual labels:  ledger, plaintext-accounting

knut ‒ a plain text accounting tool

Go

there are 29 knuts in a sickle

knut is a plain-text, double-entry accounting tool for the command line. It produces various reports based on simple accounting directives in a text file. knut is written in Go, and its primary use cases are personal finance and investing.

$ knut balance -v CHF --months --from 2020-01-01 --to 2020-04-01 doc/example.knut
+---------------+------------+------------+------------+------------+
|    Account    | 2020-01-31 | 2020-02-29 | 2020-03-31 | 2020-04-30 |
+---------------+------------+------------+------------+------------+
| Assets        |            |            |            |            |
|   BankAccount |     11,800 |     14,127 |     14,127 |     14,127 |
|   Portfolio   |      1,025 |        919 |        856 |        984 |
|               |            |            |            |            |
| Total         |     12,825 |     15,046 |     14,983 |     15,111 |
+---------------+------------+------------+------------+------------+
| Equity        |            |            |            |            |
|   Equity      |     10,003 |     10,003 |     10,003 |     10,003 |
|   Valuation   |            |            |            |            |
|     Portfolio |         26 |        -80 |       -143 |        -15 |
|               |            |            |            |            |
| Income        |            |            |            |            |
|   Salary      |      5,000 |     10,000 |     10,000 |     10,000 |
|               |            |            |            |            |
| Expenses      |            |            |            |            |
|   Rent        |     -2,000 |     -4,000 |     -4,000 |     -4,000 |
|   Groceries   |       -200 |       -873 |       -873 |       -873 |
|   Fees        |         -4 |         -4 |         -4 |         -4 |
|               |            |            |            |            |
| Total         |     12,825 |     15,046 |     14,983 |     15,111 |
+---------------+------------+------------+------------+------------+
| Delta         |            |            |            |            |
+---------------+------------+------------+------------+------------+


Table of contents

Commands

$ knut --help
knut is a plain text accounting tool for tracking personal finances and investments.

Usage:
  knut [command]

Available Commands:
  balance     create a balance sheet
  benchmark   various subcommands to benchmark knut
  completion  output shell completion code [bash|zsh]
  fetch       Fetch quotes from Yahoo! Finance
  format      Format the given journal
  help        Help about any command
  import      Import financial account statements
  infer       Auto-assign accounts in a journal
  transcode   transcode to beancount

Flags:
  -h, --help      help for knut
  -v, --version   version for knut

Use "knut [command] --help" for more information about a command.

Print a balance

knut has a powerful balance command, with various options to tune the result.

Basic balance

Without additional options, knut will print a balance with counts of the various commodities per account.

$ knut balance doc/example.knut --to 2020-04-01
+---------------+------------+
|    Account    | 2020-04-01 |
+---------------+------------+
| Assets        |            |
|   BankAccount |            |
|     CHF       |     14,127 |
|   Portfolio   |            |
|     AAPL      |         12 |
|     CHF       |         31 |
|     USD       |         97 |
|               |            |
| Total         |            |
|   AAPL        |         12 |
|   CHF         |     14,158 |
|   USD         |         97 |
+---------------+------------+
| Equity        |            |
|   Equity      |            |
|     AAPL      |         12 |
|     CHF       |      9,031 |
|     USD       |        101 |
|               |            |
| Income        |            |
|   Salary      |            |
|     CHF       |     10,000 |
|               |            |
| Expenses      |            |
|   Rent        |            |
|     CHF       |     -4,000 |
|   Groceries   |            |
|     CHF       |       -873 |
|   Fees        |            |
|     USD       |         -4 |
|               |            |
| Total         |            |
|   AAPL        |         12 |
|   CHF         |     14,158 |
|   USD         |         97 |
+---------------+------------+
| Delta         |            |
+---------------+------------+


Monthly balance in a given commodity

If prices are available, knut can valuate the balance in any of the available commodities. And the result is guaranteed to balance:

$ knut balance -v CHF --months --to 2020-04-01 doc/example.knut
+---------------+------------+------------+------------+------------+------------+
|    Account    | 2019-12-31 | 2020-01-31 | 2020-02-29 | 2020-03-31 | 2020-04-30 |
+---------------+------------+------------+------------+------------+------------+
| Assets        |            |            |            |            |            |
|   BankAccount |     10,000 |     11,800 |     14,127 |     14,127 |     14,127 |
|   Portfolio   |            |      1,025 |        919 |        856 |        984 |
|               |            |            |            |            |            |
| Total         |     10,000 |     12,825 |     15,046 |     14,983 |     15,111 |
+---------------+------------+------------+------------+------------+------------+
| Equity        |            |            |            |            |            |
|   Equity      |     10,000 |     10,003 |     10,003 |     10,003 |     10,003 |
|   Valuation   |            |            |            |            |            |
|     Portfolio |            |         26 |        -80 |       -143 |        -15 |
|               |            |            |            |            |            |
| Income        |            |            |            |            |            |
|   Salary      |            |      5,000 |     10,000 |     10,000 |     10,000 |
|               |            |            |            |            |            |
| Expenses      |            |            |            |            |            |
|   Rent        |            |     -2,000 |     -4,000 |     -4,000 |     -4,000 |
|   Groceries   |            |       -200 |       -873 |       -873 |       -873 |
|   Fees        |            |         -4 |         -4 |         -4 |         -4 |
|               |            |            |            |            |            |
| Total         |     10,000 |     12,825 |     15,046 |     14,983 |     15,111 |
+---------------+------------+------------+------------+------------+------------+
| Delta         |            |            |            |            |            |
+---------------+------------+------------+------------+------------+------------+


It balances in any currency:

$ knut balance -v USD --months --to 2020-04-01 doc/example.knut
+-----------------+------------+------------+------------+------------+------------+
|     Account     | 2019-12-31 | 2020-01-31 | 2020-02-29 | 2020-03-31 | 2020-04-30 |
+-----------------+------------+------------+------------+------------+------------+
| Assets          |            |            |            |            |            |
|   BankAccount   |     10,324 |     12,172 |     14,583 |     14,716 |     14,506 |
|   Portfolio     |            |      1,058 |        949 |        892 |      1,010 |
|                 |            |            |            |            |            |
| Total           |     10,324 |     13,230 |     15,532 |     15,608 |     15,516 |
+-----------------+------------+------------+------------+------------+------------+
| Equity          |            |            |            |            |            |
|   Equity        |     10,324 |     10,327 |     10,327 |     10,327 |     10,327 |
|   Valuation     |            |            |            |            |            |
|     BankAccount |            |         -5 |         55 |        188 |        -22 |
|     Portfolio   |            |         29 |        -80 |       -136 |        -18 |
|                 |            |            |            |            |            |
| Income          |            |            |            |            |            |
|   Salary        |            |      5,157 |     10,260 |     10,260 |     10,260 |
|                 |            |            |            |            |            |
| Expenses        |            |            |            |            |            |
|   Rent          |            |     -2,067 |     -4,130 |     -4,130 |     -4,130 |
|   Groceries     |            |       -207 |       -896 |       -896 |       -896 |
|   Fees          |            |         -4 |         -4 |         -4 |         -4 |
|                 |            |            |            |            |            |
| Total           |     10,324 |     13,230 |     15,532 |     15,608 |     15,516 |
+-----------------+------------+------------+------------+------------+------------+
| Delta           |            |            |            |            |            |
+-----------------+------------+------------+------------+------------+------------+


Filter transactions by account or commodity

Use --diff to look into period differences. Use --account to filter for transactions affecting a single account, or --commodity to filter for transactions which affect a commodity. Both --account and --commodity take regular expressions, to select multiple matches.

$ knut balance -v CHF --months --from 2020-01-01 --to 2020-04-01 --diff --account Portfolio doc/example.knut
+---------------+------------+------------+------------+------------+
|    Account    | 2020-01-31 | 2020-02-29 | 2020-03-31 | 2020-04-30 |
+---------------+------------+------------+------------+------------+
| Assets        |            |            |            |            |
|   BankAccount |     -1,000 |            |            |            |
|   Portfolio   |      1,025 |       -106 |        -63 |        127 |
|               |            |            |            |            |
| Total         |         25 |       -106 |        -63 |        127 |
+---------------+------------+------------+------------+------------+
| Equity        |            |            |            |            |
|   Valuation   |            |            |            |            |
|     Portfolio |         26 |       -106 |        -63 |        127 |
|   Equity      |          3 |            |            |            |
|               |            |            |            |            |
| Expenses      |            |            |            |            |
|   Fees        |         -4 |            |            |            |
|               |            |            |            |            |
| Total         |         25 |       -106 |        -63 |        127 |
+---------------+------------+------------+------------+------------+
| Delta         |            |            |            |            |
+---------------+------------+------------+------------+------------+


$ knut balance -v CHF --months --from 2020-01-01 --to 2020-04-01 --diff --commodity AAPL doc/example.knut
+---------------+------------+------------+------------+------------+
|    Account    | 2020-01-31 | 2020-02-29 | 2020-03-31 | 2020-04-30 |
+---------------+------------+------------+------------+------------+
| Assets        |            |            |            |            |
|   Portfolio   |        900 |       -106 |        -62 |        126 |
|               |            |            |            |            |
| Total         |        900 |       -106 |        -62 |        126 |
+---------------+------------+------------+------------+------------+
| Equity        |            |            |            |            |
|   Equity      |        874 |            |            |            |
|   Valuation   |            |            |            |            |
|     Portfolio |         26 |       -106 |        -62 |        126 |
|               |            |            |            |            |
| Total         |        900 |       -106 |        -62 |        126 |
+---------------+------------+------------+------------+------------+
| Delta         |            |            |            |            |
+---------------+------------+------------+------------+------------+


Collapse accounts

Use -m to map accounts matching a certain regex to a reduced number of segments. This can be used to completely hide an account (-m0 - its positions will show up in the delta):

$ knut balance -v CHF --months --from 2020-01-01 --to 2020-04-01 --diff -m0,(Income|Expenses) doc/example.knut
+---------------+------------+------------+------------+------------+
|    Account    | 2020-01-31 | 2020-02-29 | 2020-03-31 | 2020-04-30 |
+---------------+------------+------------+------------+------------+
| Assets        |            |            |            |            |
|   BankAccount |     11,800 |      2,327 |            |            |
|   Portfolio   |      1,025 |       -106 |        -63 |        127 |
|               |            |            |            |            |
| Total         |     12,825 |      2,221 |        -63 |        127 |
+---------------+------------+------------+------------+------------+
| Equity        |            |            |            |            |
|   Equity      |     10,003 |            |            |            |
|   Valuation   |            |            |            |            |
|     Portfolio |         26 |       -106 |        -63 |        127 |
|               |            |            |            |            |
| Total         |     10,029 |       -106 |        -63 |        127 |
+---------------+------------+------------+------------+------------+
| Delta         |      2,796 |      2,327 |            |            |
+---------------+------------+------------+------------+------------+


Alternatively, with a number > 0, subaccounts will be aggregated:

$ knut balance -v CHF --months --from 2020-01-01 --to 2020-04-01 --diff -m1,(Income|Expenses|Equity) doc/example.knut
+---------------+------------+------------+------------+------------+
|    Account    | 2020-01-31 | 2020-02-29 | 2020-03-31 | 2020-04-30 |
+---------------+------------+------------+------------+------------+
| Assets        |            |            |            |            |
|   BankAccount |     11,800 |      2,327 |            |            |
|   Portfolio   |      1,025 |       -106 |        -63 |        127 |
|               |            |            |            |            |
| Total         |     12,825 |      2,221 |        -63 |        127 |
+---------------+------------+------------+------------+------------+
| Equity        |     10,029 |       -106 |        -63 |        127 |
|               |            |            |            |            |
| Income        |      5,000 |      5,000 |            |            |
|               |            |            |            |            |
| Expenses      |     -2,204 |     -2,673 |            |            |
|               |            |            |            |            |
| Total         |     12,825 |      2,221 |        -63 |        127 |
+---------------+------------+------------+------------+------------+
| Delta         |            |            |            |            |
+---------------+------------+------------+------------+------------+


Fetch quotes

knut price sources are configured in yaml format:

# doc/prices.yaml
- commodity: "USD"
  target_commodity: "CHF"
  file: "USD.prices"
  symbol: "USDCHF=X"
- commodity: "AAPL"
  target_commodity: "USD"
  file: "AAPL.prices"
  symbol: "AAPL"

Once configured, prices can be updated with one command:

knut fetch doc/prices.yaml

Infer accounts

knut has a built-in Bayes engine to automatically assign accounts for new transactions. Simply use TBD as the account in a transaction and let knut decide how to replace it, based on previous entries. The bigger the journal, the more reliable this mechanism becomes.

knut infer -t doc/example.knut doc/example.knut

Format the journal

knut can format a journal, such that accounts and numbers are aligned. Any comments and whitespace between directives are preserved.

knut format doc/example.knut

Import transactions

knut has a few built-in importers for statements from Swiss banks:

$ knut import --help
Import financial account statements

Usage:
  knut import [command]

Available Commands:
  ch.cumulus            Import Cumulus credit card statements
  ch.postfinance        Import Postfinance CSV account statements
  ch.swisscard          Import Swisscard credit card statements
  ch.swissquote         Import Swissquote account reports
  ch.viac               Import VIAC values from JSON files
  revolut               Import Revolut CSV account statements
  us.interactivebrokers Import Interactive Brokers account reports

Flags:
  -h, --help   help for import

Use "knut import [command] --help" for more information about a command.

Transcode to beancount

While knut has advanced terminal-based visualization options, it lacks any web-based visualization tools. To allow the usage of the amazing tooling around the beancount ecosystem, such as fava, knut has a command to convert an entire journal into beancount's file format:

knut transcode -c CHF doc/example.knut

This command should also allow beancount users to use knut's built-in importers.

Editor support

There is an experimental Visual Studio Code extension which provides syntax highlighting, code folding and an outline view.

File format

An accounting journal in knut is represented as a sequence of plain-text directives. The journal consists of a set of directives and comments. Directives are prices, account openings, transactions, value directives, balance assertions, and account closings. Lines starting with either # (comment) or * (org-mode title) are ignored. Files can include other files using an include directive. The order of the directives in the journal file is not important, they are always evaluated by date.

The following is an example for a knut journal:

# doc/example.knut
include "USD.prices"
include "AAPL.prices"

* Open Accounts

2019-12-31 open Equity:Equity
2019-12-31 open Assets:BankAccount
2019-12-31 open Assets:Portfolio

2019-12-31 open Expenses:Groceries
2019-12-31 open Expenses:Fees
2019-12-31 open Expenses:Rent

2019-12-31 open Income:Salary
2019-12-31 open Income:Dividends

* Opening Balances

2019-12-31 "Opening balance"
Equity:Equity           Assets:BankAccount           10000 CHF

* 2020-01

2020-01-25 "Salary January 2020"
Income:Salary           Assets:BankAccount            5000 CHF

2020-01-02 "Rent January"
Assets:BankAccount      Expenses:Rent                 2000 CHF

2020-01-15 "Groceries"
Assets:BankAccount      Expenses:Groceries             200 CHF

2020-01-05 "Transfer to portfolio"
Assets:BankAccount      Assets:Portfolio              1000 CHF

2020-01-06 "Currency exchange"
Equity:Equity           Assets:Portfolio              1001 USD
Assets:Portfolio        Equity:Equity                  969 CHF

2020-01-06 "Buy 12 AAPL shares"
Equity:Equity           Assets:Portfolio                12 AAPL
Assets:Portfolio        Equity:Equity                  900 USD
Assets:Portfolio        Expenses:Fees                    4 USD

* 2020-02

2020-02-25 "Salary January 2020"
Income:Salary           Assets:BankAccount            5000 CHF

2020-02-02 "Rent January"
Assets:BankAccount      Expenses:Rent                 2000 CHF

2020-02-05 "Groceries"
Assets:BankAccount      Expenses:Groceries             250 CHF

2020-02-25 "Groceries"
Assets:BankAccount      Expenses:Groceries             423 CHF

Open and close

An account consists of a sequence of segments, separated by ':'. The first segment must be one of Assets, Liabilities, Equity, Income, Expenses or TBD. Before an account can be used in a transaction, for example, it must be opened using an open directive:

YYYY-MM-DD open <account name>

Once an account is not needed anymore, it can be closed, to prevent further bookings. An account can only be closed if its balance is zero at the closing time.

YYYY-MM-DD close <account name>

Transactions

A transaction describes the flow of money between multiple accounts. Transaction always balance by design in knut.

YYYY-MM-DD "<description>"
<credit account> <debit account> <amount> <commodity>
<credit account> <debit account> <amount> <commodity>
...

A transaction starts with a date, followed by a description withing double quotes on the same line. It must have one or more bookings on the lines immediately following. Every booking references two accounts, a credit account (first) and a debit account (second). The amount is usually a positive numbers, and the semantics is that money "flows from left to right".

The transaction syntax deviates from similar tools like ledger or beancount for several reasons:

  • It ensures that a transaction always balances, which is not guaranteed by formats where each booking references only one account.
  • It creates unambigous flows between two accounts, which is helpful when analyzing the flows of money.
  • The representation is more compact.

Accruals (experimental)

Accruals are annotation placed on transactions to describe how the transaction's flows are to be broken up over time. Suppose you pay your yearly tax bill for 2020 on 24 March of that same year:

2020-03-24 "2020 Taxes"
Assets:BankAccount Expenses:Taxes 12000 USD

This will heavily impact your net income in March due to the large cash outflow, while the taxes are actually owed for the entire year. Enter accruals:

@accrue monthly 2020-01-01 2020-12-01 Assets:PrepaidTax
2020-03-24 "2020 Taxes"
Assets:BankAccount Expenses:Taxes 12000 USD

This annotation will replace the original transaction with an accrual, moving the money from expenses to a virtual asset account. In addition, the annotation will generate a series of small transactions which continuously move money from the virtual asset account to the expense account:

# Accrual leg:
2020-03-24 "2020 Taxes"
Assets:BankAccount Assets:PrepaidTax 12000 USD

# Expense legs:
2020-01-31 "2020 Taxes"
Assets:PrepaidTax Expenses:Taxes 1000 USD

2020-02-29 "2020 Taxes"
Assets:PrepaidTax Expenses:Taxes 1000 USD

2020-03-31 "2020 Taxes"
Assets:PrepaidTax Expenses:Taxes 1000 USD

# ... etc, in total 12 transactions

knut will take care that the total impact remains the same. Also, amounts are properly split, without remainder.

@accrue <once|daily|weekly|monthly|quarterly|yearly> <T0> <T1> <accrual account>
<transaction>

Balance assertions

It is often helpful to check whether the balance at a date corresponds to an expected value, for example a value given by a bank account statement. A balance assertion in knut performs this check and reports an error if the check fails:

YYYY-MM-DD balance <account> <amount> <commodity>

Value directive

Value directives can be used to declare a certain account balance at a specific date. When encountering a value directive during evaluation, knut will automatically generate a transaction wich makes sure that the balance matches the indicated value. The generated transaction always has exactly one booking, and the two accounts are the given account and a special Equity:Valuation account.

YYYY-MM-DD value <account> <amount> <commodity>

Value directives are handy in particular for modeling investment portfolios, where it is too much work to model every individual trade, for example in an automated trading system. In such a situation, declare inflows and outflows of the investment as usual, and provide value directives for any day the value of the investment can be established (ideally daily). knut will automatically generate transaction representing the value changes of the investment, after considering any given bookings affecting the account.

Prices

knut has a power valuation engine, which can be used to create balance sheets in any currency or security which has pricing information. Prices are declared using price directives:

YYYY-MM-DD price <commodity> <price> <target_commodity>

For example, 2020-10-03 price AAPL 45 USD declares that AAPL cost 45 USD on 2020-10-03 (you wish...). knut is smart enough to derive indirect prices. For example, knut can print a balance with an AAPL position in CHF if a price for USD in CHF and a price for AAPL in USD exists. Prices are automatically inverted, as needed. knut will always use the latest available price for every given day. If a valuation is requried for a date before the first price is given, an error is reported.

Include directives

Income directives can be used to split a journal across a set of files. The given path is interpreted relative to the location of the file where the include directive appears.

include "<relative path>"

It is entirely a matter of preference whether to use large files or a set of smaller files. knut ignores lines starting with '*', so those with a powerful editor can use org-mode to fold sections of a file, making it easy to manage files with tens of thousands of lines.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].