OptiAlpha is an institutional-grade Python framework for regularized multi-factor alpha combination, dynamic covariance shrinkage, and online signal allocation. It solves the multi-factor aggregation dilemma by trading off expected predictive Information Coefficients (IC), factor portfolio risk,
$L_1$ turnover transaction costs, and factor concentration constraints via accelerated proximal gradient methods (FISTA).
In modern quantitative equity and multi-asset factor investing, the signal construction pipeline follows a rigorous two-stage architecture:
[ Raw Alpha Factors ]
│
▼
┌─────────────────────────────────────────────────────────────┐
│ 1. OrthoQuant (Signal Pre-Processing & Clean-up) │
│ • Cross-Sectional Risk Neutralization (FWL via Thin QR) │
│ • Lowdin Symmetric Orthogonalization (F^T F = I_K) │
└─────────────────────────────────────────────────────────────┘
│
▼ (Orthonormal Residual Factor Streams)
┌─────────────────────────────────────────────────────────────┐
│ 2. OptiAlpha (Alpha Combination & Factor Allocation) │
│ • Ledoit-Wolf Analytical Covariance Shrinkage │
│ • Convex L1-Regularized Turnover Optimization (FISTA) │
│ • Online Exponentiated Gradient Adaptive Weighting │
│ • Meucci Effective Number of Alphas (ENF) Attribution │
└─────────────────────────────────────────────────────────────┘
│
▼
[ Optimized Composite Alpha Score w_t^T F_t ]
| Symbol | Type | Description |
|---|---|---|
| Dimension | Number of assets in the universe ( |
|
| Dimension | Number of candidate alpha factors | |
| Dimension | Number of historical observation periods (trading days) | |
| Matrix | Cross-sectional factor exposure matrix at time |
|
| Vector | Information Coefficient vector ( |
|
| Matrix | Factor covariance matrix | |
| Vector | Factor allocation weight vector | |
| Vector | Previous rebalance weights for turnover control | |
| Scalar | Risk aversion penalty on factor portfolio variance | |
| Scalar |
|
|
| Scalar |
|
|
| Norms | Vector |
|
| Norm | Matrix Frobenius norm |
Let
Let
Let
Let
According to the Fundamental Law of Active Management (Grinold & Kahn, 2000; Qian & Hua, 2004), the unconstrained weight vector
The maximal achievable composite Information Ratio is:
If factors
Proof: Substituting
In practical portfolio management, factor allocations cannot change drastically from period to period due to market friction, slippage, and turnover costs. Furthermore, single-factor concentration must be bounded.
OptiAlpha formulates factor combination as a strictly convex optimization problem:
subject to convex budget and box constraints:
where:
-
$\gamma \ge 0$ : Risk aversion parameter penalizing factor portfolio volatility. -
$\lambda_{\text{turnover}} \ge 0$ :$L_1$ turnover penalty against prior allocation$\mathbf{w}_{\text{prev}}$ . -
$l_k, u_k$ : Lower/upper bounds ($l_k = 0, u_k = 1$ enforces a long-only simplex$\Delta^K$ ).
Because the
where
where dual parameter
Sample covariance matrices
-
Constant Correlation Target (
$\mathbf{T}$ ): Preserves individual sample variances$S_{ii}$ while shrinking cross-sectional correlations to the mean correlation$\bar{r} = \frac{2}{K(K-1)} \sum_{i < j} R_{ij}$ . - Optimal Shrinkage Parameter:
For real-time streaming environments, OptiAlpha provides an online multiplicative update rule (Freund & Schapire, 1997; Kivinen & Warmuth, 1997) guaranteeing sublinear regret
where
Total factor portfolio volatility
Following Meucci (2009), the effective diversification entropy across alpha streams is:
where
| Strategy | Objective Function | Turnover Control | Handles Multicollinearity | Optimal Solver |
|---|---|---|---|---|
| Equal Weighting (1/K) | Heuristic benchmark | None | Poor | Closed-form |
| IC-Weighted | None | Moderate | Closed-form |
|
| Grinold-Kahn Analytical | None | Requires Invertible |
Linear Solve |
|
| OptiAlpha Convex (FISTA) | Rigorous |
Excellent (L2 Ridge + Ledoit-Wolf) | FISTA |
|
| OptiAlpha Online (EG) | Multiplicative Weights Online Regret | Adaptive Decay | Good | Online |
git clone https://github.com/huuan26/OptiAlpha.git
cd OptiAlpha
pip install -e .import numpy as np
import pandas as pd
from optialpha import (
generate_synthetic_alpha_panel,
ledoit_wolf_shrinkage,
convex_alpha_combination,
equal_weight_combination,
information_coefficient,
effective_number_of_alphas,
turnover_ratio,
)
# 1. Generate multi-factor panel (100 assets, 5 factors, 120 periods)
panel = generate_synthetic_alpha_panel(n_assets=100, n_factors=5, n_periods=120)
factors_t0 = panel["factors_panel"][0]
returns_t0 = panel["returns_panel"][0]
ic_history = panel["ic_history"]
# 2. Estimate cleaned covariance matrix via Ledoit-Wolf Shrinkage
shrunk_cov, shrinkage_delta = ledoit_wolf_shrinkage(ic_history, target="constant_correlation")
print(f"Optimal Ledoit-Wolf Shrinkage Intensity (delta): {shrinkage_delta:.4f}")
# 3. Forecast Information Coefficients (Rolling Mean IC)
forecast_ic = ic_history.mean(axis=0).to_numpy()
# 4. Solve Regularized Convex Alpha Combination with Turnover Penalty
w_prior = np.array([0.2, 0.2, 0.2, 0.2, 0.2])
res = convex_alpha_combination(
factors=factors_t0,
ic_vector=forecast_ic,
covariance=shrunk_cov,
risk_aversion=1.5,
turnover_penalty=0.03,
w_prev=w_prior,
lower_bound=0.0,
upper_bound=0.40,
solver="fista",
)
print("\n--- OptiAlpha Allocation Results ---")
print("Optimal Factor Weights:", np.round(res.weights, 4))
print(f"Convergence: {res.converged} in {res.iterations} iterations")
print(f"Predicted Information Coefficient: {res.predicted_ic:.4f}")
print(f"Realized Turnover from Prior Allocation: {res.turnover:.4f}")
# 5. Evaluate Composite Alpha vs Equal-Weight Benchmark
composite_ic = information_coefficient(res.composite_alpha, returns_t0, method="spearman")
eq_alpha, _ = equal_weight_combination(factors_t0)
eq_ic = information_coefficient(eq_alpha, returns_t0, method="spearman")
print(f"\nEqual-Weight Rank IC: {eq_ic:.4f}")
print(f"OptiAlpha Composite Rank IC: {composite_ic:.4f}")
# 6. Measure Effective Diversification (Meucci ENF)
enf = effective_number_of_alphas(res.weights, shrunk_cov)
print(f"Effective Number of Alphas (ENF): {enf:.2f} / 5.00")Run the full test suite with coverage report:
pytest- Grinold, R. C., & Kahn, R. N. (2000). Active Portfolio Management: A Quantitative Approach for Producing Superior Returns and Controlling Risk (2nd ed.). McGraw-Hill.
- Qian, E. E., & Hua, R. H. (2004). Active risk and information ratio in multi-factor models. The Journal of Portfolio Management, 30(3), 20–34.
- Ledoit, O., & Wolf, M. (2004). A well-conditioned estimator for large-dimensional covariance matrices. Journal of Multivariate Analysis, 88(2), 365–411.
- Beck, A., & Teboulle, M. (2009). A fast iterative shrinkage-thresholding algorithm for linear inverse problems. SIAM Journal on Imaging Sciences, 2(1), 183–202.
-
Duchi, J., Shalev-Shwartz, S., Singer, Y., & Chandra, T. (2008). Efficient projections onto the
$l_1$ -ball for predictors in high dimensions. ICML, 272–279. - Meucci, A. (2009). Managing diversification. Risk, 22(5), 74–79.
- Choueifaty, Y., & Coignard, Y. (2008). Toward maximum diversification. The Journal of Portfolio Management, 35(1), 40–51.
- Freund, Y., & Schapire, R. E. (1997). A decision-theoretic generalization of on-line learning and an application to boosting. Journal of Computer and System Sciences, 55(1), 119–139.
- Author: Phan Bùi Hữu Ân (huuan26)
- License: MIT License - see the LICENSE file for details.