I'm trying to schedule an event for the third Tuesday of every month to take advantage of monthly option expiry timing - how can I do this using scheduled events? I can't seem to find anything that lets me specify which week of the month in provided documentation.
Vladimir
Dawgzy
Try this
If you are satisfied with my answer, please accept it and don't forget to like it.
Fred Painchaud
Hi Dawgzy,
You can also have an event if that is what you wanted. To separate concerns from OnData.
Fred
Vladimir
Dawgzy
This way is even better because it takes into account when the expiration occurs on a Thursday.
Vladimir
Dawgzy
“Three days before expiration Day”
Mcdawgzy
Fred Painchaud Vladimir Thanks for these responses, greatly appreciated.
Is there any way to reference something defined in one of the scheduled events in OnData? For example, in the below it's giving me Runtime error as ‘dayPerf’ is not defined on Ondata.
Fred Painchaud
Hi Dawgsy,
Yep.
Use:
self.dayPerf = self.Securities[STOCK].Open - self.Securities[STOCK].Close
and then:
if self.dayPerf > 0:
Adding self. before makes the variable an instance variable of the object instead of a local variable in the function. So the object holds the variable in-between calls. Long story short 😊.
Fred
P.S. You will also want to do something with self.Log(str(monPerf)), as monPerf will be undefined as you'll get warned as soon as you correct the first mistake. It is probably an old name and you now want to use self.dayPerf there also.
Mcdawgzy
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!