Hello,
I have a model that shorts an ETF using an MOO order, and buys is back at close using and MOC order.
It returns about 45% over the life of the test, when leverage is set to 1. When I change the following two lines of code from a 1 to 2, to represent an increase to 2x leverage, the total return is 61.25%. I am confused on what is causing a leveraged overall winning strategy to return less than double the unleveraged version. I feel I may be missing something. The trade sizes seem to double as I change from 1x to 2x so yea. anything helps!
These two lines are the ONLY ones I edit between the backtests. I simply toggle replace the 2 with a 1 and vice versa.
self.UniverseSettings.Leverage = 2
self.SetHoldings(tradeBar.Symbol, -2)
Xin Wei
Hi Ryland,
It will not be exactly twice the return as the unleveraged version. If we take a look at the trading order sizes, indeed, the first trade session (both sell and buy) will be twice the size. But, as the profits/losses accumulate differently for the two versions, leveraged trading sizes won't be precisely the twice size as the unleveraged version anymore.
I hope this helps!
Ryland Mathews
Thank you for the reponse. I understand you will end up buying a different number of shares but % moves are obviously the same for each trade and should keep it very close. I am saying the strategy unlevered returns 49%, but when levered 2x returns 61%. Same account size, double the shares = +12% a 25% increase? or a Does that seem possible to you ? or am i possibly missing something in the code. I will go trade by trade if I need to. The fees for the backtest also more than double when levered 2x, so maybe that is part of it. any further explanation would be great if you can think of anything else
Thanks!
Ryland Mathews
Also, if it helps after toggling back and forth between 1 and 0 in the below lines of code :
self.UniverseSettings.Leverage = 2
self.SetHoldings(tradeBar.Symbol, -2)
the trades change. I exported the orders for comparison, and changing the 2 to a 1 results in different trades. There are more on the leveraged version. There must be a bug or problem with my code?
Jared Broad
Hey Ryland, its highly unlikely there is a bug in the margin modeling. If you truly want to understand how this is working please go trade by trade, perform the margin calculations yourself to confirm they are working as expected. I suggest you do this as it'll be very informative about how the brokerages perform margin calculations. If you find a bug please report back the specific trade with a question about the trade-size vs margin available. If the assets traded change you should review the dropbox format and make sure all the rows are being processed.
You may want to substitute the SetHoldings() call with CalculateOrderQuantity() and then MarketOrder(). The majority of the margin calculation is done in CalculateOrderQuantity buts not simple and cannot be understood from a birds-eye view.
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.
Ryland Mathews
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!