Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maximize Sharpe ratio #15

Open
etowle opened this issue Aug 31, 2022 · 7 comments
Open

Maximize Sharpe ratio #15

etowle opened this issue Aug 31, 2022 · 7 comments
Assignees

Comments

@etowle
Copy link
Member

etowle commented Aug 31, 2022

Why this Nup?

Finance applications are probably plentiful enough to warrant their own nup category. If there is a dedicated Finance category, the maximal Sharpe ratio problem is popular and focused enough to be included.

Note that this is closely related to #9.

Does it fall under an existing category?

Other (Finance)

What will the API be?

asset_allocs = nupstup.max_sharpe_ratio(
    cov_matrix=Q  # variance-covariance matrix
    mu=mu  # estimated first moments of return function
    rf_rate=rf  # risk-free rate
)

where Q and mu are scipy/numpy data structures. We could alternatively require the factor matrix H as an argument instead of the covariance matrix Q (where Q = H.T @ H), though I think Q is more natural considering how the problem statement and model are written.

Additional context

One complication: to be solved as a QP, the model needs to be reformulated in a different variable space. Additional constraints must be added in the variable space of the reformulated model. The mapping between the two models is straightforward, but this does create a barrier for people interested in modifying the underlying model.

@rluce
Copy link
Member

rluce commented Sep 3, 2022

I like it. I think it won't harm much if the nup function allows for either the variance-covariance matrix, or its factor.

@rluce
Copy link
Member

rluce commented Oct 13, 2022

Maybe we should complement this Nup with a minimum variance portfolio selection (you'd minimize "just" x @ Q @ X), or can this be covered by some paramters in this Nup already?

@rluce
Copy link
Member

rluce commented Oct 15, 2022

I think we (@etowle, @silkehorn, and myself) should team up and create a small variety of base models in the financial space. This one and #9 are the first two on the list, but they would share the interface (and implementation) of the extra gadgets (min. buy-in, max. allocations, etc.). We may be even able to integrate the online-problem (you start with an existing allocation) into each formulation. A third variation may be needed for minimizing a tracking error.

@rluce rluce transferred this issue from another repository Nov 22, 2022
@etowle etowle mentioned this issue Mar 10, 2023
7 tasks
@etowle etowle mentioned this issue Jun 14, 2023
8 tasks
@ChinSquared
Copy link

I would love to see the best way to include these in a multi-objective problem. Sharpe, TE, MV, etc...How would you link the y world and x in an efficient and convex way using the built in multi-objective method?

@simonbowly
Copy link
Member

Hi @ChinSquared, could you please elaborate on what you mean here? Gurobi allows you to combine objectives either as a weighted sum, or in a hierarchical manner using priorities. Which are you looking for, and for which metrics?

@ChinSquared
Copy link

Sure, for example, if you specify a hierarchical objective, first is to max Sharpe with a budget of 20 bps. Then minimize tracking error as the second objective. Other constraints in the portfolio are active like max trade, step size, max positions. Thanks!

@etowle
Copy link
Member Author

etowle commented Nov 13, 2023

To incorporate other performance metrics into the Sharpe ratio model and retain convexity, these other metrics would have to be modeled in the space of the y variables (the reformulated variable space used in the Sharpe ratio model). This is because:

  • The Sharpe ratio model is only convex in the space of the y variables
  • We can't simultaneously model some metrics in the x-variable space and others in the y- variable space, unless we link together the x and y variables with the non-convex constraints x = y / (e^T y)

At any rate, I fear a multi-objective, multiple-metric model with side constraints is outside the scope of what this Mod is trying to accomplish. That said, you could always use the Sharpe ratio model-building code as a starting point for building a more complex model:

def _max_sharpe_ratio_numpy(cov_matrix, mu, rf_rate, create_env):
with create_env() as env, gp.Model("sharpe_ratio", env=env) as model:
y = model.addMVar(mu.size, name="y")
model.addConstr((mu - rf_rate) @ y == 1)
model.setObjective(y @ cov_matrix @ y, sense=GRB.MINIMIZE)
model.optimize()
# Translate solution to original variable space
x = y.X / y.X.sum()
ret = mu @ x
risk = x @ cov_matrix @ x
sharpe_ratio = (ret - rf_rate) / math.sqrt(risk)
return SharpeRatioResult(x, sharpe_ratio, ret, risk)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants