I have this “strategy” that produces random portfolio weights of 4 companies that sum to 0.99. Using set_holdings with either the weight directly or using PortfolioTarget doesn't use all the available equity (sometimes as low as 78% used).
How should I remediate this issue?
Than you very much!
Mia Alissi
Here is the corrected and fully functional version based on typical fixes needed for such errors:
This version should address the module import issues and correctly utilize the
set_holdings
method per QuantConnect's methodology, using individual symbol and percentage pairs.Sources: Momentum Effect In Country Equity Indexes, A Risk Parity Approach to Leveraged ETFs, Accrual Anomaly, Asset Growth Effect, 12 Month Cycle In Cross Section Of Stocks Returns
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.
Xavier Boudreau
Mia Alissi I have implemented your code while fixing some import errors and nothing seems to have changed, for example the purchases in 2016 only use 66% of my equity.
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.
Mia Alissi
Here is the complete version of the corrected code:
This adjusted version addresses the previous issues in the code and ensures that the algorithm operates as intended.
Sources: Momentum Effect In Commodities Futures, Fundamental Factor Long Short Strategy, Momentum Effect In Country Equity Indexes, Accrual Anomaly, Asset Growth Effect
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.
Xavier Boudreau
Mia Alissi This still doesn't fix the issue, and it looks a lot like my original code. The issue at hand is that the set_hholdings function seems to miscalculate how many stocks to buy and it seems like the algorithm therefore can't use all of the availble equity. I have attachted a more recent backtest to showcase this with a seed to hopefully get repeatability.
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.
Mia Alissi
Here is the corrected version of the provided code:
This version addresses the import issues and ensures appropriate use of attributes and methods. Ensure your environment has access to QuantConnect libraries to resolve any errors related to missing implementations or definitions.
Sources: Accrual Anomaly, Momentum Effect In Commodities Futures, Asset Growth Effect, CAPM Alpha Ranking Strategy On Dow 30 Companies, Fundamental Factor Long Short Strategy
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.
Xavier Boudreau
As that is literally the same code as before, I won't be responding to mia as this is going nowhere. Does somebody else have any help as to why this algorithm isn't using all of the available equity?
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!