[GNC] import stock transaction amount and quantity from csv

Matthew Clay mpclay at gmail.com
Sun May 17 11:43:46 EDT 2020


Hey Elias,

I tried to do this recently as well, and with the helpful responses of
Geert and David, I think it is working. Like what you described, there
is rounding in my transaction histories from my financial institution,
and all I really want to get correct in gnucash is (i) the number of
shares purchased and (ii) the amount of my contribution. In order to
do this, my "hack" was to process the csv transaction history and
compute an effective price with high precision. Now when I import the
number of shares and price into gnucash, the "amount" (which is
rounded to the nearest cent) is correct.

As an example, on 01/01/2020 I contributed $49.25 and purchased 0.5721
shares of XYZ. The multi-line multi-split transaction I import into
gnucash looks like the following in the csv file:

"DATE","DESCRIPTION","CURRENCY","ACCOUNT","DEPOSIT","PRICE"
"01/01/2020","Contribution","CURRENCY::USD","Assets:Retirement
Account:Securities:Stock XYZ","0.572100000","86.0863485405"
"","","","Assets:Retirement Account:Cash","-49.25","1.0"

When I import this into gnucash I make the following
adjustment/associations in the main box that interprets the csv file:

* Toggle "Multi-split"
* Increase "Leading Lines to Skip" to 1
* Associate "DATE" column to "Date"
* Associate "DESCRIPTION" column to "Description"
* Associate "CURRENCY" column to "Transaction Commodity"
* Associate "ACCOUNT" column to "Account"
* Associate "DEPOSIT" column to "Deposit"
* Associate "PRICE" column to "Price"

The transaction is reported as balanced by gnucash and I see -49.25 in
my "Cash" account and +0.5721 shares in the "Stock XYZ" account.

I am not sure if this is a good/acceptable practice, but it seems to
work for now and gives me consistent results with the statements from
my financial institution (e.g., the fractional number of shares over
many statements is still correct, etc.). In order to get to this
point, however, I had to write some python code to process the
thousands of transactions in the csv file. It would be great if in the
future the user could select the number of shares and the total
amount, and leave the share price as a derived quantity.

Sincerely,
Matthew Clay


More information about the gnucash-user mailing list