Hi, I have a question regarding the securities contained within the Manual and Liquid Universes;
Basically, I have 2 universes I want to work with - the Liquid Universe, and the Manual Universe.
In my algorithm, when it sends out orders for the Liquid Universe, I use the following:
for security in self.changes.AddedSecurities:
if not security.Invested:
self.SetHoldings(security.Symbol, .05)
The problem with this, is that the securities within the Manual Universe are also contained within "self.changes.AddedSecurities" which I just realized, so the following code would also allocate 5% to each security in the Manual Universe instead of just the Liquid Universe.
How do I exclude the securities within the Manual Universe from being included when calling "for security in self.changes.AddedSecurities:"? Or is there another way to call a list of the securities within the Liquid Universe that does not contain the securities within the Manual Universe?
Thanks!
Vncne
I tried storing the Manual Universe in Initialize like this:
self.symbols = [Symbol.Create("SPY", SecurityType.Equity, Market.USA), Symbol.Create("QQQ", SecurityType.Equity, Market.USA)]
and changed the initial code from this:
for security in self.changes.AddedSecurities:
if not security.Invested:
self.SetHoldings(security.Symbol, .05)
to this:
for security in self.changes.AddedSecurities:
if not security.Invested and security not in self.symbols:
self.SetHoldings(security.Symbol, .05)
But the latter code still sends orders to symbols that are contained in the Manual Universe
Shile Wen
Hi Vncne,
Please change this line:
if not security.Invested and security not in self.symbols:
to this:
if not security.Invested and security.Symbol not in self.symbols:
so our code can compare Symbol objects with Symbol objects.
Best,
Shile Wen
Vncne
Hi Shile Wen thanks for the reply!
I did what you recommended and indeed that did prevent the algorithm from allocating to what was inside self.symbols, but now the issue I'm facing is with changes.AddedSecurities.
My problem is like this - I want the algorithm to switch between a manually created universe and a liquid universe. When the algorithm switches to the manual universe from the liquid universe, it liquidates all positions with the liquid universe before allocating to the manual universe. This would be okay if I only made use of one universe, the liquid universe, so the code could just be like:
for security in self.changes.RemovedSecurities:
if security.Invested:
self.Liquidate(security.Symbol)
for security in self.changes.AddedSecurities:
if not security.Invested:
self.SetHoldings(security.Symbol, .05)
But in this case, let's say the liquid universe is to contain 5 securities; based on the filters, at first they would be - AAPL, GOOG, SPY, QQQ, and AMD. The algorithm then switches to the manual universe and liquidates all those symbols. Before it switches back to the liquid universe, AMD gets removed from the universe and is replaced with NVDA. What then happens is the only security contained within changes.AddedSecurities is NVDA; so in effect, when the algorithm switches back to the liquid universe, instead of allocating to AAPL, GOOG, SPY, QQQ, and NVDA, it instead only allocates to NVDA because that is the only security that was added.
I guess my question is what can i use in place of changes.AddedSecurities so that I can allocate to all active securities in the liquid universe and not just the most recently added ones?
I tried using self.ActiveSecurities like this but it didn't work out for me:
for security in self.ActiveSecurities:
if security.Symbol not in self.symbols:
self.SetHoldings(security.Symbol, 0.20)
Thank you!
Gahl Goziker
Hi Vncne,
Fixing this incorrect syntax around ActiveSecurities as indicated in this thread might solve the issue.
Best,
Gahl Goziker
Vncne
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!