Introduction
The expiration date for an Options contract is the time when the contract is no longer valid. The expiration date for listed stock Options in the United States is usually the third Friday of the contract month, which is the month when the contract expires. When that Friday falls on a holiday, the expiration date is on Thursday immediately before the third Friday. The Options expiration week is a week before Options expiration.
During Option-expiration weeks, a reduction occurs in Option open interest as the near-term Options approach their expiration and then expire. According to a research from Chris and Licheng Returns and Option activity over the Option-expiration week for S&P 100 stocks, large-cap stocks with actively traded Options tend to have higher average weekly returns during Option-expiration weeks. In this algorithm, we'll use the real market data to explore the Option expiration week effect.
Method
The S&P 100 index includes 102 leading U.S. stocks with exchange-listed Options. The constituents represent almost 51% of the market capitalization of the U.S. Equity market. Here we trade the S&P 100 index ETF as a portfolio of U.S. large-cap stocks.
In the next step, we add the Options to get their expiration dates. The range of expiration dates should bigger enough to include the the contract which expires in this month.
def initialize(self):
self.set_start_date(2007, 1, 1)
self.set_end_date(2018, 8, 1)
self.set_cash(10000)
self.add_equity("OEF", Resolution.MINUTE)
option = self.add_option("OEF")
option.set_filter(-3, 3, timedelta(0), timedelta(days = 60))
self.set_benchmark("OEF")
To get a list of expiration dates from the contracts in the current Option chain, we can use TradingCalendar object.
It allows us to filter the calendar days by the type TradingDayType.OPTION_EXPIRATION
and the start as well as the end date.
The expiry at the top of the list is the most recent expiration date.
The long position is opened at the start of the expiration week. Therefore, we use a Scheduled Event to fire the Rebalance
method every Monday.
If the current Monday is in the expiration week, we long the S&P 100 index ETF.
def rebalance(self):
calendar = self.trading_calendar.get_days_by_type(TradingDayType.OPTION_EXPIRATION, self.time, self.end_date)
expiries = [i.date for i in calendar]
if len(expiries) == 0: return
self.lastest_expiry = expiries[0]
if (self.lastest_expiry - self.time).days <= 5:
self.set_holdings("OEF", 1)
The algorithm stays in cash during days out of the options expiration week.
def on_data(self, slice):
if self.time.date() == self.lastest_expiry.date():
self.liquidate()
Derek Melchin
See the attached backtest for an updated version of the algorithm in PEP8 style.
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.
Derek Melchin
See the attached backtest for an updated version of the algorithm in PEP8 style.
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.
Jing Wu
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!