Back

Universe Management Outside CoarseSelectionFunction - Large Universes

I am trying to work with a live algo that uses a large universe(over 300, such as 500-2k+). I do work on historical data pre-open and then filter down to a handfull of assets to trade. I have some simple batch downloading that helps me ease up on History in live servers (20 sec timeout, with large universe I loop through each asset which takes ~350+seconds for 300 assets). But, when I go well over 300 assets I risk a timeout with CoarseSelectionFunction in live trading.

Example backtest with spread out History downloads:
https://www.quantconnect.com/terminal/processCache?request=embedded_backtest_f8760e10b464a86ad50f0638d9eeb86b.html

I am now trying to take asset management(adding and removing) 'outside' of CoarseSelectionFunction in order to prevent a timeout on firing and to reduce the cpu usage intraday. I have saved off the list of assets, returned [], and later on in the morning use my working batch download from above with the addition of adding/removing only what assets are needed. This, however, is yielding a different universe composition and I was wondering if anyone had suggestions to achieve a 1:1 result between the above example and the following.

Example backtest with manually added/removed assets as needed, but different results:
https://www.quantconnect.com/terminal/processCache?request=embedded_backtest_565a1209115024cba5e0df9374c67c6f.html

I would appreciate any thoughts or ideas on this challenge!

Scheduling issue note:
I use minute mode and normal market hours. I am unable to schedule functions, based on SPY, to occur before 9:31 am. Note the 1, odd. Anything scheduled pre-open in a backtest(live seems to work) fires at 9:31, all on top of each other and out of order. Also, anything scheduled 0 minutes after open also seem to fire 1 minute late. I have had to shift my calls into the market for backtesting to prevent errors. This can be seen/played with in the code and seen in the logs backtest logs. One day log sample:
2017-05-25 00:00:00 : CoarseSelectionFunction 2017-05-24 16:00:00
2017-05-25 09:31:00 : Downloader 0 2017-05-25 09:30:00
2017-05-25 09:31:00 : Downloader 1 2017-05-25 09:31:00
2017-05-25 09:32:00 : Downloader 2 2017-05-25 09:32:00
2017-05-25 09:33:00 : Downloader 3 2017-05-25 09:33:00
2017-05-25 09:34:00 : Strategy 2017-05-25 09:34:00
2017-05-25 09:35:00 : Rebalance 2017-05-25 09:35:00

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.



In live testing this morning, the first backtest above(where I spread out downloads each morning and rely on Coarse to update the universe automatically) had some trouble as a rather odd asset existed in self.universe that caused a key error:

QC-UNIVERSE-COARSE-USA 2T

Is this unique/related to some caveat in live trading?

0

I found some info relating to my schedule issue, though I am unsure why I am getting out of order code running in the backtester when it should be firing at the right time, despite the odd log timestamps(explained in post below, related to datetime of next datapoint vs time it was fired)

I guess this means my overall problem now is that relying on what CoarseSelectionFunction returns, vs using AddEquity pre-market(if that is what the backtester is trying to do as scheduled), is resulting in a very different universe composition. A way around this would allow me to extend my use of Coarse beyond ~3-400 assets. I am also worried about how this will impact my use of the new Framework for this style of algo(working half outside Coarse before universe is finalized).

https://www.quantconnect.com/forum/discussion/1860/having-trouble-scheduling-30-mins-before-a-trading-day/p1/comment-5747
0

I got things nearly working. Something about my attempt to move away from OnSecuritiesChanged after nixing the "full use" of CoarseSelectionFunction to return assets broke something to prevent the near same results. Still trying to figure out where the slight difference is coming from. But, for now, I can move forward with taking a larger universe algo live. Here are the backtests so far:

Backtest - Using Coarse to set assets like normal

Backtest - Manually adding and removing assets

Visual Comparison(click for full size):

0

Nice visual comparison thanks Derek; normally the best place to start is the data and go up from there. Perhaps you could 1) remove trading logic; then 2) log the securities in the algorithm each day (in alphabetical order). Then diff those two files and it should point out the root difference. e.g.

2017-01-01: AAPL, BAC, IBM, SPY, Z
2017-01-02 AAPL, BAC, CAT, IBM, SPY, Z

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