def getNeedToUpdateDaysOfFactor(self, code, factor): self.setIPODate(code) listDate = self.listDate delistDate = self.delistDate today = datetime.datetime.now().strftime("%Y%m%d") yesterday = TradedayDataProcess.getPreviousTradeday(today) endDate = min(delistDate, yesterday) lastDate = self.getLastDate(code, factor) if lastDate != EMPTY_STRING: startDate = max(listDate, TradedayDataProcess.getNextTradeday(lastDate)) else: startDate = listDate return [startDate, endDate] pass
def getLastTradedayTickData(self, code, date): previousday = TradedayDataProcess.getPreviousTradeday(date, 250) days = list(TradedayDataProcess.getTradedays(previousday, date)) days.reverse() data = pd.DataFrame() for day in days: if day < date: #data=TickDataProcess().getDataByDateFromLocalFile(code,day) data = TickDataProcess().getTickShotDataFromInfluxdbServer( code, day) if data.shape[0] > 0: return data pass pass pass return data pass
def __computerFactor(self, code, startDate, endDate): #需要前推100天来获取计算得数据 startDate = TradedayDataProcess.getPreviousTradeday(startDate, 100) [listDate, delistDate] = super().setIPODate(code) startDate = max(startDate, listDate) dailyData = KLineDataProcess('daily') mydata = dailyData.getDataByDate(code, startDate, endDate) if mydata.shape[0] == 0: return pd.DataFrame() mydata['return'] = (mydata['close'] / mydata['preClose'] - 1) mydata.loc[mydata['status'] == '停牌', 'return'] = np.nan mydata.loc[mydata['date'] == listDate, 'return'] = np.nan mydata['yesterdayReturn'] = mydata['return'].shift(1) mydata['closeStd20'] = mydata['yesterdayReturn'].rolling( 20, min_periods=16).std() mydata['ts_closeStd20'] = mydata['closeStd20'].rolling( 50, min_periods=20).apply( (lambda x: pd.Series(x).rank().iloc[-1] / len(x)), raw=True) mycolumns = ['date', 'yesterdayReturn', 'closeStd20', 'ts_closeStd20'] mydata = mydata[mycolumns] return mydata