# First-In-First-Out (FIFO) rule in calculating average buy price

Hi Evan,

Just to check if StockCafe has this feature where when I partial liquidate some of my counter, the system will recalculate the average buy price based on First-In-First-Out (FIFO) rule?

Let’s take my transaction history below as example:

Counter Action Date Qty Price Contract Value after comm
PaySign, Inc SELL 29-Oct-20 USD 416 4.85 2,006.80
PaySign, Inc BUY 10-Sep-20 USD 179 5.62 1,016.66
PaySign, Inc BUY 3-Sep-20 USD 159 6.29 1,010.81
PaySign, Inc BUY 17-Aug-20 USD 136 7.4 1,017.09
PaySign, Inc BUY 22-Jul-20 USD 108 9.5 1,036.70
PaySign, Inc BUY 24-Jun-20 USD 361 8.05 2,916.75

Total Buy Qty = 943, Total Buy contract value after comm = 6,998.01

If we use the cost basis (non-FIFO), my average buy price after partial liquidation will be
the same as before the liquidation, ie 6,998.01 / 943 = USD7.421

However, if we use FIFO rule, where my earliest buy trade will be squared off first, followed by the 2nd earliest, the table will become like this:

Counter Action Date Qty Price Contract Value after comm
PaySign, Inc SELL 29-Oct-20 USD 416 4.85 2,006.80
PaySign, Inc BUY 10-Sep-20 USD 179 5.62 1,016.66
PaySign, Inc BUY 3-Sep-20 USD 159 6.29 1,010.81
PaySign, Inc BUY 17-Aug-20 USD 136 7.4 1,017.09
PaySign, Inc BUY 22-Jul-20 USD 53 9.5 543.90

Total Buy Qty remained = 527, Total Buy contract value after comm remained = 3,588.46

In this case, with FIFO my average buy price after partial liquidation will now become
3,588.46 / 527 = USD6.81

Such differences (USD7.421 vs USD6.81) will affect how the PnL figures of existing positions to be reported & many brokerage platforms follow the FIFO rule.

My apologies for such lengthy feedback.