Skip to content

holdings: value positions at the time-filter end date - #2350

Open
ryanduguid wants to merge 1 commit into
beancount:mainfrom
ryanduguid:fix-holdings-price-date
Open

holdings: value positions at the time-filter end date#2350
ryanduguid wants to merge 1 commit into
beancount:mainfrom
ryanduguid:fix-holdings-price-date

Conversation

@ryanduguid

Copy link
Copy Markdown

Fixes #2336

Holdings BQL called value() and getprice() without a date. Those queries run on entries_with_all_prices, so beanquery used later prices from outside the time filter. Account reports already value at FilteredLedger.end_date (“The date to use for prices.”).

This moves the holdings queries to Python and pins both functions to that date. The frontend loads the report from a new /api/holdings endpoint so the Query link shows the dated BQL.

On a ledger with 10 STOCK bought in June, priced 12 at month-end and 20 in September, time=2020-06 now reports 120 (not 200). That matches the example-file case in #2336 (5170.89 USD at 2017-08-31 vs 5217.47 USD from a later price).

Verification:

uv run pytest tests/test_core_holdings.py tests/test_json_api.py -q
uv run pytest --cov=fava --cov-fail-under=100

I reviewed, understand, and take responsibility for this change.

Beanquery value() and getprice() used the latest price when undated.
Holdings queries run on entries_with_all_prices, so a time filter still
valued lots at later prices. Pin both functions to FilteredLedger.end_date,
the same date account reports already use.

Fixes beancount#2336
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Holdings report uses future prices for market value when date filter is applied

1 participant