Say I'm long on some symbol. What's the difference betwen:
MarketOrder(item.Symbol, -Portfolio[item.Symbol].Quantity);
and
SetHoldings(item.Symbol, 0, true);
In my algorithm, on the "sell" or "close" side of things when I receive a trigger to get rid of the investment, I've tried both of the calls above, and they yield signifantly different overall backtesting results over the period and symbols I'm using.
I guess I would have expected SetHoldings to 0 would be the same as a MarketOrder to sell however many shares of the stock I'm holding in my portfolio.
But, that appears to not be the case.
Alexandre Catarino
When you call SetHoldings with `liquidateExistingHoldings` set to true, this method send a market order that will liquidate the existings holding and, after that, send another market order to set the holdings according to the second parameter (percentage).
On the other hand, when percentage is zero, the second market order will be sent with the quantity of shares we still hold. Since there is no time to account the effects of the first order, the algorithm is sending two market orders with the same quantity (and sign).
Please consider using the Liquidate helper:
List<int> Liquidate(Symbol symbolToLiquidate = null);
or, when using SetHolding, do not set `liquidateExistingHoldings` to true. Simply use `SetHoldings(item.Symbol)`.
TedVZ
Ah, OK. I intentionally didn't use Liquidate as I thought that was an EOD operation, and I didn't want to wait for market close to close the position. Thanks for the info.
TedVZ
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!