Hi,
I am deploying an live algo (using alpha framework) that only analyzes closing prices at 4:00pm (market close) once a day. Based on my analysis at 4:00pm, I will be placing market-on-open orders immediately for the next morning.
To achieve this, I am using the minute resolution and has the following in the Update() method inside my alpha model:
class MyAlphaModel(AlphaModel):
def Update(self, algorithm, data):
# at market close
if algorithm.Time.hour == 16 and algorithm.Time.minute == 0:
# analysis goes here
...
Given my goal, is this the best way to do it both in backtesting and live mode? Would love to know about the best practices here. Thanks in advance.
Louis Szeto
Hi Fishstoryyy
I guess your resolution is not Daily in that setting. You can use schedule method in initialize method of your algo class like
Or even set a time like At(0,0). then emit insights in that function which could save a bit time from checking if statement and memory from initializing a new class. But if you insist of using alpha framework, this is a more general precise method:
your way works fine though in typical US traded stocks.
My experience told me that the market-on-open orders are sometimes having extreme spread for illiquid stocks so that your filling might go wrong. You might consider use SpreadExecutionModel()
Cheers
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.
Varad Kabade
Hi Fishstoryyy,
Thank you, Louis, for your response.
We suggest using the ImmediateExecutionModel, for the above strategy and update the following code.
to,
Note that we should avoid placing the order exactly at 16:00 because in practice the market is closed. We recommend placing it a couple of minutes before, e.g. 5 minutes before the close.
Best,
Varad Kabade
Fishstoryyy
Hi Varad and Louis,
Thank you for your input here and I will trying them out.
My live algo ran into a data problem after doing exactly what I described. My live data feed at 4:00pm was missing data on a lot of the added symbols (I am on Minute resolution by the way) and the Update method is confusingly called twice at market-close when I expect it to be called once each minute:
Log:
Can you please help me figure out what happened and what needs to be fixed? From the log, it looks like the Update() method was first called exactly at 4:00pm and then called again 1 second after. How is that possible given my resolution is minute? This is a big deal to my live algo. Thank you in advance.
Fishstoryyy
Hi,
Need help here.. I tried using the scheduled event as follows and the same problem still happens during live trading:
In my EveryDayBeforeMarketClose function, I have the same log messages that tell me I don't have data:
Varad Kabade
Hi Fishstoryyy,
For queries/questions regarding live algorithms, please contact support@quantconnect.com
Best,
Varad Kabade
Fishstoryyy
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!