Is it possible to create a function like EveryDayAfterMarketOpen(self, symbol), which works similar to OnEndOfDay(self, symbol)?
Because when I use end of day data in a plot and use OnEndOfDay to trigger the plot, my plot is always one day behind.
So how should below statement from the documentation be changed to make this possible?
self.Schedule.On(self.DateRules.EveryDay("SPY"), \ self.TimeRules.AfterMarketOpen(self.spy, 10), \ self.EveryDayAfterMarketOpen)
Or is this not possible and should I solve it in a different way?
Louis Szeto
Hi Abco
We can do so through schedule functions:
Best
Louis
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.
Abco Janssens
This works indeed. Thanks!
But my problem is unfortunately not solved, because the end result is the same, my plot is still one day behind. In my plot I want to depict daily closing values of my indicators (daily resolution). But the plot only depicts up until previous day, while today yesterdays closing prices are already known. And then on the previous day it shows the closing price of the day before. So my plot is always 1 day behind. The update of the plot I trigger via OnEndOfDay(self, symbol) or via the events as discussed above? But as said both give same issue. Do you also have a solution for this issue?
Varad Kabade
Hi Abco Janssens,
If we only want to plot the indicator values we recommend using:
which would plot whenever new indicator values are ready. If we are planning to do more than just plotting, please provide us with a backtest/code snippet. We would like to understand the use case to help you more effectively.
Best,
Varad Kabade
Abco Janssens
Hi Varad Kabade,
Thanks for your input. Plotting works fine. But my problem is that I can only plot a value of two days back. That is the case for back testing up until today and also in my live paper trading for the current day. Plots always only show the previous day, and in case of daily resolution you then only see the closing price of the day before (so two days back). While today I want to see the closing price of one day back in case of daily resolution.
Best,
Abco
Abco Janssens
Hi Varad Kabade,
I have created an example to show you what I mean. If you check the plot for example for QQQ, it shows the closing price of tow days back and not of yesterday. Please let me know if this can be solved or whether it is by QC design.
Best regards,
Abco.
Varad Kabade
Hi Abco Janssens,
We compared the plots with the closing prices we found them to be correct. Can you please elaborate more on how do you think they are incorrect? Please find the gif showing different plot values here and a image showing close prices attached.
Best,
Varad Kabade
Abco Janssens
Hi Varad,
The data is correct indeed. But the issue is that in my plot and in my Debug I only see closing price for 28 November (Thursday). In Debug and plot this is shown for 29 November. Today is 1st of November and I can only see 2 days back.
If I change to minute resolution I will see data of 29 November also shown as 29 November in the plot and in the Debug.
I understand that it is maybe due to ‘understanding time’ in QC. But still today I would like to see at market open the closing price of yesterday. But due to daily resolution setting in QC it will only become visible at the end of the day (even though it is already known at 9:30). My algorithm however works fine, but during the day I cannot see why orders are placed etc. Only at the end of the day 15:50 it will become clear what happened during the day, while all the information is available already at MarketOpen 9:30. But it is impossible to show. in Debug and Plot (I tried many ways, let me know if you find one).
Note: now market is closed already, so now 29 Oct closing price is visible and shown as 1 Nov.
Thanks!!
Regards,
Abco.
Abco Janssens
Hi Varad,
In attached back test you can see minute data and daily data together. Please check the data in the Debug Log after running it yourself. Here you can see that Daily data is always one day too late. On 1/11 9:30 the Daily Close is 384.2 (Minute close of 28/10). To my opinion 1/11 9:30 it should be 386.08 (Minute Close 29/10). It will only become 386.08 on 1/11 16:00 in both the Debug Log and in the plot. My impression is, but not 100% sure yet, that the algo calculates indeed at 9:30 already with 386.08, which is to my opinion correct. Why not show it in the same way in the Debug Log and on the plot. Now it is also not possible to log or plot Minute data and Daily date in a correct manner (Daily is always out of sync to my opinion)..
Please let me know if my thinking is incorrect.
Regards,
Abco
Varad Kabade
Hi Abco,
Your understanding is correct. But when using daily resolution, the data for 1/11 will be available at OnData on midnight 2/11. To have more control over our algorithm, it is always better to have finer resolution.
Best,
Varad Kabade
Abco Janssens
Hi Varad,
If my understanding is correct, is it then not better to trigger the update of daily resolution data in the Debug Log and on the plot for 1/11 at midnight 1/11, so that is is shown on 2/11 from 9:30 onwards? What's the use of having one day too late daily resolution data in the log and in the plot? And I still hope (I need to check that once again) my algo uses the correct data! If not daily resolution in QC is completely useless. Regardless whether it is better to have finer resolution. If you want to use daily resolution it should be possible and correct right? I am still not fully comfortable with the answers. So thanks for your patience as well in answering my questions! So I am curious again to your reply.
Regards,
Abco.
Louis Szeto
Hi Abco
Let's get a better understanding of the time. For daily resolution, the 1/11 daily bar is only received at the end of the day (i.e. 2/11 00:00, which is the next minute of 23:59 1/11 if it confused you). The plot is, therefore, plotting 1/11's bar at 2/11 00:00. If you planned to plot the last datapoint as the data from 1/11, you can still set the end date as 1/11 but the last plotted point would be at 2/11 00:00. Note that no data will be received at 9:31 am. On the other hand, for minute resolution, The last bar is received at 16:00 1/11 rather than 2/11 00:00.
Both the data of daily and minute resolutions are correct. We suggest using finer resolution is because it is more realistically filled since it is using the bid-ask price at the moment for filling but not the last trading price.
Best
Louis
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.
Abco Janssens
Hi Louis,
What maybe confused me is the function OnEndOfDay. On the current day it will only give previous day close (set-up as self.close = algorithm.SMA(symbol, 1, Resolution.Daily) at 15:50 in both self.Debug and self.Plot. While I assumed EndOfDay event would give previous EndOfDay closing price from the beginning of the current day.
If I trigger the self.Debug and self.Plot via OnData (for which I always use Minute data, same as stated by you) at 9:31, it will show the previous day close (set-up as self.close = algorithm.SMA(symbol, 1, Resolution.Daily) already at 9:31 on the current day. For self.Debug I checked already in Live and that is indeed the case. For self.Plot I still need to check in Live, but I assume it will work the same (I cannot stop it now because it is running). So to have up to date daily resolution indicators on the current day, I need to move the code for self.Plot and self.Debug for the daily resolution indicators from OnEndOfDay to OnData including below code
current_time = datetime.strftime(self.Time,"%H:%M")
if self.Time >= self.StartDate and current_time > "09:30" and current_time <= "09:31":
self.Debug()
self.Plot()
Can you please confirm whether above understanding / solution is correct. Thanks!!
Regards,
Abco.
Varad Kabade
Hi Abco Janssens,
What you have stated above is correct. For checking for conditions to plot we recommend the following:
Best,
Varad Kabade
Abco Janssens
I have checked solution confirmed by Varad now in live and what happens is that it works, but after 9:31 the plot disappears again, because no data is coming anymore. Ultimately the best solution is the first one given by Louis to use scheduled events.
I struggled quite a lot to get this clear. But now it is fully clear. Back-testing does not work up until current day, only up until previous day. That's why in back-testing, even with end date as current day and market already open, only prices are shown up until day before yesterday for daily resolution indicators. But in live with a scheduled event at eg. 9:45 it is possible to plot the closing price of yesterday for daily resolution indicators.
Abco Janssens
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!