This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Updateing stock prices in KMyMoney 4.8 and 5.0

Tags: None
(comma "," separated)
User avatar
gking
Registered Member
Posts
29
Karma
1
OS
I started to use KMyMoney to replace Quicken right around the time that Yahoo discontinued their stock quote service. I looked at other online quote options in KMM, but was not very successful in getting any to work well so I crafted my own solution which works well for me. This works in KMM 5.0 and 4.8.

I use Google sheets "googlefinance" function and a bit of Linux shell scripting as follows:

1. Create a 3 column Google sheet, lets call it "Prices" with a tab also called "Prices",with 1 stock / mutual fund/ currency per row as follows:
Code: Select all
Date   ticker   Price
=now()   AAT770   1.00
=googlefinance(B3,"tradetime")   NYSE:BRK.B   =googlefinance(B3)
=googlefinance(B4,"tradetime")   NYSEARCA:EFA   =googlefinance(B4)
=googlefinance(B5,"tradetime")   BATS:EFG   =googlefinance(B5)
=googlefinance(B6,"tradetime")   BATS:EFV   =googlefinance(B6)
=googlefinance(B7,"tradetime")   NYSEARCA:GLD   =googlefinance(B7)
=googlefinance(B8,"tradetime")   TSE:XSB   =googlefinance(B8)
=googlefinance(B9,"tradetime")   NYSEARCA:VB   =googlefinance(B9)
=googlefinance(B10,"tradetime")   NYSEARCA:VTV   =googlefinance(B10)
=googlefinance(B11,"tradetime")   NYSEARCA:VWO   =googlefinance(B11)
=now()   CADUSD   =googlefinance("Currency:CADUSD")
=now()   USDCAD   =googlefinance("Currency:USDCAD")

Format the 1st column as date YYYY-MM-DD such that the results looks like:

Date   ticker   Price
2018-02-21   AAT770   1.00
2018-02-21   NYSE:BRK.B   201.02
2018-02-21   NYSEARCA:EFA   70.41
2018-02-21   BATS:EFG   80.61
2018-02-21   BATS:EFV   55.42
2018-02-21   NYSEARCA:GLD   125.66
2018-02-21   TSE:XSB   27.31
2018-02-21   NYSEARCA:VB   147.03
2018-02-21   NYSEARCA:VTV   105.92
2018-02-21   NYSEARCA:VWO   47.81
2018-02-21   CADUSD   0.7876
2018-02-21   USDCAD   1.2698

You will need to get the Google finance ticker for each of your stocks and update that data in KMM as well If you have a lot of stocks this can be a pain but hopefully it will be the last time you will have to do this. I use the whole ticker <exchange>:<stock> since there can be duplicates or substrings that match if you have holdings in multiple countries. Some investments like money market funds have constant prices, so you can just put in a fixed price if you want KMM to value the units on each update.

2. Set your browser to save downloads to /tmp. This is not strictly necessary if you can remember to erase/delete the download after every update, but /tmp is usually emptied upon reboot. If you do not do something to remove previous downloads, each successive download wil get (1), (2) etc appended to the filename, and the update script will not find it. YMMV.

3. Place the following script called "get-stock-price.sh" in your home directory:
Code: Select all
#!/bin/bash
grep $1  "/tmp/Prices - Prices.csv" -m 1

and make it executable. (chmod +x get-stock-price.sh).

4. In KMM, Settings->Configure KMyMoney->Online Quotes-> New
Code: Select all
URL: file:/home/<uid>/get-stock-price.sh  %1
Symbol: %1
Price: (\d+\.\d+)
Date: (\d{4}\-\d{2}\-\d{2})
Format: %y-%m-%d
---Check the "Skip HTML stripping option"


5. It looks like KMM defaults to Yahoo currency to get currency conversions, so update that source with the same info as your new source, except put %1%2 for the symbol. This assumes you have a row in your Google sheet for the appropriate currencies.

6. Every time you want to update your stock prices, open the Google Sheet "Prices", and select "File->Download as->Comma separated values" . You should have a file called /tmp/Prices - Prices.csv" similar to:
Code: Select all
Date,ticker,Price
2018-02-21,AAT770,1.00
2018-02-21,NYSE:BRK.B,201.02
2018-02-21,NYSEARCA:EFA,70.41
2018-02-21,BATS:EFG,80.61
2018-02-21,BATS:EFV,55.42
2018-02-21,NYSEARCA:GLD,125.66
2018-02-21,TSE:XSB,27.31
2018-02-21,NYSEARCA:VB,147.03
2018-02-21,NYSEARCA:VTV,105.92
2018-02-21,NYSEARCA:VWO,47.81
2018-02-21,CADUSD,0.7875
2018-02-21,USDCAD,1.2698

Next, in KMyMoney, select "Tools->Update stock and currency Prices"

This is a bit more maintenance since you need to keep the holdings in the Google sheet and the KMM portfolio in sync, and it is a 2 step process, but I think it is solid as long as Goggle offers the "googlefinance" function. I was also able to do this with a Globe & Mail watchlist, but at the time their currency rates were not updating (since fixed I think). Of course their stock ticker exchange symbols are all different so you need to pick one and stick with it.

I hope this helps.


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], Yahoo [Bot]