Gurobi / gurobi-optimods

Data-driven APIs for common optimization tasks
https://gurobi-optimods.readthedocs.io
Apache License 2.0
147 stars 31 forks source link

Maximize Sharpe ratio #15

Open etowle opened 2 years ago

etowle commented 2 years ago

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 Gurobi/gurobi-optimods#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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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 Gurobi/gurobi-optimods#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.

ChinSquared commented 1 year ago

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 commented 11 months ago

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 commented 11 months ago

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 commented 11 months ago

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:

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:

https://github.com/Gurobi/gurobi-optimods/blob/d1723e8f5dec79f2926eb8d7a46be62e882e5bb3/src/gurobi_optimods/sharpe_ratio.py#L87-L100