/accounts

Turning CSVs from my bank into Ledger files

Primary LanguagePythonGNU General Public License v3.0GPL-3.0

accounts

Tools to help converting my various CSV outputs from bank accounts and credit cards into a ledger file. There are (or will be) a few components:

  • Sanitising the CSV files from the banks/credit cards I use,
  • Command-line interface for easily selecting the correct account for each transaction (for this I implemented something like ido-mode in Python),
  • Machine learning to automatically predict the account for each transaction,
  • Consolidation of ledger files from various accounts (for inter-account transfers).

Installation

Requires Python >= 3.6. Scripts assume the interpreter is called python. Install the requirements with pip:

pip install -r requirements.txt

Converting one CSV to ledger format

Use accounts.py. Only three parameters are required, the others are for using training data to enable prediction:

usage: accounts [-h] [-t TRAINING_DATA] [-c CURRENCY] [-m LEDGER_MAXIMUM_AGE]
                csv_file account_name ledger_output

Makes ledger from CSV file semi-automatically. If training data is provided
then a model is trained and used to predict classes.

positional arguments:
  csv_file              CSV file containing date, payee, and amount (relative
                        to this account).
  account_name          Name of this account.
  ledger_output         Output Ledger file.

optional arguments:
  -h, --help            show this help message and exit
  -t TRAINING_DATA, --training_data TRAINING_DATA
                        Ledger file to use for training data and accounts
                        names. (default: None)
  -c CURRENCY, --currency CURRENCY
                        Currency symbol to use. (default: £)
  -m LEDGER_MAXIMUM_AGE, --ledger-maximum-age LEDGER_MAXIMUM_AGE
                        Maximum age, in days, of entries in ledger file to use
                        for training. (default: 180)

For example:

./accounts.py -t All.ledger \
              Current-201711.csv \
              Assets:Bank:Current \
              Current-201711.ledger

Testing the model

Run model.py to show how the model performs on a 3-fold validation test, for example:

./model.py All.ledger

Todo

Ledger file consolidation

Proper sanitising scripts