getAccountBalance() intermittently returns incorrect value, but only if syncing is enabled

Jim Richmond's Avatar

Jim Richmond

03 Sep, 2019 07:00 PM

Hello,

I'm developing an extension that's fairly computationally intensive and have been occasionally getting incorrect account balances (eg once every 20-30 runs). I originally discovered the problem using AccountUtil.getBalancesAsOfDates() on security type accounts, but I can also reproduce the problem using AccountUtil.getAccountBalance() on investment accounts. I'm not sure if account type matters actually.

To isolate the problem, I created a very simple python script that iterates on calculating a sum of balances for all investment accounts and checking that the sum is the same each time through.

With my data file, this script detects a discrepancy after between 10,000 and 50,000 iterations (less than 1 minute), but ONLY if I have SYNCING ENABLED on my data file. If I turn syncing off, the script seems to run indefinitely without any errors (left running for 1 hour to test this).
 
My data file has over 100 security accounts, a few dozen investment accounts, and a couple of decades worth of transaction data (imported from quicken). I tried to reproduce the problem with dkfurrow's testMD02 data file from github and was NOT able to reproduce the problem even after turning on syncing on the file. It's possible this is due to something in my data file, but I suspect any file with enough accounts and transactions will do.
 
Here's the contents of the python script:

from com.infinitekind.moneydance.model import AccountUtil

book = moneydance.getCurrentAccountBook()
print "Running account balance consistency test..."
loopCount = 0
done = 0
while (done == 0):
 loopCount = loopCount + 1
 totalBalance = 0
 for acct in AccountUtil.getAccountIterator(book):
   if acct.getAccountType() == acct.AccountType.INVESTMENT:
      totalBalance += acct.getBalance()/100.0
 if loopCount == 1:
   initialBalance = totalBalance
 elif totalBalance != initialBalance:
   print "Balance discrepancy detected after {:0d} iterations. Initial balance: {:1,.2f} Incorrect balance: {:2,.2f}".format(loopCount, initialBalance, totalBalance)
   done = 1
 elif (loopCount % 5000) == 0:
   print "{0:d} Iterations".format(loopCount)
 if loopCount >= 100000:
   print "Completed {:0d} iterations. Exiting...\n".format(loopCount)
   done = 1

  1. System closed this discussion on 03 Dec, 2019 07:00 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac