Skip to main content

beancount-derived-prices

A Beancount plugin that automatically generates commodity prices in alternative currencies (like gold/XAU) based on existing price data.

Why?

If you track your investments in USD but want to see their value in gold (XAU) to measure real purchasing power over time, you'd normally need to manually calculate and enter prices like:

2024-01-02 price VTSAX 0.060578 XAU

This plugin does that automatically. Given:

2024-01-02 price VTSAX 163.56 USD
2024-01-02 price XAU   2700.00 USD

It derives:

2024-01-02 price VTSAX 0.060578 XAU  ; 163.56 / 2700.00

Features

  • Derived Prices: Convert all commodity prices to an alternative currency
  • Inverse Rates: Automatically generates inverse exchange rates (e.g., USD/XAU)
  • Proxy Commodities: Create a chartable commodity that mirrors an operating currency's price (useful for Fava, which doesn't show charts for operating currencies)
  • Configurable: Exclude specific commodities, adjust decimal precision

Installation

pip install beancount-derived-prices

Or install from source:

git clone https://github.com/stenius/beancount-derived-prices
cd beancount-derived-prices
pip install -e .

Usage

Add to your beancount file:

plugin "beancount_derived_prices" "target:XAU via:USD"

Configuration Options

Option Default Description
target:<currency> XAU Target currency to derive prices into
via:<currency> USD Base currency used for conversion
exclude:<c1,c2> (none) Comma-separated commodities to exclude
precision:<n> 6 Decimal places for derived prices
proxy:<commodity> (none) Create a proxy commodity for charting

Examples

Basic gold pricing:

plugin "beancount_derived_prices" "target:XAU via:USD"

With proxy for Fava charts:

; XAU is an operating currency, so Fava won't show a price chart for it.
; The proxy:GOLD option creates a GOLD commodity with XAU's USD prices,
; which will show up in Fava's Commodities page with a chart.
plugin "beancount_derived_prices" "target:XAU via:USD proxy:GOLD"

Exclude volatile assets:

plugin "beancount_derived_prices" "target:XAU via:USD exclude:BTC,ETH"

Higher precision:

plugin "beancount_derived_prices" "target:XAU via:USD precision:8"

Full example:

option "operating_currency" "USD"
option "operating_currency" "XAU"

plugin "beancount_derived_prices" "target:XAU via:USD proxy:GOLD exclude:BTC precision:8"

; Your price data
2024-01-02 price XAU   2700.00 USD
2024-01-02 price VTSAX 163.56 USD
2024-01-02 price VOO   480.00 USD

; The plugin automatically generates:
; 2024-01-02 price VTSAX 0.06057778 XAU
; 2024-01-02 price VOO   0.17777778 XAU
; 2024-01-02 price USD   0.00037037 XAU
; 2024-01-02 price GOLD  2700.00 USD

How It Works

  1. Collects prices: Finds all price directives quoted in the base currency (USD)
  2. Calculates derived prices: For each date with a target currency price (XAU), divides each commodity's base price by the target's base price
  3. Generates inverse rates: Creates base-to-target exchange rates (USD → XAU)
  4. Creates proxy (optional): Mirrors the target currency's price as a regular commodity for charting

Use Cases

Track Portfolio in Gold

See how your investments perform relative to gold's purchasing power:

option "operating_currency" "USD"
option "operating_currency" "XAU"

2016-04-14 custom "fava-option" "conversion-currencies" "USD XAU"

plugin "beancount_derived_prices" "target:XAU via:USD"

Now in Fava, you can view your balance sheet converted to XAU.

Multiple Alternative Currencies

Run the plugin multiple times with different targets:

plugin "beancount_derived_prices" "target:XAU via:USD"
plugin "beancount_derived_prices" "target:BTC via:USD"

Requirements

  • Python 3.8+
  • Beancount 2.3+

License

MIT License - see LICENSE for details.

Contributing

Contributions welcome! Please open an issue or submit a pull request.

Metadata

Release files for beancount-derived-prices 0.1.0

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

Source distribution (sdist)

Source distribution for beancount-derived-prices 0.1.0
File Size Uploaded
beancount_derived_prices-0.1.0.tar.gz 7.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for beancount-derived-prices 0.1.0
File Interpreter ABI Platform
beancount_derived_prices-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 14.5 kB

Release files / beancount_derived_prices-0.1.0.tar.gz

Download URL beancount_derived_prices-0.1.0.tar.gz
Size 7.4 kB
Tags Source
SHA-256 checksum
How to use checksums
b6c32cd2f317a93933743c3934391a55b326ccd48f194cd51a37e74991aee56c
BLAKE2b-256 checksum
How to use checksums
c20d8a191ce5543a9e36681ba2f6c84fcc198803f4aff225bbc7ebbae2a58366
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.2

Release files / beancount_derived_prices-0.1.0-py3-none-any.whl

Download URL beancount_derived_prices-0.1.0-py3-none-any.whl
Size 7.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
172848bb14e91218970064f2ad221b03b9671cb5c85dc96082a96a62402e6e0c
BLAKE2b-256 checksum
How to use checksums
48f5078c490517731b1de6f68d50864d11f786bc0484688501b8ff095191c27e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.2

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

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