I am trying to trade fractional shares with alpaca as my broker. I use the self.SetHolding() command. When trading in the paper environment. It failed to execute a fractional order. Is that because I used self.SetHoldings() rather than self.buy(), or is it because I used the paper environment?
Mia Alissi
Here's a direct answer to Zachary's question based on QuantConnect and Alpaca behavior:
1. Paper Environment Restriction:
The failure to trade fractional shares with Alpaca in QuantConnect's paper environment is due to a limitation of the PaperBrokerage. QuantConnect's native paper brokerage does not support fractional share trading for equities—even if Alpaca (in live mode) does. This is a well-known limitation with the QuantConnect paper trading environment for most equity brokers.
2. Method Choice –
SetHoldings
vs.Buy
:Both
self.SetHoldings()
and direct share order methods likeself.Buy()
ultimately submit orders for a number of shares. The method does not affect fractional support:SetHoldings()
, QuantConnect calculates the corresponding number of shares. If that number is a fraction, but the brokerage integration does not support it (as with PaperBrokerage), the order fails or gets rounded.self.Buy(symbol, quantity)
with a fractional value for quantity, the same brokerage limitation applies.3. Solution:
Summary:
It's not the method (
SetHoldings
vsBuy
)—the restriction is from using the paper environment, which does not support fractional shares for equities in QuantConnect, regardless of which order method you use.If you'd like, I can write a code sample that asserts this behavior or demonstrates a workaround—just let me know your preference!
Sources: QuantConnect Paper Trading - QuantConnect.com, Opening Range Breakout for Stocks in Play, Alpaca - QuantConnect.com, QuantConnect Paper Trading - QuantConnect.com, Reimagining the 60-40 Portfolio in an Era of AI and Falling Rates
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.
Zachary Allgood
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!