Hello,
I'm trying to get some code to run once a day that checks a bunch of pairs and then trades if certain conditions are met (I've presented the key parts to this below).
My issue is that when I run my code I get the output also shown below - as you can see it looks like it's being executed on the same day over and over. Any ideas where I could have gone so wrong?
6652 | 19:32:58:
2018-01-03 13:00:00
6653 | 19:32:58:
100 of 500
6654 | 19:32:58:
200 of 500
6655 | 19:32:58:
300 of 500
6656 | 19:32:58:
400 of 500
6657 | 19:32:58:
500 of 500
6658 | 19:32:58:
New Day
6659 | 19:32:58:
2018-01-03 13:00:00
6660 | 19:32:58:
100 of 500
6661 | 19:32:58:
200 of 500
6662 | 19:32:58:
300 of 500
6663 | 19:32:58:
400 of 500
6664 | 19:32:58:
500 of 500
6665 | 19:32:58:
New Day
6666 | 19:32:58:
2018-01-03 13:00:00
6667 | 19:32:58:
100 of 500
6668 | 19:32:58:
200 of 500
6669 | 19:32:58:
300 of 500
6670 | 19:32:58:
400 of 500
6671 | 19:32:58:
500 of 500
6672 | 19:32:58:
New Day
6673 | 19:32:58:
2018-01-03 13:00:00
6674 | 19:32:58:
100 of 500
6675 | 19:32:58:
200 of 500
6676 | 19:32:58:
300 of 500
6677 | 19:32:58:
400 of 500
6678 | 19:32:58:
500 of 500
6679 | 19:32:58:
New Day
6680 | 19:32:58:
2018-01-03 13:00:00
6681 | 19:32:58:
100 of 500
6682 | 19:32:58:
200 of 500
6683 | 19:32:58:
300 of 500
6684 | 19:32:58:
400 of 500
6685 | 19:32:58:
500 of 500
6686 | 19:32:58:
New Day
6687 | 19:32:58:
2018-01-03 13:00:00
6688 | 19:32:58:
100 of 500
6689 | 19:32:58:
200 of 500
6690 | 19:32:58:
300 of 500
6691 | 19:32:58:
400 of 500
6692 | 19:32:58:
500 of 500
class PairsTradingAlgorithm(QCAlgorithm):
def Initialize(self):
---some parameter stuff here not shown----
tickers = list(set(tickers))
self.symbols = []
for i in tickers:
self.symbols.append(self.AddEquity(i,Resolution.Daily).Symbol)
self.day_run = self.daily_run
self.SetStartDate(2018,1,1)
self.SetEndDate(2019,6,30)
self.lastSlice = None
self.pairs_list = pairs[0:500]
def OnData(self, data):
'''OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
Arguments:
data: Slice object keyed by symbol containing the stock data'''
self.lastSlice = data
scheduled_function = self.day_run
self.Schedule.On(self.DateRules.EveryDay(), self.TimeRules.At(13, 0), Action(scheduled_function))
def daily_run(self):
data = self.lastSlice
if data != None:
self.Debug('New Day')
self.Debug(str(self.Time))
run = 0
count = 0
for pair in self.pairs_list:
run += 1
count += 1
if count == 100:
self.Debug(str(run) + ' of ' + str(len(self.pairs_list)))
count = 0
if not (data.ContainsKey(pair[0]) and data.ContainsKey(pair[1])): return
### need to check this is the last 60 days
price_x = self.History([pair[0]], 60)['close'].values
price_y = self.History([pair[1]], 60)['close'].values
if len(price_x) < 60: return
------------Some trading logic ---------------