def Process(self, context, task): if task.key == Message.SUGGEST_BUY_EVENT: context.AddTask( Task( Priority( Message.STAGE_BUY_TRADE, Message.PRIORITY_BUY), Message.BUY_EVENT, None, const.TASK_BROADCAST, *task.args))
def Process(self, context, task): if task.key == Message.SUGGEST_BUY_EVENT: #缓存 self.eventCache[context] = Task( Priority(Message.STAGE_BUY_TRADE, Message.PRIORITY_BUY), Message.BUY_EVENT, None, *task.args) # context.AddTask( # Task( # Priority( # Message.STAGE_BUY_TRADE, Message.PRIORITY_BUY), # Message.BUY_EVENT, None, *task.args)) elif task.key == Message.OTHER_WORK: if context.date in self.df.index: #计算月度终值 digest, detail = self.TM.CalcNowValue() self.df.loc[context.date, 'cash'] = self.totalMoney self.df.loc[context.date, 'marketValue'] = digest['marketValue'] self.df.loc[context.date, 'stockNumber'] = digest['stockNumber'] self.df.loc[context.date, 'total'] = self.totalMoney + digest['marketValue'] self.df.loc[context.date, 'profit'] = self.df.loc[context.date, 'total'] - self.TOTALMONEY self.df.loc[context.date, 'percent'] = self.df.loc[ context.date, 'profit'] / self.TOTALMONEY self.quarterDetail[context.date] = detail pass
def Process(self, context, task): if task.key == Message.SUGGEST_BUY_EVENT: # 缓存 self.eventCache[context] = Task( Priority(Message.STAGE_BUY_TRADE, Message.PRIORITY_BUY), Message.BUY_EVENT, None, const.TASK_BROADCAST, *task.args) elif task.key == Message.OTHER_WORK: #计算每天: digest, detail = self.TM.CalcNowValue() self.holdDetailEveryDay.append((context.date, detail)) if len(self.holdDetailEveryDay) > 5: self.holdDetailEveryDay = self.holdDetailEveryDay[-5:] if context.date in self.dfW.index: # 计算每周终值 # self.gather(context.date, self.dfW, self.maxAndRetracementW, False) if context.date not in self.gatherSetW: self.gatherSetW.add(context.date) self.gather(context.date, digest, detail, self.tmpGatherIndexW, self.tmpGatherDataW, self.maxAndRetracementW, False) if context.date in self.dfM.index: # 计算月度终值 # self.gather(context.date, self.dfM, self.maxAndRetracementM, True) if context.date not in self.gatherSetM: self.gatherSetM.add(context.date) self.gather(context.date, digest, detail, self.tmpGatherIndexM, self.tmpGatherDataM, self.maxAndRetracementM, True) elif task.key == Message.NEW_DAY: self.lastDate = context.date
def Process(self, context, task): if task.key == Message.SUGGEST_BUY_EVENT: # 缓存 self.eventCache[context] = Task( Priority( Message.STAGE_BUY_TRADE, Message.PRIORITY_BUY), Message.BUY_EVENT, None, const.TASK_BROADCAST, *task.args) elif task.key == Message.OTHER_WORK: if context.date in self.dfW.index: # 计算每周终值 self.gather(context.date, self.dfW, self.maxAndRetracementW, False) if context.date in self.dfM.index: # 计算月度终值 self.gather(context.date, self.dfM, self.maxAndRetracementM, True) elif task.key == Message.NEW_DAY: self.lastDate = context.date
def Process(self, context, task): if task.key == SUGGEST_BUY_EVENT: context.AddTask(Task(Priority(4, 2500), 5, None, *task.args))