Hi,
I would like to create exit strategy that executes 2 times a year, - at the start of a new year, and at the beginning of July.
How can i do this?
I would appreciate any help i can get.
QUANTCONNECT COMMUNITY
Hi,
I would like to create exit strategy that executes 2 times a year, - at the start of a new year, and at the beginning of July.
How can i do this?
I would appreciate any help i can get.
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.
VasilK
Hi!
I took it as a challange and came up with this code - hope it helps :)
How it works:
1. Each day we check if it's the specific date to trade:
2. Each day we call the 2nd function to execute the trade, and only when the boolean value is True, we actually execute the trade. Once we executed the trade, we reset the boolean to False and wait for the next cycle.
Here is a log from the code I developed, tesdting for the last few years:
2015-01-02 10:00:00 :Execute trade at Date: Friday 02. January 2015
2015-07-01 10:00:00 :Execute trade at Date: Wednesday 01. July 2015
2016-01-04 10:00:00 :Execute trade at Date: Monday 04. January 2016
2016-07-01 10:00:00 :Execute trade at Date: Friday 01. July 2016
2017-01-03 10:00:00 :Execute trade at Date: Tuesday 03. January 2017
2017-07-03 10:00:00 :Execute trade at Date: Monday 03. July 2017
2018-01-02 10:00:00 :Execute trade at Date: Tuesday 02. January 2018
2018-07-02 10:00:00 :Execute trade at Date: Monday 02. July 2018
2019-01-02 10:00:00 :Execute trade at Date: Wednesday 02. January 2019
2019-07-01 10:00:00 :Execute trade at Date: Monday 01. July 2019
2020-01-02 10:00:00 :Execute trade at Date: Thursday 02. January 2020
2020-07-01 10:00:00 :Execute trade at Date: Wednesday 01. July 2020
2021-01-04 10:00:00 :Execute trade at Date: Monday 04. January 2021
Samwel Kibet
Hey, Thanks for the help. Appreciate it!
Vladimir
Samwel Kibet,
You can executes strategy 2 times a year simply by using
self.Schedule.On(self.DateRules.MonthStart ('SPY')
and specifying MONTHES = [1, 7] which you want to trade.
2015-01-02 12:00:00 : Execute trade at Date: Friday 02. January 2015
2015-07-01 12:00:00 : Execute trade at Date: Wednesday 01. July 2015
2016-01-04 12:00:00 : Execute trade at Date: Monday 04. January 2016
2016-07-01 12:00:00 : Execute trade at Date: Friday 01. July 2016
2017-01-03 12:00:00 : Execute trade at Date: Tuesday 03. January 2017
2017-07-03 12:00:00 : Execute trade at Date: Monday 03. July 2017
2018-01-02 12:00:00 : Execute trade at Date: Tuesday 02. January 2018
2018-07-02 12:00:00 : Execute trade at Date: Monday 02. July 2018
2019-01-02 12:00:00 : Execute trade at Date: Wednesday 02. January 2019
2019-07-01 12:00:00 : Execute trade at Date: Monday 01. July 2019
2020-01-02 12:00:00 : Execute trade at Date: Thursday 02. January 2020
2020-07-01 12:00:00 : Execute trade at Date: Wednesday 01. July 2020
2021-01-04 12:00:00 : Execute trade at Date: Monday 04. January 2021
VasilK
Much more elegant solution Vladimir - thanks for sharing! :)
Samwel Kibet
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!