A transaction cost is an expense incurred when buying, selling, transferring, or modifying an asset or contract. In investing, it extends beyond visible commissions: bid–ask spreads and tax consequences can make frequent trading expensive. section 1.2.3 section 13.1.2
Account for transaction costs when evaluating trades:
- Include the bid–ask spread for both the asset sold and the asset purchased. section 1.2.3 section 14.3.1
- Compare explicit costs and tax effects with the benefit motivating the trade, such as a tax-loss harvest. section 14.3.1
- Recognize that rebalancing can realize capital gains, while frequent trading can create short-term gains that are not tax-efficient. section 1.2.3 section 13.1.2
Net cost of a tax-loss harvest
For a lot with quantity q and current price p, trade size is q × p. The implementation computes spread cost as (sell spread + buy spread) × trade size and commission cost as twice the commission rate times trade size, then subtracts both from the tax benefit. section 14.3.1
Listing 14.11 Measuring benefit of harvesting a loss, net of trading cost
def evaluate_tcost(lot: pd.Series, current_price: float,
sell_spread: float, buy_spread: float,
commission_rate: float = 0):
""" Evaluate a loss harvest based on the cost to execute it """
trade_size = lot['quantity'] * current_price
spread_cost = (buy_spread + sell_spread) * trade_size
commission_cost = 2 * commission_rate * trade_size
return lot['tax_benefit'] - (spread_cost + commission_cost)
Use the supplied Python listing to calculate whether a harvesting trade’s tax benefit exceeds its spread and commission costs. section 14.3.1



