Back

Backtest using all stocks

Hello,

I'm new here and just dicovered Quant Connect, it looks promising.

Immediately I have a question though: I'm used to run backtests on all stocks and it seems I have to add each stock manually. Is there a way to run a backtest on many stocks at once? I'd like to receive, for example, minute bars for all active stocks between 1/1/2010 and 12/31/2010. So each "OnTradeBar" dictionary should have about 6000-8000 items in it if I request just NYSE and NASDAQ stocks. How would I do this in the "Initialize" method and is this even possible with QuantConnect?

Thanks!
-luke
Update Backtest








Ah i just saw in the Docs that I can only add 500 1 minute stock.
https://www.quantconnect.com/docs/API#2.2.2

Is there a way to request EOD data for all stocks and then use that to select the minute data to subscribe to?
0

Thanks Lukas! -- Welcome to QC -- The limit is based on RAM each strategy can use (at the moment 1GB) but we can scale that if required until 3GB with few issues. All 16,000 stocks would consume a fair amount of ram and take quite a while to process.

EOD is a good idea, and on the roadmap. Its taken a while but we're getting there :)

We're slowly open sourcing and tidying up the base code, I'd welcome your help if you're interested in extending the base classes: https://github.com/QuantConnect/QCAlgorithm
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.


Yeah, I know, to have all that data in memory is not feasible (maybe with AWS it is...). I can run a strategy with minute data for all stocks for several years in about 20-30 minutes, reading the required data straight from the file system. Are you keeping all the data in memory? Are you keeping only ticks and then compressing them on the fly?

In my experience it's a good feature to be able to run a strategy on all EOD data (lets say all NYSE and NASDAQ stocks) and then on every EOD bar event I use the EOD data to select the intraday data for that day, be it bars or ticks. Then I have the best of both worlds.

This is how it could look like:
public class BasicTemplateAlgorithm : QCAlgorithm, IAlgorithm
{
//Initialize the data and resolution you require for your strategy:
public override void Initialize()
{
//Initialize the start, end dates for simulation; cash and data required.
SetStartDate(2012, 06, 01);
SetEndDate(2012, 12, 30);
SetCash(30000); //Starting Cash in USD.
AddSecurities("NYSE", Resolution.EOD);
AddSecurities("NASDAQ", Resolution.EOD);
SetRunMode(RunMode.Series); //Series or Parallel for intraday strategies.
}

//Handle TradeBar Events: a TradeBar occurs on every time-interval
public override void OnTradeBar(Dictionary data)
{
if(IsEod)
{
//remove yesterdays intraday data, to get ready for todays data
//this could be done smarter too where only the new securiteis
// are added and the old ones removed.
ClearSecurities(Resolution.Minute);

var selectedStocks = OnEndOfDay(data);
foreach(var selectedStock in selectedStocks)
{
AddSecurity(SecurityType.Equity, selectedStock, Resolution.Minute);
}
//also request the securities for open positions from yesterday
}
else
{
OnIntraday(data);
}
}

private IList OnEndOfDay(Dictionary data)
{
//select the most insteresting stocks based on eod data.
// could be volatility, volume, paterns, MAs...
return mySelectedStocks;
}

private void OnIntraday(Dictionary data)
{
//look for intraday patterns and trade them
}
}
1

Very cool @LukasB├╝hler - Bars are pre-processed and stored in files as bars. We were trying to figure out the best way to filter/ do a stock-universe function. I'll have to re-process the minute bars into daily ones at the moment but it seems worthwhile. We could create the volume information from the ticks as well.
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.


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