Skip to main content

Beancount plugin to derive commodity prices in alternative currencies like gold (XAU)

Project description

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

beancount_derived_prices-0.1.0.tar.gz (7.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

beancount_derived_prices-0.1.0-py3-none-any.whl (7.1 kB view details)

Uploaded Python 3

File details

Details for the file beancount_derived_prices-0.1.0.tar.gz.

File metadata

File hashes

Hashes for beancount_derived_prices-0.1.0.tar.gz
Algorithm Hash digest
SHA256 b6c32cd2f317a93933743c3934391a55b326ccd48f194cd51a37e74991aee56c
MD5 b555b375c428bf8f4a8f89eb93478c88
BLAKE2b-256 c20d8a191ce5543a9e36681ba2f6c84fcc198803f4aff225bbc7ebbae2a58366

See more details on using hashes here.

File details

Details for the file beancount_derived_prices-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for beancount_derived_prices-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 172848bb14e91218970064f2ad221b03b9671cb5c85dc96082a96a62402e6e0c
MD5 5ceb8a0a48033ef1bb79610621587a5b
BLAKE2b-256 48f5078c490517731b1de6f68d50864d11f786bc0484688501b8ff095191c27e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page