Skip to main content

Hledger-lots

automatic lots

This package helps hledger users to add and manage transactions involving buying and selling commodities like stock, currency, etc.

Features

Add transaction

Instead of editing the journal file directly to add a commodity purchase or sale, answer some interactive prompts with the following benefits:

  • Validation of allowed values for each field
  • Fuzzy search completion using previous transaction data in the journal
  • Select the answer between possible values or autocomplete when only one answer is allowed.

Automatic Lots

The most convoluted aspect of using hledger for investment is to manage lots because when selling a commodity, you need to use its cost, which is buried deep down in your journal, instead of the sale price, which is more easily available to add the correct profit/loss of the trade.

To calculate the cost, there are some methods you can apply and hledger doesn't provide tools to do it, so you are on your own. Hledger-lots calculate the cost without the need to alocate each purchase to a specific subaccount or tag. When you use hledger-lots sell, it traverse the journal and arrive to the correct cost without additional information.

You can choose between two diferrent methods to calculate the cost of selling lots:

  • FIFO: First In First Out
  • AVERAGE COST: Average Cost of all previous purchase. It is as if selling a proportional part of each previous sale.

Automatic Price Download

One simple command to automatically download market price from Yahoo Finance for choosen commodities as explained here.

Reports

To get information about the commodities, there is more 2 commands:

command description
view Get the lots and indicators for a specific commodity
list Get the indicators for all commodities as a table

The indicators provided by these command are explained here.

Documentation

Documentation with usage information can be found here

Setup

Requirements

Install

pip install --upgrade hledger-lots

Config

Instead of using command options, which is hard to remember and makes the command long, environment variables, which demands tweaking the .bashrc file or a configuration file, this app add configuration options directly in the journal using a custom directives specification explained here

You can still use LEDGER_FILE environment variable by adding export LEDGER_FILE=your_data.journal or prepend to the command: LEDGER_FILE=your_data.journal hledger-lots ...

Workflow

  1. Add a commodity purchase using the command buy or edit the journal as usual using "@" notation. Don't bother creating subaccounts or tags with unique lot name. See some examples here
  2. Download market price history from Yahoo Finance as price directive using the command prices
  3. View financial indicators for a specific commodity using view or a summary of all commodities using list.
  4. When you sell, use the command sell instead of adding the transactions manually. Hledger-lots will generate the correct transaction and append to the selected journal if you confirm the transaction is correct. See transaction tags with interesting indicators about the current trade

Indicators

Basic Indicators

  • Commodity Name
  • Total Quantity Purchased
  • Total Amount Purchased
  • Average Cost

Market Indicators

For commodities with price directives on a date after the last purchase, you will have also the following indicators:

  • Last Market Price
  • Market Amount: Quantitty Purchased * Last Market Price
  • Market Profit: Market Amount - Amount Purchased
  • Last Market Date
  • XIRR

XIRR

The sale transaction gives you the calculated xirr as tag, which is the internal rate of return of an investment based on a specified series of irregularly spaced cash flows. This value is annual percentage rate following the 30/360US day count convention. It is a good metric to compare the investment return with a benchmark like the S&P or the T-Bill, for example.

Note the benchmark can use another day count convention, so this comparison may not be 100% precise. This app may in the future offer others day count convention for xirr calculation.

Checks

It is recommended to set the option check to true to ensure you past selling transaction has the correct cost according to the choosen cost method. See how to set it up here

Limitations

  • No short-selling
  • Each commodity can have only one base currency. For example, it is not possible to buy AAPL with USD and later with EUR.

Metadata

Release files for hledger-lots 0.4.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for hledger-lots 0.4.2
File Size Uploaded Provenance
hledger_lots-0.4.2.tar.gz 26.5 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for hledger-lots 0.4.2
File Interpreter ABI Platform
hledger_lots-0.4.2-py3-none-any.whl Python 3 none any Details

Total release size: 67.3 kB

Release files / hledger_lots-0.4.2.tar.gz

Download URL hledger_lots-0.4.2.tar.gz
Size 26.5 kB
Tags Source
SHA-256 checksum
How to use checksums
81dbe70e0075732d112a33691728055026bcc2e807d36d13df900bb4b5e3dd02
BLAKE2b-256 checksum
How to use checksums
9e51a24a935d39159cd686274a5a937702ce519b28dacc14df2d608f45091927
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.3

Release files / hledger_lots-0.4.2-py3-none-any.whl

Download URL hledger_lots-0.4.2-py3-none-any.whl
Size 40.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
608feae1a38177e815d09cd08d683161c489208a1bf6aeae1f785ec23f5ea68a
BLAKE2b-256 checksum
How to use checksums
a444ce6dadf4c2f2d8e8feb3e3188813657e868a5550f5e6a3e99adbfc454bfb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.3

Security for hledger-lots 0.4.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page