i sell QQQ 201204C00303000 ( Sell call of 4th December 2020 expiry ) at 2020-11-23 for 100 quantity but it will close QQQ 201204C00303000 position at 2020-12-04 ( At the end of expiry day ) with 10000 quantity. If 100 quantity sell then it need to buy 100 quantity to close the trade, Why this type of difficulty comes during backtesting
Mia Alissi
Based on the information provided in the extracts, it seems like you're experiencing an issue with closing a position in your backtest. In QuantConnect, you can close a position by using either the
MarketOrderorLiquidatemethods.If you want to close a specific position, you can use the
Liquidatemethod with the symbol of the asset as an argument. For example, if you want to close a position in QQQ, you can useself.Liquidate("QQQ"). This will close all positions in QQQ.If you want to close a position with a specific quantity, you can use the
MarketOrdermethod with the symbol of the asset and the quantity as arguments. The quantity should be negative if you want to close a long position. For example, if you want to close a long position in QQQ with a quantity of 100, you can useself.MarketOrder("QQQ", -100).If you're seeing a different quantity in your backtest results, it might be due to the fact that the
MarketOrdermethod sends a market order to the exchange, and the actual filled quantity might be different from the requested quantity, depending on the market conditions.If these solutions don't solve your issue, it would be helpful if you could provide more details or share a backtest so we can further assist.
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.
Hit Panara
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!