liveBook · Manning

Effective tax rate

As explained in Build a Robo-Advisor with Python (From Scratch)

An effective tax rate is the percentage of a sale's gain or loss used to determine the applicable tax impact for a particular holding.

An effective tax rate estimates the tax impact of selling a particular holding by multiplying its percentage gain or loss by the applicable tax rate. It varies with both appreciation and holding period, so shares bought at different prices or times should be evaluated separately as tax lots. section 13.2.3

Comparing four tax lots

With a current price of $110, short-term gains taxed at 40%, and long-term gains at 20%, four lots produce effective rates of 7.5%, 11.76%, 1.90%, and −1.74%. The negative rate reflects a loss, making that lot the first candidate under a lowest-rate rule. section 13.2.3

A practical tax-aware sale process is:

  • Compute each lot’s holding period, applicable rate, percentage gain or loss, and effective rate. section 13.2.3
  • Order lots by effective rate and sell from the lowest-rate lot until the requested share quantity is reached. section 13.2.3
Listing 13.3 Calculating tax exposure
import datetime as dt

lt_gains_rate = 0.20
income_rate = .40
current_price = 110
current_date = dt.date(2022, 5, 11)

lots = pd.DataFrame({'price': [80, 85, 105, 115],
                     'quantity': [25, 30, 20, 10],
                     'purchase_date': ['2021-02-10', '2021-07-21',
                                       '2021-11-23', '2022-03-25']})

tax_info = {}
for i in lots.index:
    lot_info = lots.iloc[i]
    purchase_date = dt.date.fromisoformat(lot_info['purchase_date'])
    holding_period = (current_date - purchase_date).days
    if holding_period <= 365:
        lot_rate = income_rate
    else:
        lot_rate = lt_gains_rate

    purchase_price = lot_info['price']
    gain = (current_price / purchase_price - 1)
    effective_rate = gain * lot_rate

    tax_info[i] = pd.Series({'holding_period': holding_period,
                             'applicable_rate': lot_rate,
                             'pct_gain': gain,
                             'effective_rate': effective_rate})

tax_info = pd.DataFrame(tax_info).T

Inspect the Python implementation that calculates holding periods, applicable rates, gains, and effective rates for each lot. section 13.2.3

How Build a Robo-Advisor with Python (From Scratch) covers it

How deep it goes
Calculates rates from holding periods, gains, and tax brackets, then applies them to a share-selection algorithm.
Examples
Uses four priced tax lots and selects 35 shares by ordering their calculated effective rates.
What it assumes
Assumes tax rates, purchase prices, quantities, purchase dates, and current prices are available for each lot.
What you can do after
Operate a simple Python tax-lot selector that prioritizes shares with the lowest calculated effective tax rate.
How it connects
Connects tax lots, capital gains, holding periods, portfolio rebalancing, and trade execution.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build a Robo-Advisor with Python (From Scratch). The section links point to the parts of the book it draws on.