1 Star 0 Fork 1

光之影 / awesome-systematic-trading

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
turn-of-the-month-in-equity-indexes.py 1.12 KB
一键复制 编辑 原始数据 按行查看 历史
edarchimbaud 提交于 2022-10-22 22:05 . feat: new strategies
# https://quantpedia.com/strategies/turn-of-the-month-in-equity-indexes/
#
# Buy SPY ETF 1 day (some papers say 4 days) before the end of the month and sell the 3rd trading day of the new month at the close.
from AlgorithmImports import *
class TurnoftheMonthinEquityIndexes(QCAlgorithm):
def Initialize(self):
self.SetStartDate(1998, 1, 1)
self.SetCash(100000)
self.symbol = self.AddEquity("SPY", Resolution.Daily).Symbol
self.sell_flag = False
self.days = 0
self.Schedule.On(self.DateRules.MonthStart(self.symbol), self.TimeRules.AfterMarketOpen(self.symbol), self.Rebalance)
self.Schedule.On(self.DateRules.MonthEnd(self.symbol), self.TimeRules.AfterMarketOpen(self.symbol), self.Purchase)
def Purchase(self):
self.SetHoldings(self.symbol, 1)
def Rebalance(self):
self.sell_flag = True
def OnData(self, data):
if self.sell_flag:
self.days += 1
if self.days == 3:
self.Liquidate(self.symbol)
self.sell_flag = False
self.days = 0
Python
1
https://gitee.com/shadow-of-light/awesome-systematic-trading.git
git@gitee.com:shadow-of-light/awesome-systematic-trading.git
shadow-of-light
awesome-systematic-trading
awesome-systematic-trading
main

搜索帮助