Formulating Maximum Sharpe Ratio Portfolio Optimization
Summary
The document frames portfolio construction as choosing weights across return series to maximize the Sharpe ratio, defined in the question as average portfolio return divided by its standard deviation. It provides a small sample return matrix and a CVXPY formulation with long-only weights that sum to one, then reports encountering a disciplined convex programming error.
The author considers replacing the ratio objective with return maximization under a volatility limit, but worries that selecting a limit would be arbitrary. The text is primarily a problem statement: it does not provide a corrected formulation, numerical result, or comparison with CVXOPT. Practical treatment would also need to specify the return and volatility estimates and any further portfolio constraints; those choices are not resolved here.
Key ideas
- The optimization objective is to maximize average portfolio return divided by portfolio return volatility.
- The example constrains portfolio weights to be long-only and fully invested.
- The proposed CVXPY ratio formulation triggers a disciplined convex programming error.
- A return objective with a volatility constraint is considered, but the threshold-selection issue remains unanswered.
Tags
Full text
# Maximizing sharpe ratio using cvxpy or cvxopt
# Maximizing sharpe ratio using cvxpy or cvxopt
I have a dataframe $n$ by $m$ representing $m$ timeseries of returns (each column is a different time series) with total $n$ number of observations, I want to find weight vector of length $m$ such that the sharpe ratio of the resulting time series is maximized (defined as average of column / std of column)
I tried using cvxpy to accomplish this, but I am getting a DCP rules error. Is there a way to do this in cvxpy? If not, what about cvxopt? My suspicion is that I have not formulated it in a convex way. I can change the problem to maximize return subject to the standard deviation be below a certain threshold. But I dont want to set an arbitrary threshold
```
import pandas as pd
import cvxpy as cp
import numpy as np
df = pd.DataFrame([[0.01, -0.005],
[-0.005, -0.005],
[0.02, 0.01],
[0.01, -0.005],
[-0.03, 0.0025],
[0.01, -0.005],
[0.01, 0.001],], columns=["a","b"])
m = len(df.columns)
n = len(df)
A = np.array(df.values)
x = cp.Variable(m)
objective = cp.Maximize(cp.sum(A@x) / cp.sum_squares(A@x - cp.sum(A@x) / n))
constraints = [sum(x)==1, x<=np.array([1]*m), x>=np.array([0]*m)]
prob = cp.Problem(objective, constraints)
prob.solve()
```Shown in full with attribution under the source's licence. Licence: CC BY-SA 4.0 (Stack Exchange)
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.