def _factor_convert2daily(self): tiaocang_date_list = self._tiaocang_date ret = pd.DataFrame() for i in range(0, len(tiaocang_date_list) - 1): date = bizDatesList(self._calendar.name, tiaocang_date_list[i], tiaocang_date_list[i + 1]) date = date if i == len(tiaocang_date_list) - 2 else date[:-1] nb_date = len(date) tiancang_factor = self._factor.loc[ self._factor.index. get_level_values('date') >= tiaocang_date_list[i], :] tiancang_factor = tiancang_factor.loc[ tiancang_factor.index. get_level_values('date') < tiaocang_date_list[i + 1], :] duplicate_date = np.concatenate( map(lambda x: np.tile(x, len(tiancang_factor)), date)) duplicate_sec_score = np.tile(tiancang_factor.values, nb_date) duplicate_sec_id = np.tile( tiancang_factor.index.get_level_values('asset'), nb_date) ret = pd.concat([ ret, pd.DataFrame({ 'date': duplicate_date, 'secID': duplicate_sec_id, 'factor': duplicate_sec_score }) ]) ret = ret.set_index(['date', 'secID']) ret = ret['factor'] return ret
def testBizDatesList(self): bizDtList = bizDatesList('China.SSE', self.fromDate, self.toDate) fromDate = Date.fromDateTime(self.fromDate) currentDate = fromDate.toDateTime() cal = Calendar('China.SSE') while currentDate <= self.toDate: finpyDate = Date.fromDateTime(currentDate) if cal.isBizDay(finpyDate): self.assertTrue(finpyDate.toDateTime() in bizDtList, "{0} is expected as a business day in {1}".format(finpyDate, cal)) currentDate = (finpyDate + 1).toDateTime()
def testIsBizDay(self): bizDates = bizDatesList('China.SSE', self.fromDate, self.toDate) for i, date in enumerate(bizDates): isBizFlag = isBizDay('China.SSE', date) self.assertTrue(isBizFlag, "at index {0:d} {1} is expected to be business day.".format(i, date)) holDates = holDatesList('China.SSE', self.fromDate, self.toDate) for i, date in enumerate(holDates): isBizFlag = isBizDay('China.SSE', date) self.assertTrue(isBizFlag is False, "at index {0:d} {1} is expected to be business day.".format(i, date))
def _get_sec_price_between_tiaocang_date(self, tiaocang_start_date, tiaocang_end_date): tiaocang_data = get_multi_index_data(self._secSelected, 'tiaoCangDate', tiaocang_start_date) sec_ids = tiaocang_data.index.get_level_values('secID').tolist() date = bizDatesList('China.SSE', tiaocang_start_date, tiaocang_end_date) if self._dataSource == DataSource.WIND: price_data = WindMarketDataHandler.get_sec_price_on_date(start_date=date[0], end_date=date[-1], sec_ids=sec_ids) else: raise NotImplementedError return price_data
def testBizDatesList(self): bizDtList = bizDatesList('China.SSE', self.fromDate, self.toDate) fromDate = Date.fromDateTime(self.fromDate) currentDate = fromDate.toDateTime() cal = Calendar('China.SSE') while currentDate <= self.toDate: finpyDate = Date.fromDateTime(currentDate) if cal.isBizDay(finpyDate): self.assertTrue(finpyDate.toDateTime() in bizDtList, "{0} is expected as a business day in {1}".format(finpyDate, cal)) currentDate = (finpyDate + 1).toDateTime()
def testIsBizDay(self): bizDates = bizDatesList('China.SSE', self.fromDate, self.toDate) for i, date in enumerate(bizDates): isBizFlag = isBizDay('China.SSE', date) self.assertTrue(isBizFlag, "at index {0:d} {1} is expected to be business day.".format(i, date)) holDates = holDatesList('China.SSE', self.fromDate, self.toDate) for i, date in enumerate(holDates): isBizFlag = isBizDay('China.SSE', date) self.assertTrue(isBizFlag is False, "at index {0:d} {1} is expected to be business day.".format(i, date))
def _get_sec_price_between_tiaocang_date(self, tiaocang_start_date, tiaocang_end_date): tiaocang_data = get_multi_index_data(self._sec_selected, 'tiaoCangDate', tiaocang_start_date) sec_ids = tiaocang_data.index.get_level_values('secID').tolist() date = bizDatesList('China.SSE', tiaocang_start_date, tiaocang_end_date) price_data = get_sec_price(start_date=date[0], end_date=date[-1], sec_ids=sec_ids, data_source=self._data_source, csv_path=self._csv_path) return price_data