Can someone provide guidance on how to implement the MaximumSharpeRatioPortfolioOptimizer?
Example 1: Mean-Variance Portfolio at the link below does not work when tested.
https://www.quantconnect.com/docs/v2/writing-algorithms/historical-data/history-requests
Running a backtest uing the example code results in an error:
Argument 1 to "optimize" of "MaximumSharpeRatioPortfolioOptimizer" has incompatible type "DataFrame"; expected "list[float]"here is the relevant section of code:
symbols = self._universe.selected
history = self.history(symbols, 253, Resolution.DAILY).close.unstack(0).dropna()
# Daily return on the universe members to calculate the optimized weights.
returns = history.pct_change().dropna()
# Calculate the optimized weights.
weights = self._optimizer.optimize(returns)here is the funciton definition:
def optimize(historical_returns: typing.List[float], expected_returns: typing.List[float]=None, covariance: typing.List[float]=None) -> typing.List[float]I tried this revision, but it does not work..
returns = history.pct_change().dropna().stack().to_numpy().tolist()How is the optimizer intented to be used?
Christopher Roberts
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!