Step-by-Step Guide to Portfolio Construction with Transaction Costs
Portfolio construction in quantitative finance isn't just about chasing alpha—it's a battle against frictions like decay, costs, and risk. We'll incorporate alpha decay , impact models , risk constraints , and optimizer settings into a realistic mean-variance optimization framework. I'll assume you're working in Python (e.g., with CVXPY or SciPy) or a similar setup, but the logic is tool-agnostic.
Think of it as a detective story: signals are clues (alpha), but they fade (decay), trading them costs (impact), and you must stay within bounds (risk) while solving the optimization puzzle efficiently.
Step 1: Generate and Decay Alpha Forecasts
Raw Alpha : Start with your signal(s)—e.g., factor scores, ML predictions, or momentum. Let (\alpha_t) be the expected excess return vector for (N) assets over horizon (H) (e.g., 1 week).
Alpha Decay : Signals aren't timeless. Model decay as (\alpha_{t,h} = \alpha_t \cdot e^{-\lambda (h - t)}), where:
(\lambda): Decay rate (e.g., 0.1/day for short-horizon signals, estimated from backtests).
(h - t): Time since signal generation.
Why? Half-life might be 3-5 days for intraday signals, longer for fundamentals.
Implementation :
python Copy code
import numpy as np
decay_lambda = 0.1 # Tune via backtest
time_since_signal = np.arange(1, 8) # Days
decayed_alpha = raw_alpha * np.exp(-decay_lambda * time_since_signal[:, None])
Output : Forward-looking expected returns (\mu = decayed_alpha).
Step 2: Model Transaction Costs
Transaction costs erode alpha, so predict turnover and penalize it.
Components :
Fixed Costs : Commissions (e.g., 1-2 bps).
Spread Costs : Half bid-ask (e.g., 2-5 bps for liquid stocks).
Market Impact : The killer for large portfolios. Use an Almgren-Chriss model :
[
Impact(q) = \sigma \sqrt{\frac{V}{ADV}} \cdot \eta \cdot |q|
]
(q): Trade size as fraction of daily ADV (Average Daily Volume).
(\sigma): Stock volatility.
(V): Trading urgency (e.g., 1 for urgent).
(\eta): Impact coefficient (e.g., 0.1-0.5 bps per % ADV, estimated per asset class).
Temporary (price reversion) vs. permanent (walk-up) impact: Split 70/30.
Total TC : (TC(w, w_{prev}) = \sum |w_i - w_{prev,i}| \cdot (spread/2 + impact_i)), where (w) is target weights.
Turnover Penalty : Expected cost = (TC \cdot \mu_{decay}), where (\mu_{decay}) is decayed alpha (opportunity cost of delay).
Implementation (simplified):
python Copy code
def transaction_costs(w_new, w_old, adv, sigma, eta=0.3):
turnover = np.abs(w_new - w_old).sum()
q = turnover / adv # Fractional ADV
impact = eta * sigma * np.sqrt(q)
return turnover * (spread + impact)
Step 3: Build the Risk Model and Constraints
Covariance Matrix (\Sigma) : Use factor models (e.g., Barra) or EWMA for short horizons. Forecast over (H).
[
Risk = \sqrt{w^T \Sigma w} \leq risk_budget \quad (e.g., 5% vol)
]
Key Risk Constraints :
Constraint Type Math/Form Typical Bound Rationale Total Vol (\sqrt{w^T \Sigma w} \leq \sigma_{max}) 3-10% Leverage control Value-at-Risk (VaR) (VaR_\alpha(w) \leq VaR_{max}) 95% VaR < 2% Tail risk Sector/Style Neutral (\sum_{i \in sector} w_i = benchmark_{sector}) ±2% tracking error Diversification Long-Short (\sum w_i^+ = \sum w_i^- ), (|w|_1 \leq L) (leverage) Turnover (|w - w_{prev}|1 \leq T {max}) 20-50%/rebalance Cost control Position Limits ( w_i \leq pos_{max}) Liquidity (w_i \cdot ADV_i \geq liq_{min}) >$10M/day notional Executability
Implementation Tip : Use conic optimization for quadratic constraints.
Step 4: Set Up the Optimizer
Objective: Maximize risk-adjusted alpha net of costs :
[
\max_w \quad \mu^T w - \lambda_{risk} w^T \Sigma w - TC(w, w_{prev})
]
(\lambda_{risk}): Risk aversion (e.g., 2-5 for Sharpe targeting).
Add decay: Scale (\mu) by remaining half-life.
Optimizer Settings (critical for stability—poor settings = garbage weights):
Parameter Recommended Why/Tune Solver CVXPY + ECOS/MOSEK (conic), or QuadProg Handles quadratics + inequalities Tolerance 1e-6 to 1e-8 Primal/dual feasibility; tighter = precise but slower Max Iterations 1000-5000 Avoid early termination on large N (>1000 assets) Warm Start Use (w_{prev}) Speeds convergence 10x Regularization L1/L2 penalty on (w) (ridge=0.01) Prevents corner solutions (100% in one stock) Turnover Scaling (\gamma \cdot TC), (\gamma=1-10) Tune to match live turnover Rebalance Frequency Daily/weekly, but optimize decay-aware Decay fast? Rebalance more
Full Python Sketch (CVXPY):
python Copy code
import cvxpy as cp
w = cp.Variable(N)
risk = cp.quad_form(w, Sigma)
tc = transaction_costs(w, w_prev) # Linear approx for solvability
objective = mu @ w - risk_aversion * risk - gamma * tc
constraints = [
cp.norm(w, 1) <= leverage,
cp.norm(w, 2) <= pos_max,
risk <= vol_max**2,
turnover(w, w_prev) <= turnover_max,
# Sector sums == benchmark
]
prob = cp.Problem(cp.Maximize(objective), constraints)
prob.solve(solver=cp.ECOS, eps=1e-7, max_iters=2000, warm_start=True)
optimal_w = w.value
Step 5: Post-Optimization Checks and Iteration
Diagnostics :
Projected Sharpe: ((\mu^T w) / \sqrt{w^T \Sigma w}).
TC Projection: <10-20% of gross alpha.
Stress Test: Simulate ±50% impact.
Backtest Loop : Optimize → Simulate trades → Measure decay-adjusted PnL → Tune (\lambda, \eta, \gamma).
Edge Cases :
Low liquidity? Add ADV-weighted decay.
Regime shifts? Dynamically estimate (\Sigma, \lambda).
Final Tips from the Deductive Lens
Alpha Decay Rules All : If half-life < rebalance freq, you're toast—shorten horizon.
Impact is Nonlinear : Small portfolios ignore it; AUM>$1B demands it.
Iterate Live : Use Kalman filters for real-time (\mu, \Sigma).
Common Pitfalls : Ignoring decay leads to 50% PnL bleed; loose tolerances = unstable weights.
This framework turns naive mean-variance into production-ready. Backtest ruthlessly—data doesn't lie. Questions on code or tuning? Fire away.