Hi - I am new to the platform, and certainly able to do more than i understand so far.
I have an algorithm running live, that works well when it works, but often fails due to the number of shares and the total funds in my account. I receive the error message back from IB stating that:
Order rejected - reason:YOUR ORDER IS NOT ACCEPTED. IN ORDER TO OBTAIN THE DESIRED POSITION YOUR EQUITY WITH LOAN VALUE [$$$$ USD] MUST EXCEED THE INITIAL MARGIN [$$$$ USD]
My logic for choosing how many shares to purchase is pretty basic and is:
(Portfolio.Cash * AllocationPercent) / SharePrice
This essentially takes a fraction of my available cash (75%) and uses that for the limit order, which is a Short position at the current price. of the stock
Sometimes it works, sometimes it doesn't, it appears that certain stocks may require more available funds, but I am unable to understand how to better calculate how many shares to purchase.
Help would be very appreciated. i believe IB gives me 4X leverage, so i would expect to be able to enter these types of orders without problem.
Derek Melchin
Hi Dan,
If IB is rejecting the orders, too many shares are probably be requested. We recommend reviewing this logic
(Portfolio.Cash * AllocationPercent) / SharePrice
If there are open positions when submitting the order, use `Portfolio.MarginRemaining`.
For further assistance with live trading, please contact support@quantconnect.com with the algorithm attached.
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.
BedaTrades
Is there anyway to determine the Margin Requirements in QuantConnect before submitting the order to IB? I am running into this issue when trying to short stocks as well - and its becuase some of the stocks I am trying to short have a "higer than normal" margin requirement to short them. If i could pre-determine the Margin Requirement, then I would be able to calculate the proper number of shares to use.
The other issue I run into is sometime IB does not have the shares available to borrow. Is there a "Is Shortable" flag or anything in QuantConnect that I can use to determine if a stock is Easy to Borrow or Hard to Borrow?
Jared Broad
Sorry, it is not possible. You may be able to find a third-party site with these higher-margin stocks and adjust accordingly.
In the meantime, you can use this as a general rule to scale down the meaning of "100%" to give yourself more of a buffer while IB is messing with the margin requirements.
self.Settings.FreePortfolioValuePercentage = 0.10
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.
Dan Iorg
Thanks Jared.
I am only making 1 trade, so there won't be any other open orders or reduced availability of cash. It is simply an IB Margin requirement that appears to be "magical" in nature. I wasn't sure if there was a way or a recommendation on how to circumvent this.
One solution I am thinking of is simply submitting multiple smaller orders, and expecting failure towards the end. With this, I am hopeful that some orders are filled rather than none. I would expect IB to do a partial fill when this situation occurs, rather than all-or-none and rejecting the request outright. Id like to use as much as my free cash that I can to work towards the trade.
Any thoughts on that?
Derek Melchin
Hi Dan,
Without any knowledge on the margin required, the process outlined above may be the best option to entering the position. Although, submitting many small orders may lead to higher trading fees.
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.
Dan Iorg
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!