Hello guys, I'm new to QC.
In my logic, I want scan top gain stock and trade by them in minute resolution inlcude pre and after market.
I read source code found `Algorithm.Python/CustomDataUniverseAlgorithm.py` in source code.
It seems like `http://www.wsj.com/mdc/public/page/2_3021-gainnyse-gainer.html` not include pre-market data.
Can anyone help me?
Derek Melchin
Hi Cool nemo,
To create a universe of securities that are the top gainers, we can adjust the EmaCrossUniverseSelectionAlgorithm to use the RateOfChange indicator. Note that this will create a universe of securities with the largest return based on the close of the last trading day, not the current market price.
To subscribe to data outside of regular market hours, we can use
self.UniverseSettings.ExtendedMarketHours = True
Best,
Derek Melchin
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.
Cool nemo
@Derek Melchin thank for u reply.
About Pre_Market Data, I found wsj support, code is here.
import requests headers = { 'sec-ch-ua': '"Chromium";v="88", "Google Chrome";v="88", ";Not A Brand";v="99"', 'Referer': 'https://www.wsj.com/market-data/stocks/extendedhours?mod=md_usstk_view_ext_hours_full', 'sec-ch-ua-mobile': '?0', 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 11_1_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.150 Safari/537.36', } params = ( ('id', '{"application":"WSJ","count":15,"isExtendedHours":true}'), ('type', 'mdc_stockmovers'), ) response = requests.get('https://www.wsj.com/market-data/stocks/extendedhours', headers=headers, params=params) response.json()
but in backtest (just test this work) , I got erorr.
Does runtime has some network restrict
During the algorithm initialization, the following exception has occurred: ProxyError : HTTPSConnectionPool(host='www.wsj.com', port=443): Max retries exceeded with url: /market-data/stocks/extendedhours?id=%7B%22application%22%3A%22WSJ%22%2C%22count%22%3A15%2C%22isExtendedHours%22%3Atrue%7D&type=mdc_stockmovers (Caused by ProxyError('Cannot connect to proxy.', OSError('Tunnel connection failed: 403 Forbidden',)))
Derek Melchin
Hi Cool nemo,
We recommend using the premarket data we have available instead of utilizing outside sources. However, when using wsj.com as the data source, we should replace `requests` with the `Download` method to ensure the data gets transmitted correctly.
See the attached notebook for reference.
Best,
Derek Melchin
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.
Cool nemo
@Derek Melchin thank for u reply.
`qb.Download` works for me.
I use live premarket data to chose top gainer, it seem quantconnect not provide
Derek Melchin
Hi Cool nemo,
We have premarket data available. To subscribe to it, refer to this related thread.
Best,
Derek Melchin
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.
Cool nemo
Hi @Derek Melchin
the pre-market top gainer logic is sort by current price roc with yesterday close price.
I should get this list first and then `AddEquity` to subscribe data.
the worst solution is subscribe all equity pre-markt data and get roc rank
Derek Melchin
Hi Cool nemo,
It may be an inefficient approach when compared to using an external data source. However, when implementing this type of universe with built-in components, this related thread discusses how we can select a subset of our universe based on intraday performance.
Best,
Derek Melchin
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.
Cool nemo
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.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!