Back

[Feature] Universe Using Remote Symbol Selection

Hey all!

Ever wanted to fetch symbols to trade each day from a remote server? Maybe you have a file uploaded to dropbox each day, or can call a web service to get a list of symbols to trade for the day. This is now all possible using our newest feature: universe selection!

In the attached algorithm I show how you can add a universe that will look to dropbox for both backtesting and live modes. This is all done through the AddUniverse method which is how we define a new universe. The general idea behind all of the AddUniverse methods is that they define how you choose your symbols. The main argument to these methods is a selection function that returns the symbols to be traded. Have a look at this example: AddUniverse("my-universe-name", Resolution.Daily, dateTime => {
return new List{"SPY", "GOOG"};
});

Now the example above is simple and contrived, but I think it shows some important things. First off, we give our universe a unique name, then we specify that this universe should 'fire' on a daily resolution, that is, at midnight on trading days. The final argument is our selection function that accepts a DateTime as the argument and returns an IEnumerable or IEnumerable. For those unfamiliar, IEnumerable can be viewed as a more generic version of List that only allows you to loop over it.

So in this example, our selection function will be called each trading day at midnight and will return the list of symbols that we want to trade for the next day! The engine will handle getting you all the data you need and will never remove data if you have open orders or open positions!

Check out the attached demo algorithm and let us know what you think!!
Update Backtest






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.



HI Michael

Best feature but correct me if im wrong on the logic here.

Your universe changes at 12, but you still have the old stocks with open positions, thus they are still a part of the universe. You then call on tradebar and it buys everything in the universe again, which creates an odd loop and the algo seems to not always buy/sell as is in the excel.

I tried something like

var percentage = 1m/_backtestSymbolsPerDay[Time.Date].Count;
foreach (var symbol in _backtestSymbolsPerDay[Time.Date])
{
SetHoldings(symbol, percentage);
}

It then only sets the holding to the new symbols, rather than the entire active universe. Just something you might want to look at.

I am trying to figure out a couple things still

A. Can I remove tickers from the universe as well ? My universe keeps growing until it reaches 500 and then stops due to the limit/

B. Now that you dont add every stock seperately, how can I change the transaction model of the universe to a flat fee one ?

Thanks again for the feature already seeing some great results. Also the engine seems to handle missing securities that are not available in your database a lot better now which is a nice added bonus.

Regards
Daniel
0

A> This happens automatically when universe selection is performed (that is, securities are returned and we did not use Universe.Unchaged) If you need further help with this please share the algorithm, or if not willing to share, send me the project ID and I can take a peek at it with your permission.

B> In the OnSecuritiesChanged(SecurityChanges changes) event, you have access to each security via the changes.AddedSecurities and changes.RemovedSecurities. If you loop over your added securities, you can set your transaction models.
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.


Question when you say

// define a new custom universe that will trigger each day at midnight

Does this still count as the current day if I use DateTime.Now in the update function, or the next day ?
0

I would strongly recommend against ever using DateTime.Now. For one it assumes that your server is set up with a certain time zone. Instead use the Time property of the algorithm for the algorithm's local time, or the UtcTime property for the current UTC time.
If you're trying to determine a date for the purposes of universe selection, you should actually use the 'dateTime' parameter in the selection function (copied from above):// the dateTime parameter in the universe function is the local time this is being triggered
// in this case, midnight NYC time
AddUniverse("my-universe-name", Resolution.Daily, dateTime => {
return new List{"SPY", "GOOG"};
});
The 'dateTime' parameter in the universe selection function will be the local universe time at the point of trigger, which in the Resolution.Daily case will be 12:00AM NYC time (EST/EDT). To answer your question more directly, if something triggers 'at midnight' or 'on the hour' or 'on the minute' - it means it will reach your algorithm ~10 milliseconds after 'midnight'/'hour'/'minute'.

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.


One important thing to keep in mind is that the example above is what we call a user defined universe, that is, it doesn't perform selection based on data retrieved using the Engine. For a non-user defined universe (such as coarse), the selection is performed when the data is available. For coarse universes, this data is usually available by 2am and guaranteed to be after midnight.
1

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.


I am new to Quantconnect (as in less than 1 hour of reading through the docs) and I am a bit confused on this universe selection. First, let me explain what I want to do.

I would like to grab the list of all stocks which trade on a US exchange and then rank them based on various criteria of my choosing. There are more than 500 stocks which trade on US exchanges. I can filter out a significant number of stocks with some fairly simple tests on volume, closing prices, balance sheet, income statement, and cash flow statement. However, I will still likely have well over 1000 stocks left to perform more in-depth analysis on. I would use a considerable number of additional computational factors to rank and filter the stocks down to about 20 which I would actually purchase. I would use another set of computational factors to decide when to sell those stocks.

Is this Universe the list of initial stocks I would start out analyzing? That's what I think you are saying, and that's what I would expect. But if that's the case, is it limited to only 500 symbols? Because I would need thousands in there to start with.

Am I correct in assuming that I could take some initial list of symbols (let's ignore how many for a moment) and then filter those into a newly created "smaller" universe of symbols which I could loop over for the more extensive checks I need to perform?

Am I correct in assuming that I could create multiple such smaller universes which I could perform separate analysis techniques on (i.e. splitting the stocks up into multiple universes based on market capitalization)?
0

Welcome @Eliot - the universe function scans all 9000 current equities and applies your filter. It allows selecting/following 500 simultaneous symbols at a time. Check out the example code in the project at the top to see examples of it in operation! :)
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.


Hey guys,

On another note, is it possible to set the time at which the universe selection occurs?


Thanks!
0

Hey Riley, I've answer this question on this thread. There's an example algorithm that shows how you can define a custom universe object which will set the times the universe triggers.
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.


Ah thanks!
For some reason I couldn't find that old thread.
0

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