I appreciate the analysis of the code, and the confirmation of what I found 
through experimentation. I had tried searching the code for the answer, but I 
do not know C/C++ and I would not have been able to figure it out. 

I’d be happy to write a paragraph documenting how a QIF entry for a StkSplit 
import should be built, but I’m not sure where this should be included?

Tim


> On Jan 5, 2023, at 22:23, john <jra...@ceridwen.us> wrote:
> 
> gnc_numeric_create is a C function implemented in 
> libgnucash/engine/gnc-numeric.cpp and made available to Scheme by SWIG which 
> changes its name to gnc-numeric-create. It takes two int64_t arguments, 
> numerator and denominator.
> 
> There's a general convention that public functions defined in Scheme are 
> named gnc:foo. SWIG-wrapped functions have their same name in Scheme except 
> that underscores are replaced with hyphens. Aside from the original xacc  
> camel-case functions we generally follow the Gnome practice of beginning C 
> and C++ free functions with the gnc namespace followed by the class name, 
> separated by underscores. With only seven exceptions if the name is like 
> gnc-foo-bar then it's a wrapped C function while (with no exceptions) 
> gnc:foo-bar is defined in Scheme.
> 
> Note that n/ is defined in qif-to-gnc.scm: (define (n/ a b) (gnc-numeric-div 
> a b 0 GNC-DENOM-REDUCE)) and n* as (define (n* a b) (gnc-numeric-mul a b 0 
> GNC-DENOM-REDUCE)).
> 
> So in normal arithmetic notation, out_shares = inshares * (split_ratio / 10). 
>  That code was added in 
> https://github.com/Gnucash/gnucash/commit/00972f52311b3641c0bd4474334ff846501a3019#diff-fe1b1f57a35caf6ec4d0916b27f888c9bec88a4264248e4d1687d97cbabcc963
>  
> <https://github.com/Gnucash/gnucash/commit/00972f52311b3641c0bd4474334ff846501a3019#diff-fe1b1f57a35caf6ec4d0916b27f888c9bec88a4264248e4d1687d97cbabcc963>
>  with no explanation of why the provided split ratio should be divided by 10.
> 
> Regards,
> John Ralls
> 
> 
> 
>> On Jan 5, 2023, at 6:05 PM, David Reiser via gnucash-user 
>> <gnucash-user@gnucash.org> wrote:
>> 
>> bug, maybe?
>> 
>> import-export/qif-imp/qif-to-gnc.scm says:
>> 
>> ((stksplit)
>>             (let* ((splitratio (n/ num-shares (gnc-numeric-create 10 1)))
>>                    (in-shares
>>                     (xaccAccountGetBalance near-acct))
>>                    (out-shares (n* in-shares splitratio)))
>>               (xaccSplitSetAmount gnc-near-split out-shares)
>>               (xaccSplitSetAmount gnc-far-split (n- in-shares))
>>               (xaccSplitSetValue gnc-near-split (n- split-amt))
>>               (xaccSplitSetValue gnc-far-split split-amt))))
>> 
>> 
>> num-shares is the value of the qif Q line, so it looks like the entered 
>> split ratio is being divided by 10. But I can’t find a definition of 
>> gnc-numeric-create. And my scheme (well, LISP, in my case) is so rusty it 
>> almost might be worse than not knowing it in the first place...
>> --
>> Dave Reiser
>> dbrei...@icloud.com
>> 
>> 
>> 
>> 
>> 
>>> On Jan 5, 2023, at 6:13 PM, m...@tgr66.me wrote:
>>> 
>>> So, the ratio * 10 does seem to be working. :man_shrugging:
>>> 
>>> For example, if it is a 4 for 1 split, 40
>>> If it is a 1 for 10 split, 1
>>> 
>>>> On Jan 5, 2023, at 14:17, m...@tgr66.me wrote:
>>>> 
>>>> Yes. I missed adding that to the list I’ve tried.
>>>> 
>>>> In the full work minimal example below, the share balance ends up at 1.2
>>>> 
>>>> !Account
>>>> NAssets:Investments:Brokerage Account:Joint Brokerage
>>>> TInvst
>>>> ^
>>>> !Type:Bank
>>>> D01/11/2020
>>>> NPayment/Deposit
>>>> PTrf My Bank
>>>> CX
>>>> T1,000.00
>>>> MDeposit
>>>> LAssets:Current Assets:My Bank
>>>> ^
>>>> !Type:Invst
>>>> D12/2/2021
>>>> NBuy
>>>> PXYZ, INC
>>>> YXYZ
>>>> I150
>>>> T450
>>>> Q3
>>>> CR
>>>> M3 shares @ 150; Nothing to see here
>>>> ^
>>>> !Type:Invst
>>>> D1/1/2022
>>>> NStkSplit
>>>> PXYZ, INC
>>>> YXYZ
>>>> CR
>>>> Q4
>>>> M4 for 1 split
>>>> ^
>>>> 
>>>> Then I changed Q to 40 and while I end up with the correct balance 
>>>> (GnuCash creates two transactions, one removing the original three shares, 
>>>> and the second adding 12 shares), I have no idea if that is just luck or 
>>>> if I’ve stumbled on new math :-)
>>>> 
>>>> I’ll experiment some more.
>>>> 
>>>> 
>>>>> On Jan 5, 2023, at 14:02, David Reiser <dbrei...@icloud.com> wrote:
>>>>> 
>>>>> I’ve never used QIF for stock splits, but the obvious question is “Have 
>>>>> you tried Q4?” After all, 4/1 is numerically equal to 4 (a ratio reduced 
>>>>> to a single number).
>>>>> --
>>>>> Dave Reiser
>>>>> dbrei...@icloud.com
>>>>> 
>>>>> 
>>>>> 
>>>>> 
>>>>> 
>>>>>> On Jan 5, 2023, at 2:51 PM, m...@tgr66.me wrote:
>>>>>> 
>>>>>> I’ve searched considerably, but if I missed it, I apologize.
>>>>>> 
>>>>>> Docs for QIF say the Q field should contain the split ratio. I’ve tried 
>>>>>> various options, but I’m not getting the expected results after import.
>>>>>> 
>>>>>> !Type:Invst
>>>>>> D8/31/2020
>>>>>> NStkSplit
>>>>>> PAPPLE INC
>>>>>> YAAPL
>>>>>> CR
>>>>>> M4 for 1 split; 
>>>>>> Q36 // Have also tried 4:1, 4/1 and simply 48
>>>>>> ^
>>>>>> 
>>>>>> GnuCash 4.13 on macOS. I’ve not tried yet on my Linux box.
>>>>>> 
>>>>>> Thanks.
>>>>>> _______________________________________________
>>>>>> gnucash-user mailing list
>>>>>> gnucash-user@gnucash.org
>>>>>> To update your subscription preferences or to unsubscribe:
>>>>>> https://lists.gnucash.org/mailman/listinfo/gnucash-user
>>>>>> -----
>>>>>> Please remember to CC this list on all your replies.
>>>>>> You can do this by using Reply-To-List or Reply-All.
>>>>> 
>>>> 
>>>> _______________________________________________
>>>> gnucash-user mailing list
>>>> gnucash-user@gnucash.org
>>>> To update your subscription preferences or to unsubscribe:
>>>> https://lists.gnucash.org/mailman/listinfo/gnucash-user
>>>> -----
>>>> Please remember to CC this list on all your replies.
>>>> You can do this by using Reply-To-List or Reply-All.
>>> 
>> 
>> _______________________________________________
>> gnucash-user mailing list
>> gnucash-user@gnucash.org
>> To update your subscription preferences or to unsubscribe:
>> https://lists.gnucash.org/mailman/listinfo/gnucash-user
>> -----
>> Please remember to CC this list on all your replies.
>> You can do this by using Reply-To-List or Reply-All.
> 

_______________________________________________
gnucash-user mailing list
gnucash-user@gnucash.org
To update your subscription preferences or to unsubscribe:
https://lists.gnucash.org/mailman/listinfo/gnucash-user
-----
Please remember to CC this list on all your replies.
You can do this by using Reply-To-List or Reply-All.

Reply via email to