dkfurrow / moneydance-investment-reports

Useful Investment Reports Addin for Moneydance Personal Finance Software
3 stars 2 forks source link

Split Transaction causing wrong Cash balance #4

Closed krpradeep closed 2 years ago

krpradeep commented 2 years ago

Recently installed this plugin and till now most of the number looks correct in report expect one I noticed.

Report showing 401k account cash balance wrong. After spending 3-4 hours figuring out what is the reason.

This is the scenario - Receiving paycheck into checking account. In order to capture all deduction from salary I am then splitting that transaction into various category (like fed, state, medical insurance deduction, 401k, commuter account etc). Tax, medical related category are configured as expense in Moneydance but 401k, commuter account are investment and bank account. Now looks like in order to calculate Cash balance it is using not only just 401 amount it is picking all other account (expect expense) from split category and causing cash balance to be in negative.

Lets says for a date 401K - $56 Commuter - $12

Instead of using 56 as Cash balance for that date, it is using 44 (56-12) as cash balance subtracting all bank account from 401k contribution. I was able to use csv to figure out what is happening below is csv relevant extract.

ParentAcct Security Ticker DivFrequency TxnNum Date TxnType Desc Buy Sell Short Cover OpenValue
401kAccount CASH CASH UNKNOWN TxnId2 4/8/2022 BANK INSERTED: -44 0 0 0 44
401kAccount CASH CASH UNKNOWN TxnId1_1 4/8/2022 BUY INSERTED: 0 44 12 0 -12
401kAccount Security1 Ticker1 UNKNOWN TxnId1 4/8/2022 BUY   -56 0 0 0 56

I tried to look into code but since there is not much documentation I kind of got lost.

If someone can guide me where to look for I would be able to create pull request.

dkfurrow commented 2 years ago

Hi; So we don't have a split like that in the test folder, but I do have many in my personal folder, with income offset by taxes, etc and a deposit to a 401k. The transactions on the investment side went correctly, i.e. the entire amount deposited to 401k shows up as a purchase of cash in the 401k account (which cash is then 'sold' to buy and offsetting value of securities. So something is different in your case. Two questions:

  1. On report menu, you'll see tabs up at the top, among them 'Investment Income' and 'Investment Expenses' is your Commuter category defined as an Investment Expense?
  2. So it's typically difficult to diagnose issues because each individual has their own personal records. But we do have a fully functional test dataset here. Can you replicate the issue there? If you can, then we can both be looking at the same data set and reports.
krpradeep commented 2 years ago

Hi

I am able to recreate issue in test dataset. You can check here.

New 2022 txn. Salary coming into Checking account with one tax entry and some part of salary going to Saving account and some going into Brokerage Account 3. When you run report for Brokerage Account 3, cash balance is wrong.

dkfurrow commented 2 years ago

So your forked repo shows as even with mine--could you commit your changes?...I cloned it, but the transactions in the TestMD02 datafile under resources are of course the same as mine. I did a quick test, in checking, a split with 1000 Salary, 100 Income Tax, and 200 transfer to StockBrokerage2 on 08/15/2009...still got the expected result in the investment reports transactions (Buy 200 cash)...details below. Anyway, if you can commit your changes, I'll pull them from your repo and take a look.

0.acctid: 8d8ea535-6943-4028-8e78-57c9ea9fa28b 0.desc: Split Transaction Test 0.id: 13dc0481-0362-4011-b9e3-2d81536ac85c 0.obj_type: 0.oldid: -1 0.pamt: 100000 0.samt: -100000 0.tags: 1.acctid: ec6ebdfb-28fb-4362-868e-1e4fb886a2b8 1.desc: Income Tax Trnsfer 1.id: f71670a8-ab0a-47e3-bd57-06945e5322a1 1.obj_type: 1.oldid: -1 1.pamt: -10000 1.samt: 10000 1.tags: 2.acctid: dde35e39-c1fd-4ef4-8458-44fa671c340c 2.desc: 401(k) Transfer 2.id: c88dc193-683f-44e7-93b4-c707868a149b 2.obj_type: 2.oldid: -1 2.pamt: -20000 2.samt: 20000 2.tags: acctid: 44626d42-89fc-44bd-ab3b-6c871d13c7ac chk: desc: Split Transaction Test dt: 20090815 dtentered: 1649783549005 id: 71e6c2fe-10ca-4e97-8919-b699d6cce471 memo: obj_type: txn oldid: -1 td: 20090815 ts: 1649783708081

krpradeep commented 2 years ago

I think issue happen when you have one more bank account in your salary txn. In your case try adding another split like 150 to saving account.

1000 salary 100 tax 200 transfer to Brokerage and 150 to saving effectively 550 coming to checking account.

I commit all file that git was showing me as changed. Anyway I am attaching screenshot of transaction and report.

Salary-Txn Report

dkfurrow commented 2 years ago

Okay, got it--you still haven't pushed your changes, but I was able to replicate. The problem is in the SplitValues class of the TransactionsValues module...we implicitly assumed that each transaction would have only one investment account, and only one account in the type of Investment, Bank, Asset, or Liability...and your case has 2 banks and 1 investment account in the chain. So we need to ignore that savings account split. That's in that long embedded switch statement that goes through Transaction Type and Account Type...my take me a bit to test this out.

dkfurrow commented 2 years ago

Okay, please have a look at branch 'fix2' and the associated bundled mxt files here. It worked on the test folder, transaction records show buy 700 cash in StockBrokerage3 with correct balance. If that seems right I'll update the test and merge that branch on to master. Thanks!

krpradeep commented 2 years ago

Sorry got busy with something else. Will check after 3-4 days.

krpradeep commented 2 years ago

I am still getting 721.38 as End Pos

Steps -

I pushed my changes into "SplitTxn-Issue" branch of my repo. (which is fork of your repo)

Comparison to master branch of your repo.

dkfurrow commented 2 years ago

So for whatever reason, when I pulled up the test file in your repo, no accounts came up...but in any case, I think the problem was that I didn't recompile the correct mxt file, so that is fixed in my 'fix2' branch here.. For avoidance of doubt, I updated the version number to 221, so if you're running it in application, that's what you should see. I also recorded a desktop video, showing the test transaction and detailing the balances in both the moneydance app and in the extension. Hopefully, you're seeing the same numbers and that the rest of the transactions in your personal file are coming through correctly.

krpradeep commented 2 years ago

After taking new mkt file. It working fine.

Please put fix into master branch.