Hey everyone, I'm trying to figure out why the "Action(self.rebalance))" buys on market 100% of funds but over two different stocks.
e.g. self.SetCash is (10000)
But then the backtest under orders says:
2010-01-04 09:40:00BAMarket$42.910440804 USD209Buy($8968.28)
2010-01-04 09:40:00PFEMarket$12.83388834 USD699Buy($8968.17)
Total purchase for 2010-01-04 = $17,936.45, but should only be $10,000
I hope that makes sense,
Alethea Lin
Hi Liam,
I added a few logs in the code. As you can see from the log, the securities being traded have default leverage of 2.0. In fact, each asset in QC has its own pre-defined leverage (2 for Equity, 50 for Forex and CFD, etc). In QC, the algorithms are also modeled with margin-modeling by default, but you can change it to cash account type. Check out “Cash and Brokerage Models” for more information.
The SetHoldings helper function sets a fraction of unlevered equity. In the beginning of the backtest period, the unlevered equity is the 10,000 cash. Later, this unlevered equity is the Total Portfolio Value. Therefore, SetHoldings(security, 1.0) would use 100% of the unlevered equity, so you see two orders being placed with total purchase of around 2x original cash since you have a default leverage of 2.0. If you modify the code to SetHoldings(security, 0.5), you will see the total purchase to be close to 10,000, evenly split between two stocks.
In addition, you might find this post useful! Hope this helps!
Liam Maurer
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!