Back

OnData not getting all the symbols

I'm confused by the fact that OnData doesn't seem to be receiving the full list of symbols that I wish to evaluate.  I have attached a backtest with a sample app to convey my question & confusion.  It's not a real algorithm.  

I'm loading into a custom universe on a daily basis a random set of 20 (out of 100) symbols.  When OnData is getting called, there are sometimes 0 symbols passed in, or 7, or 18 ... I must be missing something.  I would expect that if I'm loading a universe with 20 symbols that when OnData gets called that it would be able to evaluate trading rules for all 20 of those symbols, not some (seemingly) randon subset.

Surely there is just a misunderstanding on my part somewhere?  In the log snippet below you'll see that each day the universe is loading up 20 symbols, yet in OnData, only 16, 9, and 2 are available.  The full details are in the attached backtest.

Secondly - why on earth does this backtest take nearly 3 minutes?  It's really not doing any processing at all.  And, if I change the number of symbols I'm loading into the universe to be around 100 (which I want to do) I get timeout errors executing the backtest.

Log Snippet:

2016-11-01 00:00:00 Launching analysis for 3694b60833dd6868c9715ce5b1ceec91 with LEAN Engine v2.2.0.2.875

2016-11-01 00:00:00 ENFDataManager loaded 50 records.

2016-11-01 08:30:00 Universe selection trigger time: 11/01/2016 08:30:00 - Number of symbols: 20

2016-11-01 09:30:01 OnData: Date: 11/01/2016 00:00:00 - Count: 16

2016-11-02 08:30:00 Universe selection trigger time: 11/02/2016 08:30:00 - Number of symbols: 20

2016-11-02 09:30:01 OnData: Date: 11/02/2016 00:00:00 - Count: 9

2016-11-03 08:30:00 Universe selection trigger time: 11/03/2016 08:30:00 - Number of symbols: 20

2016-11-03 09:30:01 OnData: Date: 11/03/2016 00:00:00 - Count: 2

Any help & explanations greatly appreciated.  Thanks!

Update Backtest








In this algorithm, the user defined universe count is evaluated as soon as market is open. By that time, not all securities have had their first trade of the day, therefore the TradeBars object will not contain all the required symbols.
Please, check it some minutes after the market is open:

public void OnData(TradeBars data)
{
if (Time.TimeOfDay == TimeSpan.FromHours(10))
{
Debug("OnData: Date: " + data.Time.Date +
" - Count: " + data.Count);
}
}

 

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.


I thought pehaps the same thing and made a similar code change earlier but haven't had a chance to follow-up here.  Thanks again, Alexandre for your quick response.  

Trying your code I still don't get as many items in OnData as expected.  Th recent change I made looks like this to print out the count 3 times a day.  Still unexpected results (to me).

        public void OnData(TradeBars data)
        {
            if( Time == new DateTime(Time.Year, Time.Month, Time.Day, 10, 0, 0) ||
                Time == new DateTime(Time.Year, Time.Month, Time.Day, 13, 0, 0) ||
                Time == new DateTime(Time.Year, Time.Month, Time.Day, 15, 30, 0))
            {
                // a new day!
                Debug("OnData: Date: " + Time + " - Count: " + data.Count);
            }

        }

And running this I'm still getting unexpected (to me) results.  The universe starts with 20 symbols, and i'm still only getting a subset of them in OnData most of the time.  Another snippet from the log:

Universe selection trigger time: 11/01/2016 08:30:00 - Number of symbols: 20

OnData: Date: 11/01/2016 10:00:00 - Count: 18

OnData: Date: 11/01/2016 13:00:00 - Count: 19

OnData: Date: 11/01/2016 15:30:00 - Count: 18

Universe selection trigger time: 11/02/2016 08:30:00 - Number of symbols: 20

OnData: Date: 11/02/2016 10:00:00 - Count: 10

OnData: Date: 11/02/2016 13:00:00 - Count: 10

OnData: Date: 11/02/2016 15:30:00 - Count: 9

Universe selection trigger time: 11/03/2016 08:30:00 - Number of symbols: 20

OnData: Date: 11/03/2016 10:00:00 - Count: 4

OnData: Date: 11/03/2016 13:00:00 - Count: 4

OnData: Date: 11/03/2016 15:30:00 - Count: 3

Universe selection trigger time: 11/04/2016 08:30:00 - Number of symbols: 20

OnData: Date: 11/04/2016 10:00:00 - Count: 20

OnData: Date: 11/04/2016 13:00:00 - Count: 20

OnData: Date: 11/04/2016 15:30:00 - Count: 19

0


I added a plot to mean count of symbols since we could have been missing symbols due to their liquidity:

private int count = 0;
private int sum = 0;

public void OnData(TradeBars data)
{
count++;
sum += data.Count;
}

public override void OnEndOfDay()
{
Plot("Plot", "Mean", (decimal)(sum/count));
count = 0;
sum = 0;
}

And I could confirm that on the November 2nd and 3rd, there are far less than 20 symbols. The algorithm may be adding symbols that are not very liquid (or were deslisted, please checkout the data here).

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 again, Alexandre for the prompt response.  But, I'm pretty sure for my testing purposes that I selected some very liquid stocks.  I updated the static list (for testing purpose) once again from these two sources:
http://online.wsj.com/mdc/public/page/2_3021-activnyse-actives.html
http://www.nasdaq.com/markets/most-active.aspx

these are the most active from the NYSE and NASDAQ.  I have the top 30 from the NYSE and top 20 from the NASDAQ on my [new] list.  I've also changed the test sample so that the random seed is consistent so that everyone will get the same "random" 20 stocks for each day. 

Yet, when I run this, using 30 of the top most NYSE active and 20 of the top most NASDAQ active, and check the symbol count at 3 different points in the day, I'm still significantly lacking on the number of expected symbols in OnData().  Am I still doing something wrong, or is there an infrastructure bug?  Surely I'm still doing something wrong or others would have cried foul a long time ago.

2016-11-01 00:00:00 ENFDataManager loaded 50 records.

2016-11-01 08:30:00 Universe selection trigger time: 11/01/2016 08:30:00 - Number of symbols: 20

2016-11-01 10:00:00 OnData: Date: 11/01/2016 10:00:00 - Count: 20

2016-11-01 13:00:00 OnData: Date: 11/01/2016 13:00:00 - Count: 20

2016-11-01 15:30:00 OnData: Date: 11/01/2016 15:30:00 - Count: 19

2016-11-02 08:30:00 Universe selection trigger time: 11/02/2016 08:30:00 - Number of symbols: 20

2016-11-02 10:00:00 OnData: Date: 11/02/2016 10:00:00 - Count: 6

2016-11-02 13:00:00 OnData: Date: 11/02/2016 13:00:00 - Count: 6

2016-11-02 15:30:00 OnData: Date: 11/02/2016 15:30:00 - Count: 5

2016-11-03 08:30:00 Universe selection trigger time: 11/03/2016 08:30:00 - Number of symbols: 20

2016-11-03 10:00:00 OnData: Date: 11/03/2016 10:00:00 - Count: 2

2016-11-03 13:00:00 OnData: Date: 11/03/2016 13:00:00 - Count: 2

2016-11-03 15:30:00 OnData: Date: 11/03/2016 15:30:00 - Count: 1

0


Thanks Ted for digging into it. There were a couple of days with partially processed data. I've setup those two days for reprocessing and they'll be done in 4-5 hours. In future its more productive to report issues like this directly to support@quantconnect.com

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, @Jared.  I wasn't sure if I was doing something wrong (more likely) or a infrastructure issue.  So, I erred on the side of the Community vs Support.  In the future I'll try support.  Thanks so much to both you and Alexandre for your help and support.

 

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