Thanks Fernando! It will be a bit before I can add this but I appreciate the start. I will look at the suggested code as well.
Eric On May 14, 2014 11:36 PM, "Fernando Vilas" <fvi...@iname.com> wrote: > 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 > fvi...@iname.com > > _______________________________________________ > KMyMoney-devel mailing list > KMyMoney-devel@kde.org > https://mail.kde.org/mailman/listinfo/kmymoney-devel > >
_______________________________________________ KMyMoney-devel mailing list KMyMoney-devel@kde.org https://mail.kde.org/mailman/listinfo/kmymoney-devel