My first post here so I hope this isn't a redundant question.
I have been experimenting with pairs trading and noticed that self.SetHoldings is used when there is a trigger to enter a long and short position. However, some of the stocks I am exploring are quite small and potentially illiquid. Is there a way to check whether the stock is available for shorting before executing the commend? Alternatively, is there a way to ensure long position is only entered once short is filled, otherwise it ignores the request?
elif i.touch == -1:
if i.error > i.mean_error - self.open_size*i.sd and i.last_error < i.mean_error - self.open_size*i.sd:
self.Log('long %s and short %s'%(str(i.a),str(i.b)))
self.Log('Margin remaining: '+str(self.Portfolio.MarginRemaining))
i.record_model = i.model
i.record_mean_error = i.mean_error
i.record_sd = i.sd
self.trading_pairs.append(i)
self.SetHoldings(i.a, 1.0/(len(self.selected_pair)))
self.SetHoldings(i.b, -1.0/(len(self.selected_pair)))
Dirk bothof
I don't believe quantconnect supports that currently, you could check here
https://www.quantconnect.com/tutorials/api-tutorials/tracking-and-managing-ordersWhat you need to model this yourself is order book data.
https://www.thebalance.com/order-book-level-2-market-data-and-depth-of-market-1031118As a more general word of advice I would not recommend pair trading illiquate anything. With pair trading you want to be able to open and close both positions easily. If that is not possible it is not possible to pair trade successfully since you don't know when you can open or close a position or for how much
Rahul Chowdhury
Hi Ahmed,
Unfortunately, Lean does not currently model availability of shares for shorting before filling a short order. When a short order is placed on Lean, the shares are assumed to be available for shorting. Lean's default fill model is the Immediate Fill Model, which assumes orders are immediately and completely filled. You can learn more about fill models in the documentation.
It is important to test algorithms using a brokerage paper trading account, like IB's paper trading, to understand the impact of liquidity on trading.
Best
Rahul
Ahmed Alahmadi
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!