Back

How to get tickers/symbols from Coarse Universe? (Python)

I'm not sure how Universes work. I've read all the documentation and many discussion posts and nothing I have found works for me. How do I get symbols from this? I'm not sure how to put this into a trading function since I can't figure out what this function does and can't see what it is returning. If I had the function 

def OnData(self, data) :

       if ema50 > ema200:

            SetHoldings("?", 0.5 )

What do I put in place for the question mark? I'm not sure how to get the tickers from the Universe to do this.

This is the code that I'm using for my Universe

def Initialize(self):
self.SetStartDate(2000, 1, 15) # Set Start Date
self.SetEndDate(2019, 5, 15)
self.SetCash(1000) # Set Strategy Cash
self.UniverseSettings.Resolution = Resolution.Daily
self.AddUniverse(self.CoarseSelectionFunction)




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

# we need to return only the symbol objects

return [ x.Symbol for x in sortedByDollarVolume[:50] ]
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.


The universe selects the securities and puts them in the ActiveSecurities collection of your algorithm.  Those securities are subscribed to based on you Universe Resolution setting (minute, daily, tick).  In the OnData function you should be able to access the securites.  There are several example algorithms in the source you can look at to help with this.

1

Good answer kctrader -- I've credited you 2 months free live trading =)

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.


When you say I can access them in the OnData function, how do I do that? Here is my code so far. I'm not sure how to access the symbols and use them in other functions. Even in OnData I don't know how to get my securities in there. I try to call the Coarse() function but it says it is not defined.

class TachyonVerticalCoil(QCAlgorithm):

def Initialize(self):
self.SetStartDate(2000, 1, 15) # Set Start Date
self.SetEndDate(2019, 5, 15)
self.SetCash(1000) # Set Strategy Cash
self.UniverseSettings.Resolution = Resolution.Daily
self.AddUniverse(self.Coarse)




def Coarse(self, coarse):
sorted_list = []
# sort descending by daily dollar volume
sortedByDollarVolume = sorted(coarse, key=lambda x: x.DollarVolume, reverse=True)
# we need to return only the symbol objects
values = [ x.Symbol for x in sortedByDollarVolume[:50] ]
return values
#sorted_list.append(values)
#print(sorted_list)









def OnData(self, data):



 

0

Hi Wesley,

In your OnData(),

self.ActiveSecurities[security]

would allow you to access the securities in your universe. This is automatically updated. Check out this and this documentation pages to get more familiar with the API. In addition, please spend some time working through the Boot Camp in Algorithm Lab for API practice as well :)

Hope this helps!

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