Beispiel #1
0
def timer_ctrl(win, debug=False):
    jq_login()

    # 创建rsv对象
    rsv = RSV()

    if not rsv.update_success:
        win.on_update_note_tc_a('rsv初始化失败,原因:\n' + str(rsv.msg) + '\n')
    else:
        win.on_update_note_tc_a('rsv初始化成功\n')

    while True:
        try:
            on_timer_ctrl(win, rsv, debug)
        except Exception as e_:
            win.on_update_msg_tc_a(
                '\n\n----------------------------\n高频网格检测出错! 原因:\n' + str(e_) +
                '\n\n')
        time.sleep(30)
Beispiel #2
0
    def add_reseau(self):
        """
        计算动态网格,并添加到数据当中
        :return:
        """

        if self.debug:
            print('开始增加网格信息...')

        t_s = time.time()

        # 想day data 中 增加必要index
        self.data_day = add_stk_index_to_df(self.data_day)

        # 增加必要index
        self.data_minute = add_stk_index_to_df(self.data_minute)

        # 增加rsv数据
        self.data_day = RSV.add_rsv(self.data_day, self.rsv_span)

        # 最初的数天数据不进行回测,开始的部分数据因为数据量原因计算不出网格大小
        max_days = self.max_days
        i_start = self.i_start
        i = len(self.data_minute) - i_start

        data_day = self.data_day.set_index(keys='date')

        # 大循环
        for idx in self.data_minute[i_start:].index:

            # 获取当天数据
            df_today = self.cal_today_ochl(
                self.data_minute.loc[idx -
                                     int(60 * 4 / self.retest_span):idx, :])

            # 获取时间
            date = self.data_minute.loc[idx, 'date']

            # 获取该日期之前数天的数据
            df_day_data = self.data_day[
                self.data_day['date'] < date][1 - self.reseau_slow:]

            # 增加今天的数据
            df_day_complete = df_day_data.append(df_today, ignore_index=True)

            # 计算rsv和波动情况
            # rsv = RSV.cal_rsv_rank_sub(df_day_complete, self.rsv_span)
            try:
                rsv = data_day.loc[date, 'RSV']
            except:
                print()
            reseau_object = Reseau()
            reseau = reseau_object.get_single_stk_reseau_sub(
                df_=df_day_complete,
                slow=self.reseau_slow,
                quick=self.reseau_quick)

            self.data_minute.loc[idx, 'rsv'] = rsv
            self.data_minute.loc[idx, 'reseau'] = reseau

            # 调节 buy 和 sale 的 threshold
            self.data_minute.loc[idx, 'thh_sale'] = reseau * 2 * rsv
            self.data_minute.loc[idx, 'thh_buy'] = reseau * 2 * (1 - rsv)

            if self.debug:
                i = i - 1
                print('还剩%d行' % i)

        minute_reckon_print(t_s, '增加网格')