Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
beancount litecoin example
;;; semi-realistic example: buy and sell a couple of lots of LTC on exchange,
;;; tracking basis and gains explicitly.
;; You don't have to declare your commodity symbols, but you can if you
;; want to.
1792-04-02 commodity USD
name: "United States Dollar"
2011-10-07 commodity LTC
name: "Litecoin"
;; You do have to declare all account names before you use them. I use my
;; birthday for the opening date of income, expense, and equity accounts.
;; Here we'll just use an arbitrary date.
2000-01-01 open Income:Capital-Gains
2000-01-01 open Expenses:Business:Banking
2000-01-01 open Equity:Opening-Balances
2000-01-01 open Equity:Basis-Adjustment
2017-01-01 open Assets:Bank:Checking USD
2017-01-01 * "Opening balances"
Assets:Bank:Checking 100 USD
Equity:Opening-Balances
2017-05-06 open Assets:CC:Coinbase:LTC LTC
2017-05-06 open Assets:CC:Coinbase:USD USD
2017-05-06 * "Bought 0.35060778 LTC for $10.40 USD" #cc-ltc-acquire
Assets:CC:Coinbase:LTC 0.35060778 LTC {29.6628 USD} ; effective cost basis, including the $0.40 fee, is $29.6628
Assets:Bank:Checking -10.40 USD
2017-06-04 * "Bought 0.35934448 LTC for $10.99 USD" #cc-ltc-acquire
Assets:CC:Coinbase:LTC 0.35934448 LTC {30.5835 USD}
Assets:Bank:Checking -10.99 USD
2017-08-28 * "Buy litecoin" #cc-ltc-acquire
Assets:Bank:Checking -10.99 USD
Expenses:Business:Banking 0.99 USD ; now recording the txn fee separately
Equity:Basis-Adjustment -0.99 USD ; with this adjustment so the cost basis below can include it
Assets:CC:Coinbase:LTC 0.15851918 LTC {69.3291 USD}
;; Insert a valuation for litecoin, from its closing value for the day
2017-12-31 price LTC 232.10 USD
2018-02-01 * "Coinbase" "Sold all LTC" #cc-ltc-dispose
Assets:CC:Coinbase:LTC -0.35060778 LTC {29.6628 USD} @ 161.4100 USD
Assets:CC:Coinbase:LTC -0.35934448 LTC {30.5835 USD}
Assets:CC:Coinbase:LTC -0.15851918 LTC {69.3291 USD}
Income:Capital-Gains
Assets:CC:Coinbase:USD 140.18 USD
;; Alternate approach, since you're selling all of your lots:
;2018-02-01 * "Coinbase" "Sold all LTC" #cc-ltc-dispose
; Assets:CC:Coinbase:LTC -0.86847144 LTC {} @ 161.4100 USD
; Income:Capital-Gains
; Assets:CC:Coinbase:USD 140.18 USD
2018-02-02 balance Assets:CC:Coinbase:LTC 0 LTC
## Check current balances:
$ bean-report 2-journal.beancount bal -e Assets
Assets:Bank:Checking 67.6200 USD
Assets:CC:Coinbase:LTC
Assets:CC:Coinbase:USD 140.1800 USD
## Remaining examples will examine asset balances on 2018-01-01, before the LTC was sold.
## List all lots individually:
$ bean-query 2-journal.beancount 'SELECT account, SUM(position), cost_date, cost_label FROM CLOSE ON 2018-01-01 WHERE account ~ "LTC" GROUP BY account, COST(position), cost_date, cost_label'
account sum_position cost_date
---------------------- ---------------------------- ---------- -
Assets:CC:Coinbase:LTC 0.35060778 LTC {29.6628 USD} 2017-05-06
Assets:CC:Coinbase:LTC 0.35934448 LTC {30.5835 USD} 2017-06-04
Assets:CC:Coinbase:LTC 0.15851918 LTC {69.3291 USD} 2017-08-28
## List asset balances. Note that the lots are separate items that are aggregated but not summed:
$ bean-query 2-journal.beancount 'BALANCES FROM CLOSE ON 2018-01-01 WHERE account ~ "Assets"'
account sum_position
---------------------- -----------------------------
Assets:Bank:Checking 67.62 USD
Assets:CC:Coinbase:LTC 0.35060778 LTC {29.6628 USD}, 0.35934448 LTC {30.5835 USD}, 0.15851918 LTC {69.3291 USD}
## Asset balances, in base commodity units (ignoring lot separations)
$ bean-query 2-journal.beancount 'BALANCES AT UNITS FROM CLOSE ON 2018-01-01 WHERE account ~ "Assets"'
account sum_units_posit
---------------------- ---------------
Assets:Bank:Checking 67.62 USD
Assets:CC:Coinbase:LTC 0.86847144 LTC
## Asset balances, according to their summed cost bases
$ bean-query 2-journal.beancount 'BALANCES AT COST FROM CLOSE ON 2018-01-01 WHERE account ~ "Assets"'
account sum_cost_po
---------------------- -----------
Assets:Bank:Checking 67.62 USD
Assets:CC:Coinbase:LTC 32.3800 USD
## Asset balances at current market value
$ bean-query 2-journal.beancount 'BALANCES AT VALUE FROM CLOSE ON 2018-01-01 WHERE account ~ "Assets"'
account sum_value_po
---------------------- ------------
Assets:Bank:Checking 67.62 USD
Assets:CC:Coinbase:LTC 201.5722 USD
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment