[Kmymoney-devel] KMMDroid alive and kicking

Fernando Vilas fvilas at iname.com
Thu May 15 03:35:30 UTC 2014


On Wednesday, May 14, 2014 19:48:15 Eric Bonney wrote:
> Hi everyone!
> 
> So after a year or so of letting this project lay idle I have resurrected
> it again. I have it just about updated to the latest API and starting to
> fix some other bugs.
> 
> I have a quick question about investment accounts. I am trying to figure
> out how the actual current balance in an investment account is figured. I
> don't see it stored in the database anywhere so I am guessing there is a
> calculation going on somewhere right?
> 
> If so can someone point me where to look?
> 
> Thanks,
> Eric

We have tried a few database views to calculate it, but those proved to be 
cumbersome. They also break down when the a stock splits or goes through a 
reverse split.

Consequently, they are calculated at the storage layer in the 
MMStorage::balance() function, implemented for both the XML and SQL backends. 
I will cover the one in the SQL backend, since that is one I am more familiar 
with, though it was modeled after the one in the XML backend. 

The algorithm is essentially to grab all splits in the date range that match 
txType='N' and the accountId is the one you want, ordered by accountId and 
date. Then loop through all splits returned. If the action was a normal 
transaction, then add the value to the running total. If the action was 
ActionSplitShares, then multiply instead of add so that the split is handled 
appropriately.

For speed the results are stored in the MMFile member variable of type 
MyMoneyBalanceCache.

-- 
Thanks,
Fernando Vilas
fvilas at iname.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: This is a digitally signed message part.
URL: <http://mail.kde.org/pipermail/kmymoney-devel/attachments/20140514/03a6656f/attachment.sig>


More information about the KMyMoney-devel mailing list