Trading Dev AcademyFree quant education

Free lesson · Optimization

Project a desired allocation onto the long-only simplex

Open interactive lessonPractice calculationsExplore labs

Start with the idea

Projection finds the nearest allowed set of weights to a proposed target under a specified distance.

Symbols, units & horizon
  • v_i: desired dimensionless allocation at one rebalance
  • w_i: nearest feasible allocation under sum of squared coordinate distances
  • θ: common threshold in weight units
  • i: asset index

When and why to use this

Use a known projection to check a constrained iterative allocation method.

Projection finds the nearest allowed set of weights to a proposed target under a specified distance.

The probability simplex here means nonnegative weights adding to one. Euclidean projection preserves closeness in squared weight distance; it does not maximize expected portfolio return. It is useful inside projected algorithms and as a small constrained example.

The solution subtracts a shared threshold and clips at zero. Unlike arbitrary clipping followed by normalization, this threshold is derived from the equality constraint and active coordinates. Additional sector or turnover limits require a different projection.

wi=max⁡(vi−θ,0),∑iwi=1
Convex constrained projection and active-set algebra

Project a desired allocation onto the long-only simplex

  1. Minimize half the squared distance from v subject to nonnegative weights summing to one.
  2. For positive weights, the Lagrange first-order condition gives w_i=v_i−θ; inactive coordinates stay zero.
  3. Solve the sum constraint for θ on the active set and verify positive coordinates remain positive.
Work it by hand

For v=[.8,.4,−.2], two coordinates remain active. θ=(.8+.4−1)/2=.1; projected weights [.7,.3,0] sum to one.

Apply it in a strategy

  • Freeze inputs at the stated decision time and record their units.
  • Use a known projection to check a constrained iterative allocation method.
  • Recompute the example, then change the material assumption and explain the difference.

Research deliverable

Project a desired allocation onto the long-only simplex: produce the worked calculation, a timestamped input record and a written decision addressing this limitation: Nearest Euclidean weights need not be nearest in risk or transaction costs.

These are synthetic mechanics examples, not historical performance or paper replications. Module evidence and research boundaries record the 12 September 2026 review.

Python implementation

Self-contained teaching example. Python 3.10+; dependencies and input conventions are shown in the code and notation. Run in your own Python environment.

# Python 3.10+; standard library and NumPy only.
# Synthetic teaching inputs; conventions and units are defined in the notation above.
import numpy as np

def simplex_projection(values):
    v=np.asarray(values,float)
    if v.ndim!=1 or len(v)==0 or not np.isfinite(v).all(): raise ValueError('Finite nonempty vector required')
    u=np.sort(v)[::-1]; sums=np.cumsum(u)
    eligible=np.where(u-(sums-1)/np.arange(1,len(v)+1)>0)[0]
    rho=eligible[-1]; threshold=(sums[rho]-1)/(rho+1)
    return np.maximum(v-threshold,0)

assert np.allclose(simplex_projection([.8,.4,-.2]),[.7,.3,0])
print(simplex_projection([.8,.4,-.2]))

Continue learning

Optimization: Feasibility, Costs & Robust Decisions — all lessons
  1. Exposure constraints before optimization
  2. Curvature and a bounded quadratic decision
  3. Derive the fully invested minimum-variance portfolio
  4. Project a desired allocation onto the long-only simplex
  5. Trading costs and a no-trade decision
  6. An uncertainty bound becomes a position penalty
  7. Read a binding constraint through its shadow price
  8. Numerical residuals and independent solution checks

Quantitative finance and development glossary · Python resources and libraries · Research sources and limitations