Hi, I've just started using the QuantConnect platform and am impressed with the functionality. I am having some difficulty allowing leverage in my backtests, basically I am trying to increase day trading buying power by 4x the amount of cash, as most brokers allow. From the docs and this post:
https://www.quantconnect.com/forum/discussion/500/update-margin-calls-and-portfolio-modelingthe typical way to do this is something like:
self.Securities["AAPL"].MarginModel = PatternDayTradingMarginModel()
within the Initialize() function. However, I am using a CoarseSelectionFunction to get a new list of stocks every day, and as far as I can tell self.Securities is not populated in Initialize() or onData(). I'm wondering if I am still able increase leverage/buying power while still using CoarseSelectionFunction? I also tried setting:
self.UniverseSettings.Leverage = 4
within Initialize(), but it did not seem to do anything when looking at the difference between self.Portfolio.MarginRemaining and the cost of of a new position within onData(). Thanks.
Shile Wen
Hi Dahui,
I suggest using a custom Security Initializer and have the function set the leverage of the security to 4.Furthermore, I STRONGLY suggest that you do not call AddEquity insides the Coarse filter, and also use the dict[Symbol, SymbolData/SelectionData] pattern to store the indicator information, which can be seen in this BootCamp.I've shown this change in the attached backtest.
Best,
Shile Wen
Dahui
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!