def __init__(self): # ,, items_page=200): time_frame=180): wx = lg.get_handle() # 建立数据库对象 self.db = db_ops() # 读取数据表名 self.h_conf = conf_handler(conf="rt_analyer.conf") # 大单 金额下限 self.rt_big_amount = float(self.h_conf.rd_opt('rt_analysis_rules', 'big_deal_amount')) # 量价向量 的取样resample的时间段 self.rt_PA_resample_secs = self.h_conf.rd_opt('general', 'PA_resample_secs') # 量价向量 取样聚合的 agg 的时间段 self.rt_PA_resample_agg_secs = int(self.h_conf.rd_opt('general', 'PA_resample_agg_secs')) # 去除极值的常量 self.mid_constant = float(self.h_conf.rd_opt('general', 'mid_constant')) self.cq_tname_00 = self.h_conf.rd_opt('db', 'daily_table_cq_00') self.cq_tname_30 = self.h_conf.rd_opt('db', 'daily_table_cq_30') self.cq_tname_60 = self.h_conf.rd_opt('db', 'daily_table_cq_60') self.cq_tname_002 = self.h_conf.rd_opt('db', 'daily_table_cq_002') self.cq_tname_68 = self.h_conf.rd_opt('db', 'daily_table_cq_68')
def __init__(self): wx = lg.get_handle() wx.info("[OBJ] ws_rp __init__ called") try: self.db = db_ops(host='127.0.0.1', db='stock', user='******', pwd='5171013') except Exception as e: raise e
def __init__(self, id_arr=None, keywords_arr=None): if id_arr is not None: self.id_arr=id_arr if keywords_arr is not None: self.keywords_arr = keywords_arr # 建立数据库对象 self.db = db_ops()
def __init__(self): # period is the length of days in which we look at how many days witness price increase self.h_conf = conf_handler(conf="stock_analyer.conf") self.period = int(self.h_conf.rd_opt('psy', 'period')) self.tname_00 = self.h_conf.rd_opt('db', 'daily_table_cq_00') self.tname_30 = self.h_conf.rd_opt('db', 'daily_table_cq_30') self.tname_60 = self.h_conf.rd_opt('db', 'daily_table_cq_60') self.tname_002 = self.h_conf.rd_opt('db', 'daily_table_cq_002') host = self.h_conf.rd_opt('db', 'host') database = self.h_conf.rd_opt('db', 'database') user = self.h_conf.rd_opt('db', 'user') pwd = self.h_conf.rd_opt('db', 'pwd') self.db = db_ops(host=host, db=database, user=user, pwd=pwd)
def __init__(self): wx = lg.get_handle() # log_dir = os.path.abspath('.') # self.logger = myLogger(log_dir) try: self.h_conf = conf_handler(conf="stock_analyer.conf") host = self.h_conf.rd_opt('db', 'host') database = self.h_conf.rd_opt('db', 'database') user = self.h_conf.rd_opt('db', 'user') pwd = self.h_conf.rd_opt('db', 'pwd') self.db = db_ops(host=host, db=database, user=user, pwd=pwd) # self.db = db_ops(host='127.0.0.1', db='stock', user='******', pwd='5171013') self.dd_cq_00 = self.h_conf.rd_opt('db', 'daily_table_cq_00') self.dd_cq_30 = self.h_conf.rd_opt('db', 'daily_table_cq_30') self.dd_cq_60 = self.h_conf.rd_opt('db', 'daily_table_cq_60') self.dd_cq_002 = self.h_conf.rd_opt('db', 'daily_table_cq_002') self.dd_cq_68 = self.h_conf.rd_opt('db', 'daily_table_cq_68') self.dd_qfq_00 = self.h_conf.rd_opt('db', 'daily_table_qfq_00') self.dd_qfq_30 = self.h_conf.rd_opt('db', 'daily_table_qfq_30') self.dd_qfq_60 = self.h_conf.rd_opt('db', 'daily_table_qfq_60') self.dd_qfq_002 = self.h_conf.rd_opt('db', 'daily_table_qfq_002') self.dd_qfq_68 = self.h_conf.rd_opt('db', 'daily_table_qfq_68') self.bt_dd_qfq_00 = self.h_conf.rd_opt('db', 'bt_daily_table_qfq_00') self.bt_dd_qfq_30 = self.h_conf.rd_opt('db', 'bt_daily_table_qfq_30') self.bt_dd_qfq_60 = self.h_conf.rd_opt('db', 'bt_daily_table_qfq_60') self.bt_dd_qfq_002 = self.h_conf.rd_opt('db', 'bt_daily_table_qfq_002') self.bt_dd_qfq_68 = self.h_conf.rd_opt('db', 'bt_daily_table_qfq_68') self.dd_hot_industry = self.h_conf.rd_opt('db', 'dd_hot_industry') self.fin_report = self.h_conf.rd_opt('db', 'fin_report') self.dgj_table = self.h_conf.rd_opt('db', 'dgj_table') self.dd_zhiya = self.h_conf.rd_opt('db', 'dd_zhiya') except Exception as e: raise e
def __init__(self): try: wx = lg.get_handle() self.h_conf = conf_handler(conf="stock_analyer.conf") host = self.h_conf.rd_opt('db', 'host') database = self.h_conf.rd_opt('db', 'database') user = self.h_conf.rd_opt('db', 'user') pwd = self.h_conf.rd_opt('db', 'pwd') self.db = db_ops(host=host, db=database, user=user, pwd=pwd) self.dd_hot_industry = self.h_conf.rd_opt('db', 'dd_hot_industry') # wx.info("[OBJ] analyzer __init__() called") self.dd_cq_00 = self.h_conf.rd_opt('db', 'daily_table_cq_00') self.dd_cq_30 = self.h_conf.rd_opt('db', 'daily_table_cq_30') self.dd_cq_60 = self.h_conf.rd_opt('db', 'daily_table_cq_60') self.dd_cq_002 = self.h_conf.rd_opt('db', 'daily_table_cq_002') self.dd_cq_68 = self.h_conf.rd_opt('db', 'daily_table_cq_68') except Exception as e: raise e
def __init__(self): h_conf = conf_handler(conf="rt_analyer.conf") ana_time_slice = h_conf.rd_opt('rt_analysis_rules', 'ana_time_slice') self.ana_time_slice_arr = ana_time_slice.split(',') self.rt_big_amount = float( h_conf.rd_opt('rt_analysis_rules', 'big_deal_amount')) self.msg = f_msg() # 量价向量 的取样resample的时间段 self.rt_PA_resample_secs = h_conf.rd_opt('general', 'PA_resample_secs') # 建立数据库对象 self.db = db_ops() self.rt_data_keeper_1 = pd.DataFrame() # 保存 大单记录,作为基线数据 # key:array 时间段开始时间:[时间段结束时间, 下一时间段开始时间] self.t_frame_dict = { '09:25': ['09:30', '09:30'], '09:30': ['09:40', '09:40'], '09:40': ['09:50', '09:50'], '09:50': ['10:00', '10:00'], '10:00': ['10:30', '10:30'], '10:30': ['11:00', '11:00'], '11:00': ['11:30', '13:00'], '13:00': ['13:30', '13:30'], '13:30': ['14:00', '14:00'], '14:00': ['14:30', '14:30'], '14:30': ['14:40', '14:40'], '14:40': ['14:50', '14:50'], '14:50': ['15:00', ''] } date_str = (date.today()).strftime('%Y%m%d') self.record_stamp_dict = {} # 用 self.t_frame_dict 的key (时间段的起始时间点)建立 record_stamp_dict 字典 for time_str in self.t_frame_dict.keys(): stamp = int( time.mktime(time.strptime(date_str + time_str, '%Y%m%d%H:%M'))) self.record_stamp_dict[stamp] = time_str
def __init__(self): # wx = lg.get_handle() self.h_conf = conf_handler(conf="stock_analyer.conf") ma_str = self.h_conf.rd_opt('ma', 'duration') self.ma_duration = ma_str.split(",") ema_str = self.h_conf.rd_opt('ema', 'duration') self.ema_duration = ema_str.split(",") # wx.info("ma_duration {}".format(self.ma_duration)) self.bolling = self.h_conf.rd_opt('bolling', 'duration') self.cq_tname_00 = self.h_conf.rd_opt('db', 'daily_table_cq_00') self.cq_tname_30 = self.h_conf.rd_opt('db', 'daily_table_cq_30') self.cq_tname_60 = self.h_conf.rd_opt('db', 'daily_table_cq_60') self.cq_tname_002 = self.h_conf.rd_opt('db', 'daily_table_cq_002') self.cq_tname_68 = self.h_conf.rd_opt('db', 'daily_table_cq_68') self.qfq_tname_00 = self.h_conf.rd_opt('db', 'daily_table_qfq_00') self.qfq_tname_30 = self.h_conf.rd_opt('db', 'daily_table_qfq_30') self.qfq_tname_60 = self.h_conf.rd_opt('db', 'daily_table_qfq_60') self.qfq_tname_002 = self.h_conf.rd_opt('db', 'daily_table_qfq_002') self.qfq_tname_68 = self.h_conf.rd_opt('db', 'daily_table_qfq_68') self.bt_qfq_tname_00 = self.h_conf.rd_opt('db', 'bt_daily_table_qfq_00') self.bt_qfq_tname_30 = self.h_conf.rd_opt('db', 'bt_daily_table_qfq_30') self.bt_qfq_tname_60 = self.h_conf.rd_opt('db', 'bt_daily_table_qfq_60') self.bt_qfq_tname_002 = self.h_conf.rd_opt('db', 'bt_daily_table_qfq_002') self.bt_qfq_tname_68 = self.h_conf.rd_opt('db', 'bt_daily_table_qfq_68') host = self.h_conf.rd_opt('db', 'host') database = self.h_conf.rd_opt('db', 'database') user = self.h_conf.rd_opt('db', 'user') pwd = self.h_conf.rd_opt('db', 'pwd') self.db = db_ops(host=host, db=database, user=user, pwd=pwd)
def __init__(self, f_date='', f_days=-240): wx = lg.get_handle() try: if f_days >= 0 and f_date != '': self.f_begin_date = f_date f_begin_date = datetime.strptime(self.f_begin_date, "%Y%m%d") self.f_end_date = (f_begin_date + timedelta(days=f_days)).strftime('%Y%m%d') elif f_date != '': self.f_end_date = f_date f_end_date = datetime.strptime(self.f_end_date, "%Y%m%d") self.f_begin_date = (f_end_date + timedelta(days=f_days)).strftime('%Y%m%d') else: wx.info("[back_trader] __init__ Failed, f_date is Empty") raise RuntimeError( '[back_trader] __init__ Failed, trade_date is Empty') self.h_conf = conf_handler(conf="stock_analyer.conf") self.daily_cq_t_00 = self.h_conf.rd_opt('db', 'daily_table_cq_00') self.daily_cq_t_30 = self.h_conf.rd_opt('db', 'daily_table_cq_30') self.daily_cq_t_60 = self.h_conf.rd_opt('db', 'daily_table_cq_60') self.daily_cq_t_68 = self.h_conf.rd_opt('db', 'daily_table_cq_68') self.daily_cq_t_002 = self.h_conf.rd_opt('db', 'daily_table_cq_002') self.bt_daily_qfq_t_00 = self.h_conf.rd_opt( 'db', 'bt_daily_table_qfq_00') self.bt_daily_qfq_t_30 = self.h_conf.rd_opt( 'db', 'bt_daily_table_qfq_30') self.bt_daily_qfq_t_60 = self.h_conf.rd_opt( 'db', 'bt_daily_table_qfq_60') self.bt_daily_qfq_t_68 = self.h_conf.rd_opt( 'db', 'bt_daily_table_qfq_68') self.bt_daily_qfq_t_002 = self.h_conf.rd_opt( 'db', 'bt_daily_table_qfq_002') self.ma_bt_qfq_table_60 = self.h_conf.rd_opt( 'db', 'ma_bt_qfq_table_60') self.ma_bt_qfq_table_30 = self.h_conf.rd_opt( 'db', 'ma_bt_qfq_table_30') self.ma_bt_qfq_table_00 = self.h_conf.rd_opt( 'db', 'ma_bt_qfq_table_00') self.ma_bt_qfq_table_002 = self.h_conf.rd_opt( 'db', 'ma_bt_qfq_table_002') self.ma_bt_qfq_table_68 = self.h_conf.rd_opt( 'db', 'ma_bt_qfq_table_68') host = self.h_conf.rd_opt('db', 'host') database = self.h_conf.rd_opt('db', 'database') user = self.h_conf.rd_opt('db', 'user') pwd = self.h_conf.rd_opt('db', 'pwd') self.db = db_ops(host=host, db=database, user=user, pwd=pwd) self.ts = ts_data() self.web_data = ex_web_data() self._set_bt_period() except Exception as e: raise e
def __init__(self, f_conf='', f_start_date='', f_end_date='', data_src='qfq', industry_name=''): wx = lg.get_handle() if industry_name == '': wx.info("[filter industry] 初始化:行业名称不能为空,退出") return None else: self.industry_name = industry_name try: self.f_conf = conf_handler(conf=f_conf) self.h_conf = conf_handler(conf="stock_analyer.conf") # self.pe = self.f_conf.rd_opt('filter_fix', 'pe') # self.total_amount = self.f_conf.rd_opt('filter_fix', 'total_amount') # self.high_price = self.f_conf.rd_opt('filter_fix', 'high_price') # self.days = self.f_conf.rd_opt('filter_fix', 'below_ma55_days') self.dgj_table = self.h_conf.rd_opt('db', 'dgj_table') self.ws_table = self.h_conf.rd_opt('db', 'ws_table') self.repo_table = self.h_conf.rd_opt('db', 'repo_table') self.daily_cq_t_00 = self.h_conf.rd_opt('db', 'daily_table_cq_00') self.daily_cq_t_30 = self.h_conf.rd_opt('db', 'daily_table_cq_30') self.daily_cq_t_60 = self.h_conf.rd_opt('db', 'daily_table_cq_60') self.daily_cq_t_68 = self.h_conf.rd_opt('db', 'daily_table_cq_68') self.daily_cq_t_002 = self.h_conf.rd_opt('db', 'daily_table_cq_002') self.daily_qfq_t_00 = self.h_conf.rd_opt('db', 'daily_table_qfq_00') self.daily_qfq_t_30 = self.h_conf.rd_opt('db', 'daily_table_qfq_30') self.daily_qfq_t_60 = self.h_conf.rd_opt('db', 'daily_table_qfq_60') self.daily_qfq_t_68 = self.h_conf.rd_opt('db', 'daily_table_qfq_68') self.daily_qfq_t_002 = self.h_conf.rd_opt('db', 'daily_table_qfq_002') self.bt_daily_qfq_t_00 = self.h_conf.rd_opt( 'db', 'bt_daily_table_qfq_00') self.bt_daily_qfq_t_30 = self.h_conf.rd_opt( 'db', 'bt_daily_table_qfq_30') self.bt_daily_qfq_t_60 = self.h_conf.rd_opt( 'db', 'bt_daily_table_qfq_60') self.bt_daily_qfq_t_68 = self.h_conf.rd_opt( 'db', 'bt_daily_table_qfq_68') self.bt_daily_qfq_t_002 = self.h_conf.rd_opt( 'db', 'bt_daily_table_qfq_002') self.ma_cq_table_60 = self.h_conf.rd_opt('db', 'ma_cq_table_60') self.ma_cq_table_30 = self.h_conf.rd_opt('db', 'ma_cq_table_30') self.ma_cq_table_00 = self.h_conf.rd_opt('db', 'ma_cq_table_00') self.ma_cq_table_002 = self.h_conf.rd_opt('db', 'ma_cq_table_002') self.ma_cq_table_68 = self.h_conf.rd_opt('db', 'ma_cq_table_68') self.ma_qfq_table_60 = self.h_conf.rd_opt('db', 'ma_qfq_table_60') self.ma_qfq_table_30 = self.h_conf.rd_opt('db', 'ma_qfq_table_30') self.ma_qfq_table_00 = self.h_conf.rd_opt('db', 'ma_qfq_table_00') self.ma_qfq_table_002 = self.h_conf.rd_opt('db', 'ma_qfq_table_002') self.ma_qfq_table_68 = self.h_conf.rd_opt('db', 'ma_qfq_table_68') self.ma_bt_qfq_table_00 = self.h_conf.rd_opt( 'db', 'ma_bt_qfq_table_00') self.ma_bt_qfq_table_30 = self.h_conf.rd_opt( 'db', 'ma_bt_qfq_table_30') self.ma_bt_qfq_table_60 = self.h_conf.rd_opt( 'db', 'ma_bt_qfq_table_30') self.ma_bt_qfq_table_68 = self.h_conf.rd_opt( 'db', 'ma_bt_qfq_table_30') self.ma_bt_qfq_table_002 = self.h_conf.rd_opt( 'db', 'ma_bt_qfq_table_30') self.fin_table = self.h_conf.rd_opt('db', 'fin_report') host = self.h_conf.rd_opt('db', 'host') database = self.h_conf.rd_opt('db', 'database') user = self.h_conf.rd_opt('db', 'user') pwd = self.h_conf.rd_opt('db', 'pwd') self.db = db_ops(host=host, db=database, user=user, pwd=pwd) wx.info("[OBJ] filter_fix : __init__ called") # 指定日期,用于回测,默认日期是当前最近交易日 if data_src == 'cq' or data_src == 'qfq': sql = "SELECT date from " + self.daily_cq_t_00 + " order by date desc limit 1" df_date = self.db._exec_sql(sql=sql) self.f_end_date = df_date.iloc[0, 0] self.f_start_date = (date.today() + timedelta(days=-240)).strftime('%Y%m%d') elif data_src == 'bt_qfq': if f_end_date == '' or f_start_date == '': wx.info("[Filter_fix]回测未设置起止日期区间[{}-{}]".format( f_start_date, f_end_date)) return self.f_end_date = f_end_date self.f_start_date = f_start_date # 选出该行业的所有股票 sql = "select la.id, la.name, la.sw_level_1, la.sw_level_2 " \ "from list_a as la, sw_industry_code as sw where sw.industry_name =\"%s\" and" \ " (sw.industry_code = la.sw_level_1 or sw.industry_code = la.sw_level_2)"%(self.industry_name) self.df_industry_id = self.db._exec_sql(sql=sql) self.industry_id_arr = self.df_industry_id.id.tolist() self.data_src = data_src except Exception as e: raise e
def __init__(self, f_conf='', f_start_date='', f_end_date='', data_src='qfq'): wx = lg.get_handle() try: self.f_conf = conf_handler(conf=f_conf) self.h_conf = conf_handler(conf="stock_analyer.conf") self.pe = self.f_conf.rd_opt('filter_fix', 'pe') self.total_amount = self.f_conf.rd_opt('filter_fix', 'total_amount') self.high_price = self.f_conf.rd_opt('filter_fix', 'high_price') self.days = self.f_conf.rd_opt('filter_fix', 'below_ma55_days') # self.filter_growth_below_pct = self.f_conf.rd_opt('filter_fix', 'filter_growth_below_pct') # self.filter_high_left_power_request = self.f_conf.rd_opt('filter_fix', 'filter_high_left_power_request') # self.filter_high_right_power_request = self.f_conf.rd_opt('filter_fix', 'filter_high_right_power_request') # self.filter_cur_left_power_request = self.f_conf.rd_opt('filter_fix', 'filter_cur_left_power_request') # self.filter_golden_pct = self.f_conf.rd_opt('filter_fix', 'filter_golden_pct') # self.filter_golden_pct_request = float(self.f_conf.rd_opt('filter_fix', 'filter_golden_pct_request')) self.daily_cq_t_00 = self.h_conf.rd_opt('db', 'daily_table_cq_00') self.daily_cq_t_30 = self.h_conf.rd_opt('db', 'daily_table_cq_30') self.daily_cq_t_60 = self.h_conf.rd_opt('db', 'daily_table_cq_60') self.daily_cq_t_68 = self.h_conf.rd_opt('db', 'daily_table_cq_68') self.daily_cq_t_002 = self.h_conf.rd_opt('db', 'daily_table_cq_002') self.daily_qfq_t_00 = self.h_conf.rd_opt('db', 'daily_table_qfq_00') self.daily_qfq_t_30 = self.h_conf.rd_opt('db', 'daily_table_qfq_30') self.daily_qfq_t_60 = self.h_conf.rd_opt('db', 'daily_table_qfq_60') self.daily_qfq_t_68 = self.h_conf.rd_opt('db', 'daily_table_qfq_68') self.daily_qfq_t_002 = self.h_conf.rd_opt('db', 'daily_table_qfq_002') self.bt_daily_qfq_t_00 = self.h_conf.rd_opt( 'db', 'bt_daily_table_qfq_00') self.bt_daily_qfq_t_30 = self.h_conf.rd_opt( 'db', 'bt_daily_table_qfq_30') self.bt_daily_qfq_t_60 = self.h_conf.rd_opt( 'db', 'bt_daily_table_qfq_60') self.bt_daily_qfq_t_68 = self.h_conf.rd_opt( 'db', 'bt_daily_table_qfq_68') self.bt_daily_qfq_t_002 = self.h_conf.rd_opt( 'db', 'bt_daily_table_qfq_002') self.ma_cq_table_60 = self.h_conf.rd_opt('db', 'ma_cq_table_60') self.ma_cq_table_30 = self.h_conf.rd_opt('db', 'ma_cq_table_30') self.ma_cq_table_00 = self.h_conf.rd_opt('db', 'ma_cq_table_00') self.ma_cq_table_002 = self.h_conf.rd_opt('db', 'ma_cq_table_002') self.ma_cq_table_68 = self.h_conf.rd_opt('db', 'ma_cq_table_68') self.ma_qfq_table_60 = self.h_conf.rd_opt('db', 'ma_qfq_table_60') self.ma_qfq_table_30 = self.h_conf.rd_opt('db', 'ma_qfq_table_30') self.ma_qfq_table_00 = self.h_conf.rd_opt('db', 'ma_qfq_table_00') self.ma_qfq_table_002 = self.h_conf.rd_opt('db', 'ma_qfq_table_002') self.ma_qfq_table_68 = self.h_conf.rd_opt('db', 'ma_qfq_table_68') self.ma_bt_qfq_table_00 = self.h_conf.rd_opt( 'db', 'ma_bt_qfq_table_00') self.ma_bt_qfq_table_30 = self.h_conf.rd_opt( 'db', 'ma_bt_qfq_table_30') self.ma_bt_qfq_table_60 = self.h_conf.rd_opt( 'db', 'ma_bt_qfq_table_30') self.ma_bt_qfq_table_68 = self.h_conf.rd_opt( 'db', 'ma_bt_qfq_table_30') self.ma_bt_qfq_table_002 = self.h_conf.rd_opt( 'db', 'ma_bt_qfq_table_30') host = self.h_conf.rd_opt('db', 'host') database = self.h_conf.rd_opt('db', 'database') user = self.h_conf.rd_opt('db', 'user') pwd = self.h_conf.rd_opt('db', 'pwd') self.db = db_ops(host=host, db=database, user=user, pwd=pwd) wx.info("[OBJ] filter_fix : __init__ called") # 指定日期,用于回测,默认日期是当前最近交易日 if data_src == 'cq' or data_src == 'qfq': sql = "SELECT date from " + self.daily_cq_t_00 + " order by date desc limit 1" df_date = self.db._exec_sql(sql=sql) self.f_end_date = df_date.iloc[0, 0] self.f_start_date = (date.today() + timedelta(days=-240)).strftime('%Y%m%d') elif data_src == 'bt_qfq': if f_end_date == '' or f_start_date == '': wx.info("[Filter_fix]回测未设置起止日期区间[{}-{}]".format( f_start_date, f_end_date)) return self.f_end_date = f_end_date self.f_start_date = f_start_date self.data_src = data_src except Exception as e: raise e