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:

UniverseStocksDescription
NIFTY 5050Top 50 Indian companies — blue-chip, highly liquid
NIFTY 100100Top 100 — includes large and some mid-cap
NIFTY NEXT 5050Stocks ranked 51-100 — emerging large-caps
NIFTY 500500Broad market — includes mid and small-cap
CustomVariableYour 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.

ConstraintWhat It ControlsExample ValuesImpact
Position SizeMin/max weight per stockmin: 1%, max: 10%Prevents over-concentration in any single stock
Max PositionsMaximum number of stocks20Limits portfolio to N stocks — forces selection
Beta ExposurePortfolio beta rangemin: 0.8, max: 1.2Controls market sensitivity — keeps portfolio near market-neutral if tight
TurnoverMax % changed at rebalancemax: 30%Limits trading costs by restricting how much changes
Sector WeightMin/max per sectormax: 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.