I'm pretty new to this so probably doing something silly. But I'm running a backtest, and some of the first orders placed are to sell stocks that I haven't yet placed buy orders for? Any ideas?
Don't have an account? Join QuantConnect Today
QuantConnect Community Discussions
QUANTCONNECT COMMUNITY
LEAN is the open-source algorithmic trading engine powering QuantConnect. Founded in 2012 LEAN has been built by a global community of 180+ engineers and powers more than 300+ hedge funds today.
Join QuantConnect's Discord server for real-time support, where a vibrant community of traders and developers awaits to help you with any of your QuantConnect needs.
The Open-Quant League is a quarterly competition between universities and investment clubs for the best-performing strategy. The previous quarter's code is open-sourced, and competitors must adapt to survive.
Backtest error: selling stocks that haven't been bought yet. Seeking help.
Continue ReadingRefer to our Research Guidelines for high quality research posts.
Create an account on QuantConnect for the latest community delivered to your inbox.
Sign Up Today
|
|
|||||||
|
|
||||||||
|
Backtest selling stocks I don't have
JumboFlan | Brian McVeigh | March 2021
I'm pretty new to this so probably doing something silly. But I'm running a backtest, and some of the first orders placed are to sell stocks that I haven't yet placed buy orders for? Any ideas?
QuantConnectâ„¢ 2025. All Rights Reserved
JumboFlan
Attached image of orders:
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.
JumboFlan
OK, now I'm even more confused. The Sell Order is for a stock that shouldn't even be in my universe as it over my price limit. Would love any advice here!
(And trying and failing to attach an image of the orders...it just won't show)
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.
JumboFlan
Hmm - is the sell order for stocks not yet in my portfolio, me unintentionally shorting?
Still no idea how the stock is included in my universe at $45 when my selection limits up to $15
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.
JumboFlan
Apologies for spamming comments - I am just very confused. So the stock should be in the universe, as its price was within my limits, but for some reason my order is getting filled at $45/share instead of $5.
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.
Jovad Uribe
Hi JumboFlan,
I took a brief look over your code and the logic error seems like it may be coming from your OnSecuritiesChanged method. You need to also loop through changes.RemovedSecurities and remove the corresponding security from any variables and containers you created. Let me know if this helps.
Cheers
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.
Derek Melchin
Hi JumboFlan,
To resolve the issue of fill prices being above the $15 threshold, we need to replace
universe = [c for c in coarse if 1 < c.Price < 15 and c.Volume > 1000000]
with
universe = [c for c in coarse if 1 < c.AdjustedPrice < 15 and c.Volume > 1000000]
See the attached backtest for reference.
> is the sell order for stocks not yet in my portfolio, me unintentionally shorting?
Correct. The backtest view page shows that insights with a down direction are emitted.
Continuing the development of this algorithm, consider the following:
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.
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!