1. Variables
What is the optimizer allowed to choose? In a basic portfolio problem, the variable is usually the weight vector w.
Your first durable skill: looking at a portfolio problem and naming the variables, data, objective, constraints, and solver family.
Optimization is disciplined choosing. A solver does not understand "build me a good portfolio"; it understands a mathematical formulation. The core move is to separate what the solver may choose from what is fixed while it chooses.
What is the optimizer allowed to choose? In a basic portfolio problem, the variable is usually the weight vector w.
What is known at solve time? Expected returns mu, covariance Sigma, current holdings, and cost estimates are data.
What single score is being optimized? A common score rewards expected return and penalizes risk and trading cost.
What must always be true? Examples: fully invested, long-only, leverage cap, turnover cap, or sector exposure bounds.
The official CVXPY quadratic-program example gives a finance case in which portfolio allocation balances expected return and variance under long-only and full-investment constraints. The MOSEK Portfolio Optimization Cookbook organizes a much wider set of portfolio formulations, including Markowitz optimization, transaction costs, robust optimization, and multiperiod optimization.
Suppose you allocate across n assets, with expected returns mu and covariance matrix Sigma. A simple long-only Markowitz-style problem is:
choose w in R^n
maximize mu' w - gamma * w' Sigma w
subject to 1' w = 1
w >= 0
Read it literally: choose portfolio weights; reward expected return; penalize variance; require all capital to be allocated; forbid short positions. The parameter gamma controls how expensive risk is. Larger gamma usually pushes the solution toward lower-variance portfolios.
Single-period optimization chooses today's portfolio. Multiperiod optimization chooses a plan over several future periods: trade now, anticipate future risks/costs/constraints, then usually execute only the first trade and re-solve later. Boyd et al. describe this as closely related to model predictive control.
single-period: choose w_today
multiperiod: choose w_1, w_2, ..., w_T
execute first trade
update forecasts
solve again
The mental pieces stay the same. There are more variables, more data indexed by time, and constraints that connect periods, but the formulation discipline does not change.
maximize mu' w - gamma * w' Sigma w, what is w?Read the first two pages of "Multi-Period Trading via Convex Optimization" by Boyd et al. slowly. Your job is not to understand every equation yet; it is to identify variables, data, objective terms, and constraints.
Keep the formulation glossary open while reading. For broad optimization background, add Brunton's Optimization Bootcamp to your reading queue.