Bug 458447 - Security account created on OFX import has 1/100 fraction, which gives wrong values if it really should be smaller
Summary: Security account created on OFX import has 1/100 fraction, which gives wrong ...
Status: RESOLVED FIXED
Alias: None
Product: kmymoney
Classification: Applications
Component: general (show other bugs)
Version: git (master)
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: KMyMoney Devel Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-08-29 00:38 UTC by Jack
Modified: 2022-09-10 17:20 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jack 2022-08-29 00:38:46 UTC
I  did an OFX import with a transaction for a sale of 281.543 shares, but shows up as 21.5400 because the import created a new security with precision of 1/100.  
It also looks like the price per share was adjusted from 10.019997 in the OFX file to 10.0201 in KMM (I have it set to use total price per transaction.)  I'm not sure of the right way to deal with this, but would it make sense to set the precision to handle all the digits actually used in the OFX file?  (I'm assuming any import would have the same problem, and not just OFX.)
Final point - I'd acutally prefer that KMM does NOT automatically create the security account.  This is because the string it uses (at least from Merrill Lynch) is not just the security name, but includes other info related to the transaction and not just the security.  Within KMM, I often adjust the security name, which often causes this issue for future imports of transactions for the security.
Comment 1 Ralf Habacker 2022-08-30 06:33:02 UTC
(In reply to Jack from comment #0)
> I  did an OFX import with a transaction for a sale of 281.543 shares, but
> shows up as 21.5400 because the import created a new security with precision
> of 1/100.  
This is not a regression, as this behavior is also observed in a build from the 4.8 branch by using account bug458847 from https://kmymoney.org/ofxtest.php

> It also looks like the price per share was adjusted from 10.019997 in the
> OFX file to 10.0201 in KMM (I have it set to use total price per
> transaction.)  

This seems to be from investment, which probably does not fit https://invent.kde.org/websites/kmymoney-org/-/blob/master/ofxtest.php#L447. Can you show an example of a corresponding OFX fragment ?
Comment 2 Jack 2022-08-30 18:35:43 UTC
Agreed it's not a regression.  New securities are always created with 1/100; this is perhaps the first time I have noticed that the values seem to be changed on import because of this.
I suspect the default name for my securities depend on what Merrill Lynch sends for the initial purchase, and most of the time, later transactions either match or are corrected by matching to a similar previous transaction.  However, some security names I modify such as adding a leading character to force sorting to the beginning or end of the list of securities, and those are the ones which cause this problem with later imports.
(I wonder if there could be some sort of security name matching similar to payee name matching?)

Here is one sell transaction from OFX:
          <SELLMF>
            <INVSELL>
              <INVTRAN>
                <FITID>20220607TB190801450137952
                <DTTRADE>20220607110000.000[-5:EST]
                <DTSETTLE>20220608110000.000[-5:EST]
                <MEMO>Sale: PUTNAM ULTRA SHORT DURATION INCOME FD CL Y VSP 01/04/21 FR
              </INVTRAN>
              <SECID>
                <UNIQUEID>74676P698
                <UNIQUEIDTYPE>CUSIP
              </SECID>
              <UNITS>-281.543
              <UNITPRICE>10.019997
              <MARKDOWN>0
              <COMMISSION>0
              <FEES>0
              <TOTAL>2821.06
              <SUBACCTSEC>CASH
              <SUBACCTFUND>CASH
            </INVSELL>
            <SELLTYPE>SELL
          </SELLMF>
It imports as 281.54 shares, total $2821.06, share price $10.0200.  The <SELLMF> is within <INVSTMTRS> and yes, this is within an investment account.
Comment 3 Jack 2022-08-30 20:04:11 UTC
I'll also add that the Security created on import uses the name after "Sale: " from the <MEMO> field.  Wouldn't it make more sense to use the one from <SECNAME> later on in the file?  (In my case, that wouldn't help, as that is an even longer version of that from the Memo field, thanks to Merrill Lynch.
Comment 4 Thomas Baumgart 2022-09-04 15:02:38 UTC
Can you also provide the following part from your download:

    <SECLIST>
      <STOCKINFO>
     :
     :
      </STOCKINFO>
    </SECLIST>

that matches the above SELLMF? If you want, please send it to me via PM if you don't want to post it here.
Comment 5 Jack 2022-09-04 17:53:37 UTC
      <MFINFO>
        <SECINFO>
          <SECID>
            <UNIQUEID>74676P698
            <UNIQUEIDTYPE>CUSIP
          </SECID>
          <SECNAME>PUTNAM ULTRA SHORT DURATION INCOME FD CL Y VSP 01/04/21 FRAC SHR QUANTITY   .543 PER ADVISORY AGREEMENT. PRICE    10.020
          <TICKER>74676P698
          <FIID>9MI21
          <UNITPRICE>0
          <DTASOF>20220804110000.000[-5:EST]
        </SECINFO>
        <MFTYPE>OPENEND
        <YIELD>0
        <DTYIELDASOF>20220804110000.000[-5:EST]
      </MFINFO>

Don't know if it's relevant here, but note the strange SECNAME.
Comment 6 Ralf Habacker 2022-09-08 09:16:07 UTC
Git commit 142a43555b4ad22b95af309c31549e77b41721f3 by Ralf Habacker.
Committed on 08/09/2022 at 09:15.
Pushed by habacker into branch 'master'.

ofxtest.php: Add test case for selling mutual fund

M  +34   -0    ofxtest.php

https://invent.kde.org/websites/kmymoney-org/commit/142a43555b4ad22b95af309c31549e77b41721f3
Comment 7 Thomas Baumgart 2022-09-10 17:11:00 UTC
Git commit d65cb8a432ce107fa69be617aa815f6a10173f7b by Thomas Baumgart.
Committed on 10/09/2022 at 17:10.
Pushed by tbaumgart into branch 'master'.

Improve OFX importer

Allow fractions of security smaller than 1/100. A new security is
created with a default fraction of 1/100. In case the import contains a
transaction with more fractional digits, the fraction of the security is
automatically adjusted so that no information is lost.

Securities are also detected by their unique id not only by their name.
This allows to change the name after the import without re-creating the
security during the next import.

Security accounts are using the oldest postdate found in the OFX import
file as their opening date and not the current date. This prevents the
consistency check to report and fix the opening date later on.

M  +19   -4    kmymoney/converter/mymoneystatementreader.cpp
M  +9    -1    kmymoney/mymoney/mymoneystatement.cpp
M  +3    -0    kmymoney/mymoney/mymoneystatement.h
M  +22   -2    kmymoney/plugins/ofx/import/ofximporter.cpp

https://invent.kde.org/office/kmymoney/commit/d65cb8a432ce107fa69be617aa815f6a10173f7b
Comment 8 Dawid Wróbel 2022-09-10 17:20:27 UTC
> This allows to change the name after the import without re-creating the
security during the next import.

if I remember correctly, there might already be a related bug