Back

Question Regarding Universe Functionality

Hi Guys,

I just migrated from quantopian to QC. During the process trying to migrate my algo from there to here, I find it difficult to realize the pipeline functionality. However, I might not be getting this correctlly and would like to ask if anybody cast some light on the below situation.

My strategy relies a lot on stock selection based on a pre-defined set of rules, these rules are set up based on measures like returns, volumes, highs/lows of stocks, price, etc. Everything is developed from the open, high, low, close, and volume. I know that  Coarse Universe allows us to use a few pre-defined measures to filter down stocks, but I am wondering if we can self-define some measures as well. If so, can somebody gives me an example? 

Thanks in advance and I am looking forward to hearing from you.

Remy. 

Update Backtest








Please checkout the thread we created to help people migrate to QuantConnect from Quantopian. Here is a link to the comment we talk about Universe Selection:

https://www.quantconnect.com/forum/discussion/2317/migrating-from-quantopian-to-quantconnect/p1/comment-7062

You can use that information along with the docs to write your algorithm with our API.
There is also some examples in this forum.

If you have any further questions, then please ask.

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.


Thanks Alex.

the forum u mentioned helped a lot.

But still, I might be quite confused about the whole "universe" thing. I've learned to add universe based on one indicator as the example in help doc and the forum. But how can I combine several indicators(not fundamentals indeed) together. Let's say, for example, I'd like add stocks "price > $5 & volume > 20k & low price > 0.8 * close price" to universe. 

Should I calculate & narrow down the results in func "CoarseSelectionFunction"? and how can I do that? 

Thanks in advance and I am looking forward to hearing from you.

Remy. 

0

Here are come guidelines:
First, you will narrow down the universe with a filter that uses Coarse Fundamental data:

def CoarseSelectionFunction(self, coarse):
# Only consider stock with price above $5 and volume above 20k
mask = filter(lambda x: x.Price > 5 and x.DollarVolume > 20000, coarse)

# sort descending by daily dollar volume
sortedByDollarVolume = sorted(mask, key=lambda x: x.DollarVolume, reverse=True)

# return the symbol objects of the top entries from our sorted collection
top = sortedByDollarVolume[:100]

# we need to return only the symbol objects
list = List[Symbol]()
for x in top:
list.Add(x.Symbol)

return list

We order the list by volume to return the first 100, but we can increase that number.
When securities are added to the universe, the OnSecuritiesChanged method is called. There we can make a historical data request and find the securities that fall under the second criteria:

def OnSecuritiesChanged(self, changes):
self.long = [ ]
for security in changes.AddedSecurities:
history = self.History(security.Symbol, 1, Resolution.Daily)
if history.empty: continue
if history['low'][0] > 0.8 * history['close'][0]:
self.long.append(security.Symbol)

We can later use the list of Symbols (self.long) to place orders.

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