When trading option spreads, i run into the ‘insufficient buying power’ error, because the default buying power model is being used. I see there is a new model that calculates the right margin for spreads, but I'm not sure how to use it.
Are there any examples of how to use OptionStrategyPositionGroupBuyingPowerModel?
I see it takes an OptionStrategy in the constructor, but I'm not sure if this means i have to create a new one for every strategy i trade, or if it just uses this once, to initialize itself.
.ekz.
When I attempt to use it before each trade, like this:
This is the error i am currently seeing:
Derek Melchin
Hi .ekz.,
Please attach a backtest that throws the insufficient buying power error so we can assist further. The margin for spreads should be correct.
Best,
Derek Melchin
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.
.ekz.
Thanks for the response, but this algo isnt one i can share publicly,
That said, this is a known issue. See this post that describes the issue accurately, with a backtest that reproduces the issue:
Are you suggesting that I do not need to use the custom buying power model : OptionStrategyPositionGroupBuyingPowerModel, and that it should ‘just work’ ?
.ekz.
Also sharing this, as I believe it is related.
Derek Melchin
Hi .ekz.,
We calculated the changes in margin and cash using this page as a guide and got
The logs of the attached backtest show
that the margin used matches the calculation and the total portfolio value is
TPV = Cash + Credit - Value - Fee:
and the margin remaining is TPV - margin used:
The insufficient buying power error in this thread is likely caused by how the quantity is calculated.
Best,
Derek Melchin
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.
.ekz.
Aha. Got it. I appreciate the thorough investigation and detailed response.
I'll go take a look at my code again, and revisit how i calculate the # of spreads I can afford.
Thanks a lot.
.ekz.
Trying this out, with a bull put spread on SPY.
I'm calculating the affordable quantity, based on buying power effect. The math looks right, but apparently I'm trying to buy too much because i am still getting the error. Any thoughts?
Here's my debug log below, and the backtest attached
See attached backtest.
Derek Melchin
Hi .ekz.,
The option margin model is not currently equipped to determine the maximum position size for orders with OptionStrategies, but we have an open GitHub Issue to have the problem resolved. Subscribe to our progress here:Combo buying power model #2709
For the time being, we can use the following snippet to determine the quantity of each contract we can afford without receiving the margin error:
See the attached backtest for reference.
Best,Derek Melchin
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.
.ekz.
Thanks Derek Melchin . I admit it's good to know that I was not mistaken and my concerns are valid.
With that said, I have two important questions.
Derek Melchin
Hi .ekz.,
Best,
Derek Melchin
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.
.ekz.
Ah, thats what I thought, thanks for confirmation Derek Melchin.
Follow up qq: if i were to live trade, would the engine use the broker's margin model / calculation?
Varad Kabade
Hi .ekz.,
QuantConnect's margin model is applied in live mode to avoid placing bad orders. To use the brokerage margin model, we have to "disable" the margin model.
In this algorithm just this part to turn off the HasSufficientBuyingPowerForOrder check:
Best,
Varad Kabade
.ekz.
Got it. Thanks Varad kabade
.ekz.
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!