Hi.
is there a way to get the number of business days till options expiration?
need to take into consideration holidays and weekends
thanks
Don't have an account? Join QuantConnect Today
QuantConnect Community Discussions
QUANTCONNECT COMMUNITY
LEAN is the open-source algorithmic trading engine powering QuantConnect. Founded in 2012 LEAN has been built by a global community of 180+ engineers and powers more than 300+ hedge funds today.
Join QuantConnect's Discord server for real-time support, where a vibrant community of traders and developers awaits to help you with any of your QuantConnect needs.
The Open-Quant League is a quarterly competition between universities and investment clubs for the best-performing strategy. The previous quarter's code is open-sourced, and competitors must adapt to survive.
Query for business days till options expiration, accounting for holidays and weekends.
Continue ReadingRefer to our Research Guidelines for high quality research posts.
Create an account on QuantConnect for the latest community delivered to your inbox.
Sign Up Today
|
|
|||||||
|
|
||||||||
|
Business days till expiration
Gil Sapir | September 2019
Hi.
is there a way to get the number of business days till options expiration?
need to take into consideration holidays and weekends
thanks
QuantConnect™ 2025. All Rights Reserved
Jared Broad
Yes, you can use `Time.TradableDates` function which takes a security object and the start and end DateTime objects.
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.
Gil Sapir
I'm not sure this method is enabled in python, I'm trying:
sec = self.Securities['SPY']
t = Time.TradeableDates( sec ,self.Time, self.Time+timedelta(6) )
and getting this error :
Runtime Error: Trying to dynamically access a method that does not exist throws a TypeError exception. To prevent the exception, ensure each parameter type matches those required by the TradeableDates method. Please checkout the API documentation.
at OnData in main.py:line 75
TypeError : No method matches given arguments for TradeableDates
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.
Alethea Lin
Hi Gil,
You are right that this method is not supported in Python. Please use the following code:
# Method 1 days = list(Time.EachTradeableDay(self.Securities["SPY"], self.Time, self.Time + timedelta(6))) self.Log(f'Tradeable Dates 1: {len(days)}') # Method 2 days = list(self.TradingCalendar.GetDaysByType(TradingDayType.BusinessDay, self.Time, self.Time + timedelta(6))) self.Log(f'Tradeable Dates 2: {len(days)}')
You can also read more about TradingCalendar here. Hope this helps!
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.
AM H
Ah, just what I was looking for. How would I add this to a close/liquidate options function X days beforfe the contract expiry, checkin geach day on the next contract etc.
Example:
BUY SPY 14 expiry contract every day, and each day SELL the one that is 7 days from expiration.
Would need to wait for the first cycle of 7 days to pass and then every day a contract is being bought and another sold.
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.
AM H
Here is my liquidate code:
def close_options(self): self.Log("Close options every day") # liquidate options for x in self.Portfolio: if x.Value.Invested: self.Liquidate(x.Key)
And building with your code:
def close_options(self): self.Log("Close options every day") # liquidate options for x in self.Portfolio: x = list(Time.EachTradeableDay(self.Securities["SPY"], self.Time, self.Time + timedelta(6))) self.Log(f'Tradeable Dates 1: {len(x)}'): if x.Value.Invested: self.Liquidate(x.Key)
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.
Shile Wen
Hi AM H,
One way to get the days until expiration would be to access an option’s expiry date, and compute the timedelta between the expiry date and self.Time. Alternatively, if we wanted to exclude non trading days, we can use the method mentioned by Athelea. I’ve shown how to do both in the attached backtest.
Best,
Shile Wen
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!