Hi!
I'm developing a strategy where I neet to filter the universe of stocks, basing my filtering on certain criteria.
I've used this one as a template:
I filter the securities on their returns, but I do it on the past 2 days adjusted close. For instance, now I fire a buy event every Friday before market close, but the returns are based on the close of Wednesday and Thursday. How can I calculate the returns, instead, basing them on the prices, let's say, of Thursday at 15:30 AND of Friday at 15:30? Can I program the CoarseSelectionFunction to run at a certain time of the day and not everyday at midnight as it seems to do now?
Or the only solution is storing the price in the OnData function with something like " if Time.hour==15.30 " ?
Thanks!
Derek Melchin
Hi Emiliano,
It's not currently possible to schedule the coarse universe selection, but we are working on adding this functionality. Subscribe to this GitHub Issue to be notified of our progress.
Adding the logic above to the OnData method wouldn't work because not all of the SymbolData objects are subscribed to. That is, some of the SymbolData securities don't pass all of the filters in the CoarseSelectionFunction. Therefore, to get the 3:30pm price for all of the SymbolData objects, we would need to perform a History request with a minute resolution in the CoarseSelectionFunction.
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.
Emiliano Fraticelli
So, first of all thank you very much Derek.
For what regards "subscription" to symbols, do you mean the self.addEquity() function in the initialize(self) part of the algorithm, right?
So with the universe selection function, like the CoarseSelectionFunction, we don't need to subscribe to the SymbolData objects one by one using self.addEquity(), right? The ones that are returned from the CoarseSelection function are automatically subscribed, right?
And for my case in particular, let's say I don't mind of this problem:
That is, some of the SymbolData securities don't pass all of the filters in the CoarseSelectionFunction
Adding a fragment of code like this in OnData(self,slice) would return me the prices of my stocks returned by the CoarseSelectionFunction?
if slice.Time.hour==15 and slice.Time.minute==15: for symbol in self.ActiveSecurities: stock_price = slice[symbol].Price self.Debug(stock_price)
Emiliano Fraticelli
Therefore, to get the 3:30pm price for all of the SymbolData objects, we would need to perform a History request with a minute resolution in the CoarseSelectionFunction.
Will this return prices of Friday at 3:30 PM? I mean the coarse selection function is run every midnight with values of the previous trading day.
Doing this on Friday at midnight will return the data of Friday at 3:30 or of
Thursday at 3:30?
Derek Melchin
Hi Emiliano,
> For what regards "subscription" to symbols, do you mean the self.addEquity() function in the initialize(self) part of the algorithm, right?
Correct
> So with the universe selection function, like the CoarseSelectionFunction, we don't need to subscribe to the SymbolData objects one by one using self.addEquity(), right? The ones that are returned from the CoarseSelection function are automatically subscribed, right?
Correct
> Adding a fragment of code like this in OnData(self,slice) would return me the prices of my stocks returned by the CoarseSelectionFunction?
Yes, and it would also include the price of the `benchmark` security. However, for it to work, we would need to increase the resolution from hourly to atleast the minute level.
> Doing this on Friday at midnight will return the data of Friday at 3:30 or of Thursday at 3:30?
By default, if we request 30 bars, the most recent 30 bars of data are returned. For instance, if we call the following command at 12AM on Friday, it will return the QuoteBars from 3:30-4PM Thursday.
self.History(symbol, 30, Resolution.Minute)
To get the bars from 3:30-4PM Friday, we would instead make the history call at 12AM on Saturday morning.
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.
Emiliano Fraticelli
Ok Derek, so from what I understand to trade let's say 10 minutes before market close every friday basing my trade decisions on let's say the returns of the single stock from the opening until let's say 1 hour before the close (and so 50 minutes before I want to place my trades basing them on the returns) the only way to do that is storing these prices in the OnData() function and calculating returns using some RollingWindow or something like it, no way of doing it using the self.history() thing.
Correct?
Derek Melchin
Hi Emiliano,
We can calculate the return from the open to 3PM by using the RateOfChange indicator and an hourly consolidator. See the attached backtest 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.
Emiliano Fraticelli
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!