# D14-F04-A05 — Tax-Aware Portfolio Optimization ## Learning contract **Question:** How does an optimizer choose final holdings and *which acquisition lots to sell*, while keeping modeled tax consequences, execution costs, cash settlement, and jurisdictional rules explicit? Readers should be able to calculate a lot's realized gain and illustrative tax score; distinguish tax-lot choice from the whole-portfolio optimum; and recognize when missing basis, policy, or future repurchase information makes a tax result unsupported. Prerequisites are one-period portfolio optimization and a signed rebalance. This is an **article-mode teaching package**: [ARTICLE.md](article/ARTICLE.md), [REFERENCES.md](REFERENCES.md), the SVG/Mermaid explanation, and the guided HTML lab are its teaching deliverables. It is not a filing calculator or production trading implementation. ## Frozen teaching model The article follows the lot-aware Markowitz structure in [Moehle et al.](https://web.stanford.edu/~boyd/papers/tax_aware_portfolio.html), restricted to a one-period, one-currency, separable **illustrative** lot score. Let `h_init` and `h` be pre/post-trade risky holdings in base-currency dollars, `u=h-h_init`, `h_b` a target, `a` a one-period expected trade-return vector, `V` a symmetric positive-semidefinite risk matrix, and `κ` a per-trade cost vector. Define `C(u)=κᵀ|u|`. A teaching utility is ```text U = aᵀu − γ_risk (h−h_b)ᵀV(h−h_b) − γ_tc C(u) − γ_tax L_policy(u). ``` All trade-off coefficients are declared and chosen so the utility terms have the same dollar scale and horizon; in the toy oracle, `V` has inverse-dollar units. No tax rate or holding-period status is inferred. For a sale of `s_ij` **dollars** from lot `j` of asset `i` at price `p_i` with per-share basis `b_ij` and illustrative rate `ρ_ij`, define the modeled tax score `T_ij s_ij`, where `T_ij=ρ_ij(1−b_ij/p_i)`. Require `0≤s_ij≤q_ij p_i` and `Σ_j s_ij=max(−u_i,0)`. A purchase has no immediate sale score. Under this **separable** profile and a *fixed sale size*, selecting smallest `T_ij` first minimizes the score. This is a model result, not a universal statutory lot-ordering rule. The model has an explicit cash convention. If the tax score is an **objective-only forecast**, set `tax_cash=0`. If an applicable tax amount is actually settled at trade, specify that policy and use `c_post=c_init−Σu−C(u)−tax_cash`; never count the same amount twice. A negative modeled score represents a possible loss benefit under the toy objective, **not a cash refund or an automatically deductible tax loss**. Lot sales cannot exceed validated holdings; missing jurisdiction, account scope, basis, acquisition date, adjustment state, or policy version/effective date prevents a real tax conclusion. ## Independent synthetic fixtures 1. **Lot choice, not portfolio optimum:** On 2026-01-02, asset A is marked at \$100. Lot A1 has four shares at \$40 basis/share with illustrative `ρ=.15`; A2 has two shares at \$95 with illustrative `ρ=.35`. A1 is assumed acquired earlier than A2 solely to define the oldest-first comparison; these coefficients are not inferred statutory rates. A \$100 sale scores `$9` from A1 but `$1.75` from A2, so the toy least-score choice is one A2 share. Asset B at \$50 with one \$60-basis share and illustrative `ρ=.15` would score `−$1.50`; that is conditional objective arithmetic only. All values are synthetic. 2. **Whole-portfolio exact two-asset oracle:** `h_init=[500,500]`, `h_b=[600,400]`, `a=[.04,0]`, `V=diag(.0001,.0001)`, `γ_risk=γ_tax=1`, `γ_tc=0`, `Σu=0`. The synthetic lots have 500 one-dollar shares each, with sale scores `T_A=.05`, `T_B=.01`. Write `u=[x,−x]`, `−500≤x≤500`. For `x≥0`, `U=.03x−.0002(x−100)²`, maximized at `x=175`, so `h*=[675,325]` and `U*=4.125`. For `x≤0`, `U=.09x−.0002(x−100)²`, whose maximum on the closed branch is the shared no-trade boundary `x=0` with `U=−2`. Thus the stated candidate is the global optimum **of this restricted toy model**. The two fixtures answer different questions. The first tests a sale-lot ranking; the second tests a whole allocation. Neither proves real after-tax performance. ## Policy, data, and failure boundaries Tax rules are jurisdiction- and date-specific. U.S. [IRS Publication 550](https://www.irs.gov/publications/p550) describes adequate identification, basis, and wash-sale rules for its scope; U.K. [HMRC HS284](https://www.gov.uk/government/publications/shares-and-capital-gains-tax-hs284-self-assessment-helpsheet) uses share matching/pooling; [Canada's CRA](https://www.canada.ca/en/revenue-agency/services/tax/individuals/topics/about-your-tax-return/tax-return/completing-a-tax-return/personal-income/line-12700-capital-gains/capital-losses-deductions.html) describes a superficial-loss rule. These are contrasts, not three modes implemented by this package. For a real policy, retain taxpayer/account scope, trade and acquisition dates, cost-basis elections and evidence, realized-gain/loss handling, carryovers, known purchases, future repurchase state, corporate-action adjusted units/basis, FX basis, and source/knowledge timestamps. If a future wash-sale window has not elapsed, report `future_window_unverified` rather than “clear.” The paper's full tax-aware problem is generally nonconvex; fixing buy/sell direction gives convex subproblems, while its relaxation is an approximation, not an exact certificate. A full implementation must preserve solver status, bound/gap, cash residual, and policy state. Historical named case: **deferred**. A useful case needs publication rights and reproducible dated lot/acquisition/adjustment data plus the correct jurisdiction and policy effective date. We use synthetic inputs rather than imply a public security's tax treatment. ## Reader exercises For the fixed-sale fixture, a \$300 sale uses A2's \$200 capacity then \$100 from A1: score \$12.50 versus \$27 oldest-first. At \$600, both orders liquidate all lots and score \$39.50. A synthetic two-for-one split changes ten shares with \$40 per-share basis into twenty shares with \$20 basis, preserving \$400 total basis under the stated simple split assumption.