Hi all
I'm trying to use `SetHoldings` to submit a trade on IB paper testing, but the quantity it submits is incorrect. My balance on IB paper testing is 10602.25 USD and the trade I wanted to make is QQQ with weight = 1.0. At the time of submission, QQQ was at $377.73 and I'm using QC's data feed. SetHoldings asked for 27 shares, but IB wasn't happy and gave this error:
New Order Event: Time: 07/25/2023 13:35:02 OrderID: 1 EventID: 2 Symbol: QQQ Status: Invalid Quantity: 27 Message: 201 - Order rejected - reason:Available converted to base: 10602.25 USD Cash needed for this order and other pending orders: 10708.06 USD.
There's no pending order, so I'm not sure how $10708.06 came about.
Any help appreciated.
Mia Alissi
The error message you're seeing is due to insufficient buying power. The
SetHoldings
method uses market order to reach the target portfolio weight you provide. If the portfolio weight you provide translates to an order quantity that exceeds your buying power, you will encounter anInsufficientBuyingPower
error.In your case, you're trying to allocate 100% of your portfolio to QQQ. However, due to price fluctuations and transaction fees, the total cost of the order may exceed your available balance.
To avoid this, you can adjust your buying power buffer or ensure you have enough margin remaining to cover the initial margin requirements of the order before placing it. You can also check if the quantity of the order is non-zero before you place the order.
Here's how you can adjust your buying power buffer in Python:
This sets aside 5% of your portfolio value as a buffer.
For more information, you can refer to the following documentation:
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.
John Munro
But commissions at IB are minimal and QQQ's price fluctuations are small. $10708.06 / 27 = $396. At no point today or in recent days has QQQ reached $390. How does 27 shares of QQQ translate to $10708.06?
Mia Alissi
The calculation you're making seems correct, and it's indeed strange that the total cost of the order is significantly higher than expected. However, the error message you're seeing is from Interactive Brokers, not QuantConnect. It's possible that there might be some additional fees or margin requirements that are not immediately apparent.
One thing to note is that the cost of an order in a live trading environment can be influenced by several factors, including but not limited to:
While the commission for US equities on Interactive Brokers is indeed minimal ($0.005/share with a $1 minimum fee and a 0.5% maximum fee), other factors could potentially increase the cost of the order.
If you're certain that none of these factors account for the discrepancy, I would recommend reaching out to Interactive Brokers' support for clarification on the error message. They should be able to provide a detailed breakdown of the costs associated with the order.
For more information on transaction fees, you can refer to the QuantConnect documentation.
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.
John Munro
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!