A closed tax lot is a tax lot whose remaining share quantity has reached zero after disposal. Unlike an ordinary position update, a tax-loss-harvesting backtester retains closed lots so later wash-sale checks can examine their sell date, sell price, and realized loss. section 14.4.1 section 14.2.2
Representing a closed lot requires preserving its historical state:
- Store the original ticker, purchase price, quantity, and purchase date. section 14.2.2
- Record the sell price and sell date instead of discarding the row when its quantity reaches zero. section 14.4.1 section 14.2.2
A closed VTI lot
A VTI lot purchased at $90 is sold at $75 on 2022-04-01. Its sell price and sell date remain in the tax-lot table, and its still_held status becomes false. The record can therefore document the realized loss and help determine whether a later VTI purchase creates a wash sale. section 14.2.2
import datetime as dt
import numpy as np
import pandas as pd
lots = \
pd.DataFrame({'ticker': ['VTI', 'VTI', 'VTI'],
'purchase_price': [90, 85, 105],
'quantity': [25, 30, 20],
'purchase_date': ['2021-02-10', '2021-07-21',
'2022-03-15'],
'sell_price': [75, np.NaN, np.NaN],
'sell_date': ['2022-04-01', np.NaN, np.NaN],
})
Inspect a pandas DataFrame containing two open VTI lots and one closed lot with recorded sale details. section 14.2.2
