GnuCash
Contact   Instructions
Bug 797268 - Stock Split Assistant can create nonsense transactions
Summary: Stock Split Assistant can create nonsense transactions
Status: NEW
Alias: None
Product: GnuCash
Classification: Unclassified
Component: Engine (show other bugs)
Version: git-maint
Hardware: PC Windows
: Normal normal
Target Milestone: ---
Assignee: core
QA Contact: core
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-06-03 02:43 EDT by Christopher Lam
Modified: 2019-06-30 11:35 EDT (History)
4 users (show)

See Also:


Attachments

Description Christopher Lam 2019-06-03 02:43:08 EDT
Stock-split transactions have the following features:

* stock-split transaction currency is default_currency (from user prefs)
* stock-split amount equals delta shares, value equals zero
* cash-in-lieu transfers are from income to asset account
* cash-in-lieu amounts and values (the values cancel each other out) are both assumed to be in income/asset currency

In addition a price may be added.

The sum(values) will be zero, therefore there is no Imbalance split.

I have identified the following issues:
- income/asset accounts can be in any currency
- the price added can be in any currency
- if the stock-split is manually modified causing imbalance split, the latter will be in the transaction currency

e.g. the following nonsense can occur
- set default_currency to be GBP
- stock is AAPL
- stock's parent account currency is USD
- income currency is EUR
- asset currency is AUD

creating AAPL stock split with cash-in-lieu can create the following:
- transaction's currency is GBP
- Stock split:  value =    0 GBP amount =    9 AAPL
- Income split: value = -100 GBP amount = -100 EUR
- Asset split:  value =  100 GBP amount =  100 AUD

Here's my proposal:
- stock-split price *must* be in the stock's parent's gnc_account_or_default_currency -- the price currency field should be disabled
- income & asset accounts as well must be filtered as well
- the stock-split transaction must be in the gnc_account_or_default_currency rather than default_currency
Comment 1 Christopher Lam 2019-06-03 07:40:30 EDT
The only change I can feasibly perform is the first one; others are outside my skillset:

modified   gnucash/gnome/assistant-stock-split.c
@@ -353,7 +353,7 @@ gnc_stock_split_assistant_finish (GtkAssistant *assistant,
 
     xaccTransBeginEdit (trans);
 
-    xaccTransSetCurrency (trans, gnc_default_currency ());
+    xaccTransSetCurrency (trans, gnc_account_or_default_currency (account, NULL));
 
     date = gnc_date_edit_get_date (GNC_DATE_EDIT (info->date_edit));
     xaccTransSetDatePostedSecsNormalized (trans, date);
Comment 2 John Ralls 2019-06-28 15:34:01 EDT
I think that you mean gnc_account_currency_or_parent() as the source of the currency for both price and cash-in-lieu.

If there is to be no choice for the price then the selector should be removed rather than disabled. Disabled is for controls that might be used in some circumstances.

While I agree in principal I'm not sure it's worth the effort and if we made those changes I have little doubt that some user (Les Elliot comes to mind) who does a lot of international trading would whine about not being able to do splits the way he wants.
Comment 3 Christopher Lam 2019-06-30 10:26:24 EDT
I still think:

- it would be worth while setting the stock-split xaccTransSetCurrency to be the currency of the stock account's parent account. It's unusual that if stock-split txn is imbalanced, the imbalance currency is default_currency.

- price could be autopopulated with the expected new price (assuming no cash-in-lieu) whenever the stock_delta_units is updated:

  currency = xaccAccountGetCommodity(stock_account->parent)
  old_balance = xaccAccountGetBalance(stock_acct)
  valuation = old_balance * latest_price_from_pricedb(stock/currency)

  new_balance = old_balance + stock_delta_units
  new_price = valuation / new_balance

  enter new_price as the autopopulated value, allow user to modify

 I trust my calculations are right...
Comment 4 John Ralls 2019-06-30 11:35:12 EDT
Barring cash-in-lieu there's no currency involved in a split, it's a value-less addition of shares.

Calculating a price from the basis will be wrong and fruitless. Wrong because the post-split opening price will be somewhere in the vicinity of the prior day's close times the split ratio plus whatever trading changes occur because of news overnight... and then trading resumes so prices change. The valuation price might have been years ago and several times lower than the pre-split price. Fruitless because what you're really trying to do is adjust the basis, and that lives in the transaction record, not the price database. The APR already knows how to adjust the basis for reporting. The Lots facility should, don't remember because I don't use it.

Note You need to log in before you can comment on or make changes to this bug.