Portfolio Optimizer
Find the optimal stock weights given your investment objective and constraints. Powered by CVXPY convex optimization.
Universe Selection
The universe is the set of stocks the optimizer can choose from. Select one of the predefined universes or define your own:
| Universe | Stocks | Description |
|---|---|---|
| NIFTY 50 | 50 | Top 50 Indian companies — blue-chip, highly liquid |
| NIFTY 100 | 100 | Top 100 — includes large and some mid-cap |
| NIFTY NEXT 50 | 50 | Stocks ranked 51-100 — emerging large-caps |
| NIFTY 500 | 500 | Broad market — includes mid and small-cap |
| Custom | Variable | Your own list of stock symbols |
The optimizer uses real historical price data from the database to compute expected returns and the covariance matrix.
Optimization Objectives
Choose what the optimizer should aim for. Each objective finds different optimal weights:
Minimize Risk
Finds the portfolio with the lowest possible volatility(minimum variance). Best for conservative investors who prioritize capital preservation.
Mathematically: minimize w' Σ w (portfolio variance)
Maximize Return
Finds the portfolio with the highest expected return. This tends to concentrate into the highest-returning stocks, so add position size constraints.
Mathematically: maximize w' μ (expected portfolio return)
Maximize Sharpe Ratio
Finds the portfolio with the best risk-adjusted return. Balances return and risk — generally the most practical objective.
Mathematically: maximize (w' μ - r_f) / sqrt(w' Σ w)
Minimize Tracking Error
Finds the portfolio that stays closest to a benchmark (e.g., NIFTY 50). Best for index tracking or enhanced index strategies.
Mathematically: minimize (w - w_bench)' Σ (w - w_bench)
Constraints
Constraints limit what the optimizer can do. Without constraints, the optimizer might put 100% into one stock. Add constraints to make the output realistic and investable.
| Constraint | What It Controls | Example Values | Impact |
|---|---|---|---|
| Position Size | Min/max weight per stock | min: 1%, max: 10% | Prevents over-concentration in any single stock |
| Max Positions | Maximum number of stocks | 20 | Limits portfolio to N stocks — forces selection |
| Beta Exposure | Portfolio beta range | min: 0.8, max: 1.2 | Controls market sensitivity — keeps portfolio near market-neutral if tight |
| Turnover | Max % changed at rebalance | max: 30% | Limits trading costs by restricting how much changes |
| Sector Weight | Min/max per sector | max: 25% | Ensures diversification across sectors |
Tip: Start with Position Size (2-10%) and Max Positions (15-25). Add Beta and Sector constraints if the output is too concentrated. The Sharpe objective + these constraints usually gives the most practical results.
Reading Results
After running the optimizer, you see:
- Expected Return % — annualized return based on historical data
- Expected Risk % — annualized volatility (standard deviation)
- Sharpe Ratio — risk-adjusted return metric
- Positions — number of stocks in the optimal portfolio
- Weight table — each stock with its optimal weight allocation
- Weight bar chart — visual distribution of weights
You can download the weights as CSV or use them directly in the Strategy Builder for backtesting.