Exemplo n.º 1
0
    def gen_stk_sea_select_pic_sub(stk_code):

        try:
            jq_login()

            # 保存路径
            save_dir = sea_select_pic_dir + get_current_date_str() + '/'

            if not os.path.exists(save_dir):
                os.makedirs(save_dir)

            # 准备 小时 和 日线 数据
            df_hour = gen_hour_macd_values(stk_code)
            df_day = get_k_data_JQ(stk_code, 800)

            # 定义图片名称
            file_name = stk_code + '.png'

            # 生成小时图片
            gen_hour_macd_pic_local(df_hour, stk_code, 'jq', '',
                                    save_dir + 'h_' + file_name)
            gen_hour_index_pic_local(df_hour[0], stk_code,
                                     save_dir + 'h_idx_' + file_name)
            gen_day_pic_local(df_day, stk_code, save_dir + 'd_' + file_name)
            gen_w_m_macd_pic_local(df_day, stk_code,
                                   save_dir + 'wm_' + file_name)
            gen_idx_pic_local(df_day, stk_code,
                              save_dir + 'd_idx_' + file_name)

        except Exception as e:
            print('生成股票走势图失败!原因:\n' + str(e))
        finally:
            logout()
Exemplo n.º 2
0
    def prepare_data(self):
        """
        准备数据
        :return:
        """
        if self.debug:
            print('开始准备数据...')

        jq_login()

        # 准备数据
        df_m = get_k_data_JQ(self.stk_code,
                             start_date=self.start_date,
                             end_date=self.end_date,
                             freq=str(self.retest_span) + 'm')
        df_m['date'] = df_m.apply(lambda x: str(x['datetime'])[:10], axis=1)
        df_day = get_k_data_JQ(
            self.stk_code, start_date=self.start_date,
            end_date=self.end_date).sort_index(ascending=True)

        if len(df_day) < self.max_days:
            if self.debug:
                print('max_days:%d day_data_length:%d minute_data_length:%d' %
                      (self.max_days, len(df_day), len(df_m)))
            return False

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

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

        logout()
        return True
Exemplo n.º 3
0
def download_stk_list_day_data(stk_list, days=None):
    """
    给定stk_list,下载日期数据,以tuple的形式返回
    :return:
    """

    jq_login()
    stk_list_data = [(x, get_k_data_JQ(x, count=days)) for x in stk_list]
    stk_list_data = list(filter(lambda x: not x[1].empty, stk_list_data))
    logout()

    return stk_list_data
Exemplo n.º 4
0
    def prepare_data(self, period='5m', count=48 * 100):
        """
        准备数据
        :return:
        """
        jq_login()

        # 准备数据
        df_5m = get_k_data_JQ(self.stk_code, count=count, freq=period)
        df_5m['date'] = df_5m.apply(lambda x: str(x['datetime'])[:10], axis=1)
        df_day = get_k_data_JQ(self.stk_code, count=8 * 100,
                               freq='30m').sort_index(ascending=True)

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

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

        logout()
Exemplo n.º 5
0
def download_stk_list_hour_data(stk_list):
    """
    给定stk_list,下载半小时数据,以tuple的形式返回
    :return:
    """

    jq_login()
    stk_list_data = [
        (x,
         get_k_data_JQ(x,
                       count=120,
                       end_date=add_date_str(get_current_date_str(), 1),
                       freq='30m')) for x in stk_list
    ]

    # 清除空值
    stk_list_data = list(filter(lambda x: not x[1].empty, stk_list_data))

    logout()

    return stk_list_data