Skip to content

Algorithm.Framework/Portfolio/MaximumSharpeRatioPortfolioOptimizer.py/.cs is incorrect #9322

@Ruuudy1

Description

@Ruuudy1

Expected Behavior

the implementation references/tries to implement:
quant.stackexchange.com/.../18521/...
The StackExchange answer describes the Charnes-Cooper substitution which only works when no inequality bounds on individual weights are present. Charnes-Cooper substitution requires: substitute y = w/κ, constrain mu'y = 1 (not mu'w = k), then minimize y'sum(y). The budget constraint becomes 1'y = κ and the bounds become 0 ≤ y_i ≤ κ appears in the bounds. our python optimizer ignores this.
image.png

as a result the optimizer will always default to min variance optimizer based on the equal weight expected return (it's forcing the portfolio return to match k), which is exactly what ends up happening if we run it

Actual Behavior

The portfolio should not be forced to match K, it should return the highest risk adjusted return correctly maximizing sharpe ratio.

Potential Solution

I provided the fixed sharpe ratio optimizer for both languages:
Python: Sharpe maximization via SLSQP

  • Objective: -μ'w / √(w'Σw)
  • Constraints: Σw = 1
  • Bounds: (lower, upper) per weight

C#: Charnes-Cooper QP

  • Objective: min y'Σy
  • Constraints: μ'y = 1, y_i ≥ 0
  • Recovery: w = y / Σy

Reproducing the Problem

If we plot the weights for us to vizualize. Left plot is our built is the built in one (sharpe ratio 0.133) vs right is the fixed version provided (0.164 sharpe ratio).
Python version (flat weights on built in optimzer):
Image
Image

C# Version
Left is the built in MaximumSharpeRatioPortfolioOptimizer.cs optimzer (0.038 sharpe ratio), right is the fixed implementation version (0.154 sharpe ratio).
Image

Note: the slight difference in backtest performance is due the different optimizers used matching the original implementation (since SLSQP is not built into C#.)

System Information

Cloud Master Branch

Checklist

  • [ X ] I have completely filled out this template
  • [ X ] I have confirmed that this issue exists on the current master branch
  • [ X ] I have confirmed that this is not a duplicate issue by searching issues
  • [ X ] I have provided detailed steps to reproduce the issue

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions