TheInfiniteKind / moneydance_open

17 stars 12 forks source link

Security Lot Matching Error #70

Closed sreilly closed 6 months ago

sreilly commented 2 years ago

Reported by reznor in a slack thread:

I've found a problem with the code that displays lot matching for a security. I thought I had some corrupted data but it appears to be a program issue. I can reproduce with this: • Create a new security in an investment account • Purchase (BuyXfr) 100 shares on 1/1/22 and then 50 shares on 1/5/22 • Sell 50 shares on 1/10/22 matched to the 1/5/22 purchase • Stock splits 2/1 on 1/15/22 • Sell 200 (split adjusted) shares on 1/20/22 matched the the 1/1/22 purchase When selecting the 1/10/22 date in the lot matching window it should show two lots: 1/1/22, 100 shares available, 0 allocated 1/5/22, 50 shares available, 50 allocated But instead the 1/10/22 date shows: 1/1/22, -100 shares available, 0 allocated 1/5/22, 50 shares available, 50 allocated While the 1/20/22 date shows: 1/1/22, 200 shares available, 200 allocated 1/5/22, 0 shares available, 0 allocated Whatever is calculating that -100 entry is incorrect.

dummy security used to test: image

the lots: image image

and a file that shows the issue: Personal Finances-20220310-1013.moneydancearchive.zip

RockyRoads2591 commented 2 years ago

This is also the likely source of errors in calculating cost basis when there has been a split. It was reported as a bug on April 24 in the Moneydance support forum by Bob B with attachments. After today's Amazon split, cost basis is also incorrect.

yogi1967 commented 7 months ago

Ok. This is an issue. I almost thought it wasn't as the symptom doesn't actually appear until you match the 200/100 (using this example). Ie - before you match, it all visually looks ok. This match crosses a split date. TBH - I'm puzzled that more people haven't complained about this...

Anyway, I'm investigating...

FYI - the cost basis code has been recently rewritten (unifying code for both lots and average) and should be included in the next preview. I actually think this issue could be cosmetic and that the matched data is correct. I hope the cost basis and gains, in the next preview, actually deal with this properly.

Anyway, I'll see if I can pinpoint the actual error in the lot window....

yogi1967 commented 7 months ago

Confirmed this is cosmetic.

I have provided and tested a code fix for this issue. It's with IK to review.

In your scenario CapitalGains was correct.

As mentioned, there are fixes coming anyway with a new cost basis / capital gains calculations that should fix other issues you allude to.

yogi1967 commented 6 months ago

FYI. This should be in the latest Alpha MD2024(5101)