Skip to content

[Overview issue] Make hledger good for investment tracking #1015

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
simonmichael opened this issue May 13, 2019 · 10 comments
Open

[Overview issue] Make hledger good for investment tracking #1015

simonmichael opened this issue May 13, 2019 · 10 comments
Labels
A-WISH Some kind of improvement request or proposal. investing Related to investments, lots, capital gains, etc.

Comments

@simonmichael
Copy link
Owner

simonmichael commented May 13, 2019

This is an overview/starting point for the project of making hledger good (best-in-class, effective, pleasant) for tracking investments. I'll keep this summary updated.

Related docs

Ledger

Ledger Tutorial:

Principles of Accounting with Ledger:

Transactions:

Beancount

  • How Inventories Work "how we accumulate commodities and match sales (reductions) against accumulated inventory contents"
  • Inventory Booking (proposal) "The problem of inventory booking, that is, selecting which of an inventory’s trade lots to reduce when closing a position, is a tricky one"
  • Trading with Beancount "explanation of trading P/L and worked examples of how to deal with various investing and trading scenarios"
  • Stock Vesting in Beancount "explains the vesting of restricted stock units in Beancount"
  • Exporting Your Portfolio "how to export your portfolio of holdings from Beancount to a Google Finance portfolio"

beans

  • https://sboehler.github.io/beans/
    Converts to a desired commodity:
    "derives arbitrary commodity conversions between all commodities, as long as there is at least one path (possibly over several links) from one commodity to another. For example, conversion from SomeStock in CHF is possible when prices of SomeStock in USD and CHF in USD is available. Inverted rates are derived automatically."
    Generates revaluation transactions (calculates unrealized gains) when reporting in a different commodity:
    "The journal now not only shows explicit inflows and outflows, but also valuation corrections due to price changes at the specific date they occurred."
    "When valuating the balance in a certain reference commodity, beans accounts for changes in valuation using the Equity:Valuation account. It reflects gains and losses over time with respect to the reference currency."
    "applies valuation directly at the transaction level. For example, if you choose to display a balance at market prices, beans will transparently insert valuation transactions to reflect gains and losses due to price changes"
    "Depending on whether one wants to convert commodities at cost or at market value, beans will add balancing accounts automatically."
    "offers either no valuation or valuation at market prices. Valuation at cost is yet to be implemented."
    "applies valuation at the level of transactions, which seems unique amongst plain-text accounting tools" --Transaction-level valuation.
    1 Converts all postings to the target commodity using market prices at target valuation date (there are no explicit transaction prices)
    2 At each market price change, for each asset/liability account, calculates the balance and adds a revaluation transaction (transfer to/from Equity:Valuation).

Elsewhere

Related issues

Things we need

docs/examples for common investment-related tasks, using existing features [20%]

market price fetching (latest prices, prices over a period) [10%]

show value at different dates (period end, custom date, maybe transaction date) [50%]

show value in specified commodity [10%]

show revaluations/unrealized capital gains [10%]

clear price inference & propagation behaviour [40%]

track & show lot deposits [10%]

check, execute valid lot movements (FIFO etc.) [0%]

show realized capital gains [0%]

compatibility with ledger/beancount where reasonable, better compatibility docs [40%]

other ?

@the-solipsist
Copy link
Collaborator

Hi. I'd like to underscore the significant number of important insights contained in this doc (from 2014):
https://beancount.github.io/docs/a_proposal_for_an_improvement_on_inventory_booking.html

I think the discussion on the shortcomings with Ledger, the shortcomings with Beancount (up until 2016), and the requirements section are well worth considering. I think the requirements for hledger are largely the same.

This document (from 2016) provides details of the revised inventory system that beancount adopted, which reveals both a few trade-offs, as well as one or two simplifications adopted. But I think the requirements section of the 2014 document is crucial to understand both the mistakes to avoid and what needs to be done to provide the best support for investment tracking.

@simonmichael simonmichael changed the title Make hledger good for investment tracking (overview issue) Overview issue: Make hledger good for investment tracking Aug 17, 2022
@simonmichael simonmichael changed the title Overview issue: Make hledger good for investment tracking [Overview issue] Make hledger good for investment tracking Aug 17, 2022
@the-solipsist
Copy link
Collaborator

As an update, here is Beancount's proposed redesign of its inventory (lots) booking system, which involves some simplification of the syntax as well:
https://docs.google.com/document/d/1H0UDD1cKenraIMe40PbdMgnqJdeqI6yKv0og51mXk-0/edit#

This 2021 document should ideally be read after the documents from 2014 and 2016 that are linked here: #1015 (comment)

I think it would be useful for the hledger, beancount, and ledger devs to discuss this and seek to converge on similar syntax to ensure greater interoperability in the PTA ecosystem.

@jkyiv
Copy link

jkyiv commented Aug 26, 2022 via email

@simonmichael
Copy link
Owner Author

simonmichael commented Sep 1, 2022 via email

@danielschonfeld
Copy link

Is this still on the roadmap?

@simonmichael
Copy link
Owner Author

Yes, certainly; though no-one has been working on it or expressing strong needs in this area for a while.

@jkyiv
Copy link

jkyiv commented Sep 4, 2024 via email

@simonmichael
Copy link
Owner Author

Thanks for the example @jkyiv. It's clear but I don't quite understand your point. Is there a problem with the example you showed ? Or is it demonstrating something you'd like to do with AAPL, but can't for some reason ? What sort of entries would you like to write, but can't ?

Generally speaking of course, we should first find the correct entries using standard DEB, and then think about more efficient representations/workflows.

@jkyiv
Copy link

jkyiv commented Sep 29, 2024

Hi @simonmichael , I picked a commodity (gretchka) to illustrate the need to be able to handle cost-basis in a currency-neutral manner. I only mentioned APPL because typically if one buys a security with a given currency, its in that market, and will only be sold for the same currency.

Part of what originally drew me to ledger-cli for my accounting needs was that it doesn't force one to use a currency of reference the way GNU Cash did.

Last time I looked, Beancount's ways of tracking cost basis assumed that sale of a commodity would be in the same commodity it was purchased in. But in the case of commodities bought in one country, and sold in another market---or in the case of expats perhaps buying bitcoin in one currency but selling in another, the how ought one to record such a transaction if the accounting software assumes the sale currency will match the currency of the cost basis?

Does that clarify what I was trying to do?

PS - I haven't had a chance to look at their source code yet, but I wonder if a project like https://github.com/eprbell/rp2/ might have some indications how to track cost basis?

@simonmichael
Copy link
Owner Author

Hi @jkyiv. My best understanding so far is that you would like full flexibility in which currencies you use for purchase and sale, without being forced to pick one as a reference currency. And that's what hledger provides, as far as I know. It doesn't have any concept of a reference currency. Am I still missing your point ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-WISH Some kind of improvement request or proposal. investing Related to investments, lots, capital gains, etc.
Projects
None yet
Development

No branches or pull requests

4 participants