apportion

Performs a apportioning operation common in accounting and finance. Expects a sequence of transactions. Each transaction is vector of the form [source-id, source-amount, target-id, target-amount]. Relief is performed in the order of transaction appearance.


pebblestream:from(“Transactions”)
pebblestream:apportion(“Buys.id”,”Buys.amount”,”Sales.id”,”Sales.amount”)

Consider a Transactions worksheet of paired buy-sale transactions, ordered by transaction date.

Buy.idBuy.amountSale.idSale.amountGain/Loss
110003200-50
110004900100
22503200-50
22504900100
📘

Use cartesian product to easily create worksheet from Buy and Sale worksheets.


This will produce the following worksheet "Apportion".


Buy.idSale.idapportion:source-ratioapportion:source-amountapportion:target-ratioapportion:target-amount
130.22001200
140.88000.889800
230.82001200
240.2500.05650
📘

Note that ratio of relieve for both the buys (source) and the sales (target) is conveniently provided. Use those ratios to determine the share of Gain/Loss associated with each lot.


Download the example below.

Example