Back

RemoveSecurity does not work intra-day

Hello there,

I am trying to develop a custom Risk Management decision tree so that when a condition is met, I close the position and remove the underlying from the portfolio (otherwise, OnData Loops back on it and I want to avoid this).

However as you can see in the attached backtesting, the securities are not removed, even when I loop through each component of the portfolio to force removing everything - underlying equities remain there in the portfolio... Have you guys ever witnessed this behavior? Is there another way to do this ? It seems to be working when I'm resetting the portfolio every night so I tend to think that there is a problem with intra-day behavior...

Thanks in advance for your help,

Terence.

 

 

Update Backtest








0

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.


Hi Terence,

The RemoveSecurities() command will not take a security out of the Portfolio, and that’s why you will still see the security in your Debug message. However, it will liquidate the positions and cancel any open order, and the security will be removed from the data feed and marked as nontradable until the next Universe Selection.

In addition, if the universe is not too big, we recommend using OnSecuritiesChanged() to keep track of a list of symbols and look through those symbols instead of removing securities. If the universe is too big, you might run into issues regarding subscription limits with the brokerage, in which case you would need to remove securities from the data feed. Check out this documentation to learn more!

Hope this addresses your question. Thanks for your support!

0

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.


Hello Alethea,

Thank you very much for your answer but my issue is that RemoveSecurities() does not seem to remove the ticker from the data feed since the algorithm is reinvesting right away after the position was closed by risk management.

Is it possible that the function stockDataSource() is only sensitive to the date and not the time, therefore adding the stock back into the data feed ? 

On the other hand, I cannot use OnSecuritiesChanged() for the reasons explained in the post below. 

https://www.quantconnect.com/forum/discussion/6015/option-trading-on-custom-data-onsecuritieschanged-behaviour-problems/p1

 

0

Hi Terence,

I don't want to run away from the issue because adding and removing securities manually in a universe selection algorithm is fine, but it breaks the universe selection pattern. If the algorithm is not adding hundreds of securities, using RemoveSecurity is not the best alternative, especially combined with AddEquity.

I would suggest a different approach: create a list with the underlying symbols which options the algorithm is allowed to trade. Instead of removing the security with RemoveSecurity, remove the symbol from the list and, consequently, the algorithm will not loop through data.Keys but the created list.

After these changes, we may take a look into the issue of not being able to use OnSecuritiesChanged, This method is part of the universe selection pattern and I think this algorithm would profit from its addition.

 

 

0

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.


Update Backtest





0

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.


Loading...

This discussion is closed