@Lahiru Fernando A first step I typically use in troubleshooting is to set breakpoints in the IDE. (see the docs https://www.quantopian.com/docs/user-guide/environments/algo-ide#debugger) . Setting a breakpoint at the
order_optimal_portfolio method allows one to inspect variables and, in this case, the inputs to that method.
Inspecting 'context.weights' (which are the target weights) it appears all the weights are positive. There aren't any short weights. This isn't a problem except one of the constraints is to be dollar neutral, or an equal amount of long and short positions.
What's happening? The optimizer will try changing the target weights to satisfy all the constraints including the dollar neutral constraint. It will also try to minimize the 'distance' from the original weights. In effect, the optimizer keeps decreasing the weights until it finds a solution. The first solution it finds is all weights equal to zero. This isn't probably what one wants but it does satisfy all the constraints. This result is dollar neutral ( equal long and short values). The result doesn't go over our max position size. The result doesn't go over our max leverage. And the result doesn't have any exposure to the common risk factors. The optimizer is simply doing what it was asked to do.
So, assuming this isn't the solution one really want's, what are some options? It's best to explicitly get pretty close to a solution and then use the optimizer to simply 'tweak' the results. In this case, ensure the target weights going into the optimizer include both long and short values and are pretty close to being dollar neutral from the beginning.
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 Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian 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.