Maximum Sharpe ratio portfolio: a fractional programming example, solved and checked
The maximum Sharpe ratio portfolio is a classic fractional programming problem. Here it is solved by a real solver (CLARABEL (Charnes-Cooper SOCP)) and checked: every constraint, and the optimality certificate. Change the numbers below and solve your own.
Solve your own version free, no account needed
The problem
Three assets have excess returns 8%, 12% and 6%, volatilities 15%, 25% and 10%, and correlations 0.3 (1-2), 0.1 (1-3), 0.2 (2-3). With no short sales, which portfolio has the highest Sharpe ratio?
How the model was built
The objective as written from the problem, before the numbers are multiplied out:
- Top of the ratio: the portfolio's excess return. Bottom: its volatility, the square root of the variance.
- Covariance = correlation × volatility × volatility: for assets 1 and 2, 0.3 × 0.15 × 0.25 = 0.01125. It appears twice in the variance, hence 0.0225 w1 w2.
- A ratio is not convex, so the solver uses the change of variables y = t w (Charnes-Cooper), which gives a convex problem with the same best portfolio.
The model
Each line has a plain-language note on the right.
| make this as large as possible | |
| limit 1: left side must equal 1 | |
| fraction of portfolio in asset 1 (excess return 8%, volatility 15%) cannot be negative | |
| fraction of portfolio in asset 2 (excess return 12%, volatility 25%) cannot be negative | |
| fraction of portfolio in asset 3 (excess return 6%, volatility 10%) cannot be negative |
What is being decided
There are 3 decision variables.
| Variable | Type | Meaning |
|---|---|---|
| w1 | real number | fraction of portfolio in asset 1 (excess return 8%, volatility 15%) |
| w2 | real number | fraction of portfolio in asset 2 (excess return 12%, volatility 25%) |
| w3 | real number | fraction of portfolio in asset 3 (excess return 6%, volatility 10%) |
Goal and limits
Maximize the objective subject to 4 constraints, of which 3 are simple bounds on a single variable.
Problem type
Ratio of linear to norm, complexity level 4: a ratio objective: the Charnes-Cooper change of variables (y = x t) makes it convex. Solved with CLARABEL (Charnes-Cooper SOCP) at the Medium solver tier.
The answer at a glance
The optimal value of each decision, as the solver returned it.
Which constraints hold the answer in place
Binding (no slack left): (1) w1 + w2 + w3 = 1. Changing a binding constraint changes the answer; a slack one can move a little without effect.
| # | Constraint | Value | Limit | Slack | Binding |
|---|---|---|---|---|---|
| 1 | w1 + w2 + w3 = 1 | 1 | 1 | 0 | yes |
| 2 | w1 >= 0 | 0.306812 | 0 | 0.306812 | |
| 3 | w2 >= 0 | 0.116549 | 0 | 0.116549 | |
| 4 | w3 >= 0 | 0.576639 | 0 | 0.576639 |
Algebraic model (low level)
Decision variables, objective and every constraint written out; this is exactly what the solver receives.
Model code (cvxpy)
The same model in cvxpy, ready to run.
import cvxpy as cp
w1 = cp.Variable(name='w1') # fraction of portfolio in asset 1 (excess return 8%, volatility 15%)
w2 = cp.Variable(name='w2') # fraction of portfolio in asset 2 (excess return 12%, volatility 25%)
w3 = cp.Variable(name='w3') # fraction of portfolio in asset 3 (excess return 6%, volatility 10%)
objective = cp.Maximize((0.08*w1 + 0.12*w2 + 0.06*w3)/cp.sqrt(0.0225*w1**2 + 0.0225*w1*w2 + 0.003*w1*w3 + 0.0625*w2**2 + 0.01*w2*w3 + 0.01*w3**2))
constraints = [
w1 + w2 + w3 == 1,
w1 >= 0,
w2 >= 0,
w3 >= 0,
]
problem = cp.Problem(objective, constraints)
problem.solve(solver='CLARABEL')
print(problem.status, problem.value)
print('w1 =', w1.value)
print('w2 =', w2.value)
print('w3 =', w3.value)Solve your own
This is the model as the app reads it. Change any number and solve it in the free box on the front page (no account needed).
maximize (0.08*w1 + 0.12*w2 + 0.06*w3) / sqrt(0.0225*w1^2 + 0.0625*w2^2 + 0.01*w3^2 + 0.0225*w1*w2 + 0.003*w1*w3 + 0.01*w2*w3)
subject to
w1 + w2 + w3 = 1
w1, w2, w3 >= 0
# w1 = fraction of portfolio in asset 1 (excess return 8%, volatility 15%)
# w2 = fraction of portfolio in asset 2 (excess return 12%, volatility 25%)
# w3 = fraction of portfolio in asset 3 (excess return 6%, volatility 10%)
# asked: the optimal portfolio weights w1, w2, w3 (the portfolio with the highest Sharpe ratio)Checked: the app's answer matches the reference answer in our test set, which two solvers (CLARABEL, OSQP) agree on. Built 2026-11-10.
Related examples
Try ProvenDecisions free: type, photograph or say an optimization problem; every answer is checked by a solver.