Icon

KNIME_​sale of shares

Workflow to process a SELL table against a BUY table, by determining on a First In First Out basis which stock was sold against which purchase.

The process creastes an intermediate table of single shares, so for example the purchase of 1584 shares of stock A results in a table of 1584 "purchase records" for that stock.

Likewise for a SALE of 1584 shares.

The two are then compared on a row-for-row basis (linked by sequence number). From this we can determine which sale was made against which purchase. After that, we group them back up into their original groupings, and calculate what has happened..... simples... lol!

01 May 2021 @takbb Brian Bates

Derive our list of purchased shares Derive our list of sold shares Join the purchase of astock (LEFT/TOP)toits correspondingsale (RIGHT/BOTTOM)(in same order) Outputs are:TOP (joined)Purchases that havebeen soldMIDDLE (Unsold)BOTTOM (Should beempty, unless you'vestolen them!!!!) The "Remaining Value" output is theremaining value derived from the SALEIf everything worked out correctly, thesetwo outputs should be effectively thesame information, albeit that we haveincluded the unsold items to the BUYtable output. Determine the profit/loss based on the sales dates comparedwith the different original purchases that those sales were madeagainst Workflow to process a SELL table against a BUY table, by determining on a First In First Out basis which stock was soldagainst which purchase.The process creastes an intermediate table of single shares, so for example the purchase of 1584 shares of stock A resultsin a table of 1584 "purchase records" for that stock.Likewise for a SALE of 1584 shares.The two are then compared on a row-for-row basis (linked by sequence number). From this we can determine which salewas made against which purchase. After that, we group them back up into their original groupings, and calculate what hashappened..... simples... lol!01 May 2021 @takbb Brian Bates SELLEnsure we keep record of orderfor FIFO ruleEnsure we keep record of orderfor FIFO ruleWe now have one row per share in order of purchaseWe now have one row per share in order of saleRank each of the rows within stock in order of purchaseBUYOrder by Stock and original row numberOriginalBuy RowNumberOriginal Sale RowNumberOrder by Stock and original row numberRank each of the rows within stock in order of saleMatch up Buy and SellGroup by Stock and Original Purchase and aggregate the sale values of each share soldRe-Calc Purchase Value per lineGroup Unsold Stockin original purchaselinesNode 112Remaining BUYRemaining Value of stockGet Profit / LossBy joining new values withold linesUse "Rate" asUnit Sale ValueDetermine ProfitNode 118Determine Qty RemainingPurchase Value RemainingFill in zeroes whereno sale againsta purchaseBUY tableCarried ForwardResultant BUY tableProfit / Loss Tableby Stock/PurchaseGroup SOLD Stockbased on Sale and Purchase groupingsNode 127Calc Sale Value per lineNode 130Profit / Loss tableby Stock SaleRe-Calc Purchase Value per line Table Creator Counter Generation Counter Generation One Row to Many One Row to Many Rank Table Creator Sorter Column Rename Column Rename Sorter Rank Joiner (Labs) GroupBy Math Formula GroupBy Sorter Sorter Math Formula Joiner Math Formula Math Formula Column Rename Math Formula Math Formula Missing Value Column Filter Column Rename Column Filter GroupBy Sorter Math Formula Column Rename Math Formula Math Formula Derive our list of purchased shares Derive our list of sold shares Join the purchase of astock (LEFT/TOP)toits correspondingsale (RIGHT/BOTTOM)(in same order) Outputs are:TOP (joined)Purchases that havebeen soldMIDDLE (Unsold)BOTTOM (Should beempty, unless you'vestolen them!!!!) The "Remaining Value" output is theremaining value derived from the SALEIf everything worked out correctly, thesetwo outputs should be effectively thesame information, albeit that we haveincluded the unsold items to the BUYtable output. Determine the profit/loss based on the sales dates comparedwith the different original purchases that those sales were madeagainst Workflow to process a SELL table against a BUY table, by determining on a First In First Out basis which stock was soldagainst which purchase.The process creastes an intermediate table of single shares, so for example the purchase of 1584 shares of stock A resultsin a table of 1584 "purchase records" for that stock.Likewise for a SALE of 1584 shares.The two are then compared on a row-for-row basis (linked by sequence number). From this we can determine which salewas made against which purchase. After that, we group them back up into their original groupings, and calculate what hashappened..... simples... lol!01 May 2021 @takbb Brian Bates SELLEnsure we keep record of orderfor FIFO ruleEnsure we keep record of orderfor FIFO ruleWe now have one row per share in order of purchaseWe now have one row per share in order of saleRank each of the rows within stock in order of purchaseBUYOrder by Stock and original row numberOriginalBuy RowNumberOriginal Sale RowNumberOrder by Stock and original row numberRank each of the rows within stock in order of saleMatch up Buy and SellGroup by Stock and Original Purchase and aggregate the sale values of each share soldRe-Calc Purchase Value per lineGroup Unsold Stockin original purchaselinesNode 112Remaining BUYRemaining Value of stockGet Profit / LossBy joining new values withold linesUse "Rate" asUnit Sale ValueDetermine ProfitNode 118Determine Qty RemainingPurchase Value RemainingFill in zeroes whereno sale againsta purchaseBUY tableCarried ForwardResultant BUY tableProfit / Loss Tableby Stock/PurchaseGroup SOLD Stockbased on Sale and Purchase groupingsNode 127Calc Sale Value per lineNode 130Profit / Loss tableby Stock SaleRe-Calc Purchase Value per lineTable Creator Counter Generation Counter Generation One Row to Many One Row to Many Rank Table Creator Sorter Column Rename Column Rename Sorter Rank Joiner (Labs) GroupBy Math Formula GroupBy Sorter Sorter Math Formula Joiner Math Formula Math Formula Column Rename Math Formula Math Formula Missing Value Column Filter Column Rename Column Filter GroupBy Sorter Math Formula Column Rename Math Formula Math Formula

Nodes

Extensions

Links