Back

Universal Selection - not loading the equities on the same day

Hello,

I am trying to develop uptick vs downtick based on stocks trading on NYSE.  I am trying to understand few things. I have shared my code and results as well.

Q1: Looking at the code  below, although the start date is 01/23/2019 - QC universe does not load into Slice until the following day. I have tested it with multiple date ranges and i encounter the same issue. Is there something i can do to rectify this?

Q2: I developed a coarse and fine filter, which returns around 1000 symbols. While doing backtesting, i believe everyday these symbols gets loaded into filter function, which inturn is returned to onData event. I need close prices of these stocks every minute to see if they are upticking or not. In doing so, i wonder, in order to speed up algo, is there anything other than not restricting the stocks. If you have an example, that would be good. Would restricting the universe filter function to run only once a week speed up backtesting speed of the algo? Is there a way for filter not to pass all the properties of the equity - there are around 900 properties from morning star available. 

Your thoughts are highly appreciated.

# Backtest inputs
START_DATE = "01/23/2019" # must be in "MM/DD/YYYY" format
END_DATE = "01/24/2019" # must be in "MM/DD/YYYY" format
CASH = 100000 # starting portfolio value
################################################################################
# Import libraries required
import clr
clr.AddReference("System")
clr.AddReference("QuantConnect.Algorithm")
clr.AddReference("QuantConnect.Common")

from System import *
from QuantConnect import *
from QuantConnect.Algorithm import *
from QuantConnect.Data import *
from QuantConnect.Data.Custom import *
from QuantConnect.Data.Market import *
from QuantConnect.Data.Consolidators import *
from QuantConnect.Indicators import *

from Selection.QC500UniverseSelectionModel import QC500UniverseSelectionModel
from datetime import timedelta, datetime
from System.Drawing import Color

################################################################################
class BasicTemplateAlgorithm(QCAlgorithm):
def Initialize(self):
# Setup the backtest
# Set the start and end date (YYYY, MM, DD)
start_split = START_DATE.split('/')
self.SetStartDate(int(start_split[2]),
int(start_split[0]),
int(start_split[1]))

end_split = END_DATE.split('/')
self.SetEndDate(int(end_split[2]),
int(end_split[0]),
int(end_split[1]))

# Set the starting equity amount
self.SetCash(CASH)

# Set the user time zone to be ET
self.SetTimeZone(TimeZones.NewYork)

# Define the brokerage model and account type
self.SetBrokerageModel(BrokerageName.Default, AccountType.Margin)

# Disable margin call model
self.Portfolio.MarginCallModel = MarginCallModel.Null

# Use the QC500 Universe
self.AddUniverseSelection(QC500UniverseSelectionModel())
self.UniverseSettings.Resolution = Resolution.Minute

# Add SPY for timing relative to open/close
self.AddEquity("SPY")

################################################################################
def OnData(self, slice):
"""Event handler for new data."""
# Check for new minute bar
if self.Time.microsecond == 0 and self.Time.second == 0:
# Update McClellan Oscillator
counter = 0
for stock in slice.Keys:
# Use try/except block to handle possible future data in slice
try:
if self.Time.hour == 9 and (self.Time.minute == 30 or self.Time.minute == 31 ) and counter <= 10:
self.Log('{} {} O:{} C:{} '.format(str(self.Time),str(stock),slice.Bars[stock].Open,slice.Bars[stock].Close))

counter = counter + 1
except:
continue

 

2019-01-23 00:00:00 : Launching analysis for 214bbbb2374852945b231c4b84833069 with LEAN Engine v2.4.0.0.6113
2019-01-23 09:31:00 : 2019-01-23 09:31:00 SPY O:261.580210366 C:261.609934264
2019-01-24 09:31:00 : 2019-01-24 09:31:00 A RPTMYV3VC57P O:71.15758128 C:71.22728504
2019-01-24 09:31:00 : 2019-01-24 09:31:00 AA WF7IHVI76I5H O:28.15 C:28.05
2019-01-24 09:31:00 : 2019-01-24 09:31:00 AAL VM9RIYHM8ACL O:34.068531138 C:33.988978234
2019-01-24 09:31:00 : 2019-01-24 09:31:00 AAP SA48O8J43YAT O:164.685486045 C:164.37572025
2019-01-24 09:31:00 : 2019-01-24 09:31:00 AAPL R735QTJ8XC9X O:152.69477934 C:152.9526762
2019-01-24 09:31:00 : 2019-01-24 09:31:00 ABBV VCY032R250MD O:86.020359137 C:86.010638224
2019-01-24 09:31:00 : 2019-01-24 09:31:00 AAS R735QTJ8XC9X O:78.52610337 C:78.803370822
2019-01-24 09:31:00 : 2019-01-24 09:31:00 ABMD R735QTJ8XC9X O:337.5 C:339.54
2019-01-24 09:31:00 : 2019-01-24 09:31:00 ABT R735QTJ8XC9X O:69.454623 C:69.533999712
2019-01-24 09:31:00 : 2019-01-24 09:31:00 ADBE R735QTJ8XC9X O:245.62 C:244.24
2019-01-24 09:31:00 : 2019-01-24 09:31:00 ADI R735QTJ8XC9X O:89.632037927 C:90.759982769
2019-01-25 00:00:00 : Algorithm Id:(214bbbb2374852945b231c4b84833069) completed in 11.01 seconds at 19k data points per second. Processing total of 204,088 data points.
 
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.


Hi Narayanan,

Q1: QC Universe Selection uses EOD data and is fired every day after the market close when data becomes available.

Q2: We are aware of the speed issue and we are already working hard to bring a solution to make the backtest faster. We expect the speed to improve in the next week. Even with a scheduled event, Universe Selection still happens every day and it won't change the speed. We will keep you updated once we made the improvement.

Thanks for supporting QC! 

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