liveBook · Manning

Capital gains tax rate

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

A capital gains tax rate is the tax rate applied to taxable gains from disposing of an investment.

A capital gains tax rate is a model input for estimating the tax owed on investment gains. It helps compare after-tax outcomes when placing assets in retirement or taxable accounts. section 8.1

An asset-level tax model separates the capital gains rate from other assumptions:

  • payout taxes on dividends or interest section 8.1
  • ordinary-income taxes applied to retirement-account withdrawals section 8.1
  • cost basis and turnover, which determine how taxable gains accumulate in a brokerage account section 8.1

Asset-location comparison

A Python Asset instance can assign a 20% capital gains rate to a stock and compare its taxable-account value with retirement-account outcomes. In the supplied projection, placing stocks in a taxable account and bonds in an IRA produces $4,913,923, versus $4,162,819 for the reverse placement.

The rate also determines whether tax-loss harvesting is worthwhile. With a short horizon, gains may not receive long-term treatment; with a 0% current federal rate, harvesting may provide no federal benefit; and a higher future rate can reverse the advantage. section 14.1.3

Listing 8.1 Defining the Asset() class
class Asset():
    def __init__(self, avg_ret=0.08, payout_rate=0.0, tax_rate_payout=0.2,  #1
                 tax_rate_cap_gains=0.2, tax_rate_ord_inc=0.35,  
                 turnover_rate=0, starting_value=500000, cost_basis=500000):
        self.avg_ret = avg_ret
        self.payout_rate = payout_rate
        self.tax_rate_payout = tax_rate_payout
        self.tax_rate_cap_gains = tax_rate_cap_gains
        self.tax_rate_ord_inc = tax_rate_ord_inc
        self.turnover_rate = turnover_rate
        self.starting_value = starting_value
        self.cost_basis = cost_basis
    def IRA_value(self, horizon=30):
        pretax_value = self.starting_value * (1+self.avg_ret)**horizon
        aftertax_value = pretax_value * (1-self.tax_rate_ord_inc)
        return aftertax_value
    def Taxable_value(self, horizon=30):
        curr_cost_basis = self.cost_basis
        curr_value = self.starting_value
        for year in range(1, horizon+1):
            taxes_div = self.payout_rate * curr_value * self.tax_rate_payout
            taxes_cap_gain = (self.turnover_rate * curr_value
                              * self.tax_rate_cap_gains)
            curr_cost_basis += ((self.payout_rate * curr_value)   #2
                               + (self.turnover_rate * curr_value)
                               - (taxes_div + taxes_cap_gain))
            curr_value = (curr_value * (1+self.avg_ret) 
                          - (taxes_div + taxes_cap_gain))
        aftertax_value = (curr_value 
                          - (curr_value - curr_cost_basis) 
                          * self.tax_rate_cap_gains)
        return aftertax_value
    def Taxable_minus_IRA(self, horizon=30):
        difference = (self.Taxable_value(horizon) - self.IRA_value(horizon) 
                      - self.starting_value * self.tax_rate_ord_inc)  #3
        return difference        
   
    def Roth_value(self, horizon=30):
        aftertax_value = self.starting_value * (1+self.avg_ret)**horizon
        return aftertax_value  

Browse the Asset class definition to see the capital gains rate alongside payout taxes, ordinary-income taxes, turnover, starting value, and cost basis. section 8.1

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

How deep it goes
Defines the rate as an Asset attribute and applies it within account projections, then qualifies harvesting benefits by horizon and future rates.
Examples
Uses stock and bond Asset instances, account-value projections, and a 0% federal-rate case to illustrate tax effects.
What you can do after
Apply it via a Python Asset model to compare after-tax account values and assess tax-loss harvesting conditions.
How it connects
Connects capital gains tax rate to asset location, tax-loss harvesting, cost basis, turnover, payout taxes, and ordinary-income taxes.

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.