Hi QC,
Can you please confirm if "Liquidate()" neutralizes portfolio or creates a short position? The trades tab attached makes it look like its a alternate Long/Short strategy?
QUANTCONNECT COMMUNITY
Hi QC,
Can you please confirm if "Liquidate()" neutralizes portfolio or creates a short position? The trades tab attached makes it look like its a alternate Long/Short strategy?
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.
Michael Handschuh
Sri Vanama
Miki Amit
Michael Handschuh
Fang Zhou
Hi Michael,
Sort of reviving an old thread, but I wanted to ask if the liquidate() function also closes positions that are not native to QC. For example, suppose my QC algorithm was strictly trading SPY (e.g., self.AddEquity("SPY")), but I also manually have short SPX puts in my account. Would the liquidate function also open market orders for my SPX puts as well?
Thanks!
Fang
Jared Broad
Correct; further if you place any trades outside of QC it will terminate the algorithm
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.
Fang Zhou
Great! Thank you!
C C
Just a quick follow up. Â Am I correct, that upon liquidate, in this case, given that resolution is set to daily, the market order will be executed upon open on the following day? Â Just wasn't clear when exactly such market order are executed. For example, if it was minute resolution.
Â
class LiquidUniverseSelection(QCAlgorithm):
 Â
  filteredByPrice = None
 Â
  def Initialize(self):
    self.SetStartDate(2019, 1, 11) Â
    self.SetEndDate(2019, 7, 1)Â
    self.SetCash(100000) Â
    self.AddUniverse(self.CoarseSelectionFilter)
    # Ignore this for now, we'll cover it in the next task.
    self.UniverseSettings.Resolution = Resolution.Daily
  def CoarseSelectionFilter(self, coarse):
    sortedByDollarVolume = sorted(coarse, key=lambda x: x.DollarVolume, reverse=True)Â
    filteredByPrice = [x.Symbol for x in sortedByDollarVolume if x.Price > 10]
    return filteredByPrice[:8]
 Â
  def OnSecuritiesChanged(self, changes):
    self.changes = changes
    self.Log(f"OnSecuritiesChanged({self.UtcTime}):: {changes}")
   Â
    #1. Liquidate removed securities
    for security in changes.RemovedSecurities:
      if security.Invested:
        self.Liquidate(security.Symbol)
   Â
    #2. We want 10% allocation in each security in our universe
    for security in changes.AddedSecurities:
      self.SetHoldings(security.Symbol, 0.1)
   Â
Â
Louis Szeto
Dear C C
Sorry for the delay. Yes, you're correct! It will elicit market orders to liquidate and filled upon the next bar's opening.
Best
Louis
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.
Matthew Martin
The docs say that if you liquidate when the market closes it converts to an on-open order. In paper trading, this does appear to be the case. When liquidating on 11 / 25 / 2021, the position is never liquidated.
Matthew Martin
The docs say that if you liquidate when the market closes it converts to an on-open order. In paper trading, this does appear to be the case. When liquidating on 11 / 25, the position is never liquidated.
Â
Â
Sri Vanama
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!