def on_SelectDTButton_clicked(self): if self.Times: DTs = set(DateTimeFun.combineDateTime(self.Dates, self.Times)) else: DTs = set(DateTimeFun.combineDateTime(self.Dates, [dt.time(0)])) self.DateTimes = sorted( mergeSet(DTs, set(self.DateTimes), merge_type=self.DTSelectTypeComboBox.currentText())) return self.populateDateTimeListWidget(self.DateTimes)
def getAccountValueDateSeries(self, start_date=None, end_date=None): Dates = DateTimeFun.cutDate(self.QSEnv.STM.DateSeries, start_date, end_date) EndIndex = self.QSEnv.STM.getDateEndIndex(Dates) Rslt = self.getAccountValueSeries() Rslt = Rslt.iloc[EndIndex] Rslt.index = Dates return Rslt
def getPositionAmountDateSeries(self, start_date=None, end_date=None): Dates = DateTimeFun.cutDate(self.QSEnv.STM.DateSeries, start_date, end_date) EndIndex = self.QSEnv.STM.getDateEndIndex(Dates) Rslt = pd.DataFrame(self._PositionAmount[1:]) Rslt = Rslt.iloc[EndIndex] Rslt.index = Dates return Rslt
def on_SelectTimeButton_clicked(self): Times = [] TimeDelta = self.TimePeriodEdit.time().toPyTime() TimeDelta = dt.timedelta(hours=TimeDelta.hour, minutes=TimeDelta.minute, seconds=TimeDelta.second) AMStartTime, AMEndTime = self.AMStartTimeEdit.time().toPyTime( ), self.AMEndTimeEdit.time().toPyTime() if AMStartTime <= AMEndTime: Times += DateTimeFun.getTimeSeries(AMStartTime, AMEndTime, timedelta=TimeDelta) PMStartTime, PMEndTime = self.PMStartTimeEdit.time().toPyTime( ), self.PMEndTimeEdit.time().toPyTime() if PMStartTime <= PMEndTime: Times += DateTimeFun.getTimeSeries(PMStartTime, PMEndTime, timedelta=TimeDelta) self.Times = sorted( mergeSet(set(Times), set(self.Times), merge_type=self.TimeSelectTypeComboBox.currentText())) return self.populateTimeListWidget(self.Times)
def on_SelectDateButton_clicked(self): StartDate, EndDate = self.StartDateEdit.date().toPyDate( ), self.EndDateEdit.date().toPyDate() if StartDate > EndDate: Dates = [] else: DateType = self.DateTypeComboBox.currentText() if DateType == "自然日": Dates = DateTimeFun.getDateSeries(StartDate, EndDate) elif DateType == "交易日": try: Dates = self.FDB.getTradeDay( StartDate, EndDate, exchange=self.ExchangeEdit.text()) except Exception as e: return QMessageBox.critical(self, "错误", str(e)) Dates = self.changeDateTime(Dates, self.DatePeriodComboBox.currentText()) self.Dates = sorted( mergeSet(set(Dates), set(self.Dates), merge_type=self.DateSelectTypeComboBox.currentText())) return self.populateDateListWidget(self.Dates)
def changeDateTime(self, dts, dt_period): if callable(dt_period): return dt_period(dts) elif dt_period == "月末日": return DateTimeFun.getMonthLastDateTime(dts) elif dt_period == "周末日": return DateTimeFun.getWeekLastDateTime(dts) elif dt_period == "年末日": return DateTimeFun.getYearLastDateTime(dts) elif dt_period == "季末日": return DateTimeFun.getQuarterLastDateTime(dts) elif dt_period == "月初日": return DateTimeFun.getMonthFirstDateTime(dts) elif dt_period == "周初日": return DateTimeFun.getWeekFirstDateTime(dts) elif dt_period == "年初日": return DateTimeFun.getYearFirstDateTime(dts) elif dt_period == "季初日": return DateTimeFun.getQuarterFirstDateTime(dts) elif dt_period == "财报季初日": return DateTimeFun.getFinancialQuarterFirstDateTime(dts) elif dt_period == "财报季末日": return DateTimeFun.getFinancialQuarterLastDateTime(dts) elif dt_period == "月中日": Middle, isOK = QInputDialog.getInt(self, "月中日", "月中分界日: ", value=15, min=1, max=31, step=1) if isOK: return DateTimeFun.getMonthMiddleDateTime(dts, middle_day=Middle) return dts