Free lesson · Trading algorithms
PCA, clustering, risk parity and quadratic programming
Open interactive lessonPractice calculationsExplore labs
Start with the idea
Some trading algorithms organise risk or allocate capital rather than predict returns. Their output is a representation or a feasible portfolio, which should be evaluated on that task.
Symbols, units & horizon
- σ_i: positive estimated volatility of asset i over a common horizon
- w_i: positive fully invested inverse-volatility weight
- j: asset index in the normalising sum
- Independence: needed for this rule to imply equal volatility risk contributions
- This formula: a heuristic allocation, not a return forecast
When and why to use this
Use inverse volatility as an auditable allocation baseline and a starting point for understanding covariance-aware risk budgeting.
PCA compresses common variation; clustering groups related assets; risk-parity methods target contributions; mean–variance or other convex programmes choose weights under an objective and constraints. Hierarchical risk parity combines a dependence tree with recursive allocation, introducing choices about distance and linkage.
A simple inverse-volatility rule is a useful baseline. It equals equal-risk contribution for independent assets, but not generally under arbitrary correlations. Equal dollars, inverse volatility, minimum variance and expected-return optimisation each encode a different preference.
Use an optimiser when constraints must hold jointly. Post-hoc clipping can break dollar or factor neutrality, and normalising an unconstrained solution changes its objective. Compare stable simple baselines against more elaborate allocations under the same risk estimates, costs and rebalance schedule.
PCA, clustering, risk parity and quadratic programming
- Assign an unnormalised score 1/σ_i so a more volatile asset receives less exposure.
- Sum these scores and divide each by the total to force weights to sum to one.
- For independent assets, each w_iσ_i is the same constant, so each contributes equally to portfolio variance. Correlated portfolios require covariance-aware risk budgeting.
Volatilities 10% and 20% give inverse scores 10 and 5, hence weights 2/3 and 1/3. Equal dollars would be .5/.5 and carry different risk.
Apply it in a strategy
- Choose the portfolio objective and feasible set before selecting the allocation algorithm.
- Compare equal-weight, inverse-volatility and covariance-aware alternatives on future realised risk and net results.
- Audit final constraints, turnover and sensitivity to estimation windows and correlation regimes.
Research deliverable
Report final weights, risk contributions and constraints for each allocator, with the same return forecasts and execution assumptions.
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.
def inverse_volatility(volatilities):
if not volatilities or any(v<=0 for v in volatilities): raise ValueError("Positive volatilities required")
raw=[1/v for v in volatilities]
return [v/sum(raw) for v in raw]
print(inverse_volatility([.1,.2]))Continue learning
Trading Algorithms: A Practical Selection Guide — all lessons- Moving averages, EWMA and momentum/reversion rules
- Kalman filtering: combine a prediction with a noisy observation
- ARIMA for conditional means and GARCH for conditional variance
- Linear models, random forests and gradient boosting
- PCA, clustering, risk parity and quadratic programming
- TWAP, VWAP and percentage-of-volume execution
- Optimal execution: impact versus waiting risk
Quantitative finance and development glossary · Python resources and libraries · Research sources and limitations