def run_standard_deviation(self): fund_code = self.get_fund_code() # fund_code = fund_code[0: 100] run_cnt = 0 fd_num = len(fund_code) logging.info('funds number: {}'.format(fd_num)) for code in fund_code: run_cnt += 1 logging.info('code: {} pct: {} / {}'.format(code, run_cnt, fd_num)) for date_list in self.run_date_list: report_date = date_list[0] start_date = self.find_fund_clr(code) if start_date > report_date: continue try: std_value = standard_deviation(code, start_date, report_date) logging.debug('start_date: {} end_date: {}'.format(start_date, report_date)) logging.debug('code {} year_lag {} std_value {}'.format(code, "", std_value)) except Exception as err: logging.warning(err) std_value = None rec = (code, 'StandardDeviationAll', str(std_value), None, self.algid, report_date, self.thisfilename, self.todaydate) # print(rec) self.db_insert_session.add_info(rec) self.db_insert_session.finish()
def run_standard_deviation(self): fund_code = self.get_fund_code() # fund_code = fund_code[0: 100] rec = [] run_cnt = 0 fd_num = len(fund_code) logging.info('funds number: {}'.format(fd_num)) for code in fund_code: run_cnt += 1 logging.info('code: {} pct: {} / {}'.format(code, run_cnt, fd_num)) for date_list in self.run_date_list: report_date = date_list[0] for year_lag in range(1, 4): tmp_date = date_list[4 - year_lag] start_date = pd.date_range(start=tmp_date, periods=2, freq='D').strftime('%Y%m%d').tolist()[-1] try: std_value = standard_deviation(code, start_date, report_date) logging.debug('start_date: {} end_date: {}'.format(start_date, report_date)) logging.debug('code {} year_lag {} std_value {}'.format(code, year_lag, std_value)) except Exception as err: logging.warning(err) std_value = None rec.append((code, 'StandardDeviation%dYear' % (year_lag), str(std_value), None, self.algid, report_date, self.thisfilename, self.todaydate)) if len(rec) > 500: # self.db_insert_session.DBInsert(sql_index_insert, rec) rec = [] # self.db_insert_session.DBInsert(sql_index_insert, rec) return
def compute_std(code, start_date, end_date): ''' 计算基金周波动年化 ''' try: std = standard_deviation(code, start_date, end_date) except Exception as err: print(err) logging.debug(err) std = None logging.info('\t std: {}'.format(std)) return std
def test_standard_deviation(): # 测试普通接口 print(start) code, start, end = '163807', '20170101', '20171231' for i in range(10): res = standard_deviation(code, start, end) print('res: {}'.format(res)) """ code, start, end = '163807', '20170101', '20180110' res = standard_deviation(code, start, end) print('res: {}'.format(res)) code, start, end = '163807', '20180101', '20181231' res = standard_deviation(code, start, end) print('res: {}'.format(res)) code, start, end = '163807', '20170101', '20181231' res = standard_deviation(code, start, end) print('res: {}'.format(res)) code, start, end = '163807', '20160101', '20181231' res = standard_deviation(code, start, end) print('res: {}'.format(res)) code, start, end = '005757', '20180101', '20181231' res = standard_deviation(code, start, end) print('res: {}'.format(res)) # 测试返回为nah # 净值数据缺失,周发布 code, start, end = '004940', '20170630', '20180630' res = standard_deviation(code, start, end) print('res: {}'.format(res)) """ """