Valuating sum to continue process

Hi @babagrebler

So nobody came to my rescue … :weary: :rofl:

But it was a very good coffee, with plenty of caffeine… so here goes! I think that somewhere in this workflow (hopefully at the bottom) are the answers you need.

I think it gives more than you asked for, but maybe the rest is useful too. Although perhaps it isn’t in exactly the format you need the information, but you should be able to adapt the output from the four end nodes for your purposes:

There may be a better mathematical approach to this problem and maybe the use of iterators, but as is common for me, I try to avoid iteration if I can (which is probably why it took me so long to develop the answer).

The approach I took came from this idea: imagine for every single share purchased, you received a single share certificate, so 1584 shares resulted in 1584 certificates. Now if you lay all your certificates out on the floor in order of purchase, then when you sell them, you pick them up off the floor in that same order, and sell those shares. Well that is what this workflow does. For Stock “A” It takes 1584 + 1584 + 1060 shares and generates 1584 +1584 +1060 “buy records”. It takes 1584+1500 sold shares and generates 1584+1500 sold records. It then matches them up in sequence to find out which purchased shares were sold. It then groups back the result and works out what the resultant stock values and profit/loss will be. Well, ok it is slightly more than that, but in essence that is all it does!

One last thing though… please don’t base your tax affairs on this without testing it out to your satisfaction! Best endeavours, but use at your own risk as I can’t be held responsible if it there is an error in my calculation :wink:


KNIME_sale of shares.knwf (70.7 KB)

7 Likes