コード例 #1
0
def batch_gen_cnn_data_only_ave(code_list, inc_ratio_time_span, file_save_dir):
    """
    “批存储2”
    根据  “代码列表”  将数据按    “合适的格式” 存到  “指定文件夹”,
    有些stk天数不够,但在此函数里没有考虑这一问题,所以在读取的时候应该根据此条件进行筛选
    @param field_list  volume df中需要求均值的字段

    :param code_list:
    :param inc_ratio_time_span:
    :param file_save_dir:
    :return:
    """

    for code in code_list:

        csv_name = file_save_dir + str(code) + "CNN_Data.csv"

        # “数据库里面存在这个表”,且“目标文件不存在”的时候,才能继续操作
        if is_table_exist(conn_tick, stk_tick_data_db_name,
                          'tick' + code) & (not os.path.exists(csv_name)):

            # 获取均值数据
            df_ave = get_total_ave_ss(code, inc_ratio_time_span)
            df_ave.to_csv(csv_name)

        else:
            print("函数batch_gen_cnn_data:tick" + code +
                  " 表不存在,或者目标csv文件已经存在,函数返回空!")
コード例 #2
0
def getSingleStkGrowth(codeParam):

    result = []
    for year in range(2001, int(get_current_date_str().split('-')[0]) + 1):
        for quarter in range(1, 5):
            table_name = 'growth' + str(year) + '0' + str(quarter)
            if (int(str(year) + '0' + str(quarter)) < int(
                    get_quarter_date())) & is_table_exist(
                        conn_growth, stk_growth_data_db_name, table_name):
                growth_df = get_total_table_data(conn=conn_growth,
                                                 table_name=table_name)
                singleGrowth = growth_df[growth_df.code == codeParam]\
                .reset_index(drop=True)\
                .to_dict(orient='index')

                if len(singleGrowth):
                    singleGrowth = singleGrowth[0]
                    singleGrowth.update(
                        {'date': str(year) + '0' + str(quarter)})
                    result.append(singleGrowth)

    return DataFrame(result).sort_values(by='date', ascending=True)
コード例 #3
0
def get_ss_sb(codeParam, basic_ele):
    """
    从profit数据库中获取每个stk的数据,转成Dataframe后按时间升序排序,返回!

    :param codeParam:
    :param basic_ele:
    :return:
    """
    result = []

    if basic_ele == "profit":

        for year in range(2001, int(get_current_date_str().split('-')[0]) + 1):
            for quarter in range(1, 5):

                table_name = 'profit' + str(year) + '0' + str(quarter)
                if (int(str(year) + '0' + str(quarter)) < int(
                        get_quarter_date())) & is_table_exist(
                            conn_profit, stk_profit_data_db_name, table_name):
                    db_df = get_total_table_data(conn=conn_profit,
                                                 table_name=table_name)
                    single_basic_ele_data = db_df[db_df.code == codeParam]\
                    .reset_index(drop=True)\
                    .to_dict(orient='index')

                    if len(single_basic_ele_data):
                        single_basic_ele_data = single_basic_ele_data[0]
                        single_basic_ele_data.update(
                            {'date': str(year) + '0' + str(quarter)})
                        result.append(single_basic_ele_data)
                    else:
                        print(
                            "函数get_single_stk_single_basic:profit指标数据为空!季度为:" +
                            str(year) + '0' + str(quarter))

    elif basic_ele == "growth":

        for year in range(2001, int(get_current_date_str().split('-')[0]) + 1):
            for quarter in range(1, 5):

                table_name = 'growth' + str(year) + '0' + str(quarter)
                if (int(str(year) + '0' + str(quarter)) < int(
                        get_quarter_date())) & is_table_exist(
                            conn_growth, stk_growth_data_db_name, table_name):
                    db_df = get_total_table_data(conn=conn_growth,
                                                 table_name=table_name)
                    single_basic_ele_data = db_df[db_df.code == codeParam] \
                        .reset_index(drop=True) \
                        .to_dict(orient='index')

                    if len(single_basic_ele_data):
                        single_basic_ele_data = single_basic_ele_data[0]
                        single_basic_ele_data.update(
                            {'date': str(year) + '0' + str(quarter)})
                        result.append(single_basic_ele_data)
                    else:
                        print(
                            "函数get_single_stk_single_basic:growth指标数据为空!季度为:" +
                            str(year) + '0' + str(quarter))

    elif basic_ele == "operation":

        for year in range(2001, int(get_current_date_str().split('-')[0]) + 1):
            for quarter in range(1, 5):

                table_name = 'operation' + str(year) + '0' + str(quarter)
                if (int(str(year) + '0' + str(quarter)) < int(
                        get_quarter_date())) & is_table_exist(
                            conn_profit, stk_operation_data_db_name,
                            table_name):
                    db_df = get_total_table_data(conn=conn_operation,
                                                 table_name=table_name)
                    single_basic_ele_data = db_df[db_df.code == codeParam] \
                        .reset_index(drop=True) \
                        .to_dict(orient='index')

                    if len(single_basic_ele_data):
                        single_basic_ele_data = single_basic_ele_data[0]
                        single_basic_ele_data.update(
                            {'date': str(year) + '0' + str(quarter)})
                        result.append(single_basic_ele_data)
                    else:
                        print(
                            "函数get_single_stk_single_basic:operation指标数据为空!季度为:"
                            + str(year) + '0' + str(quarter))

    elif basic_ele == "debtpaying":

        for year in range(2001, int(get_current_date_str().split('-')[0]) + 1):
            for quarter in range(1, 5):

                table_name = 'debtpaying' + str(year) + '0' + str(quarter)
                if (int(str(year) + '0' + str(quarter)) < int(
                        get_quarter_date())) & is_table_exist(
                            conn_debtpaying, stk_debtpaying_data_db_name,
                            table_name):
                    db_df = get_total_table_data(conn=conn_debtpaying,
                                                 table_name=table_name)
                    single_basic_ele_data = db_df[db_df.code == codeParam] \
                        .reset_index(drop=True) \
                        .to_dict(orient='index')

                    if len(single_basic_ele_data):
                        single_basic_ele_data = single_basic_ele_data[0]
                        single_basic_ele_data.update(
                            {'date': str(year) + '0' + str(quarter)})
                        result.append(single_basic_ele_data)
                    else:
                        print(
                            "函数get_single_stk_single_basic:debtpaying指标数据为空!季度为:"
                            + str(year) + '0' + str(quarter))

    elif basic_ele == "cashflow":

        for year in range(2001, int(get_current_date_str().split('-')[0]) + 1):
            for quarter in range(1, 5):

                table_name = 'cashflow' + str(year) + '0' + str(quarter)
                if (int(str(year) + '0' + str(quarter)) < int(
                        get_quarter_date())) & is_table_exist(
                            conn_cashflow, stk_cashflow_data_db_name,
                            table_name):
                    db_df = get_total_table_data(conn=conn_cashflow,
                                                 table_name=table_name)
                    single_basic_ele_data = db_df[db_df.code == codeParam] \
                        .reset_index(drop=True) \
                        .to_dict(orient='index')

                    if len(single_basic_ele_data):
                        single_basic_ele_data = single_basic_ele_data[0]
                        single_basic_ele_data.update(
                            {'date': str(year) + '0' + str(quarter)})
                        result.append(single_basic_ele_data)
                    else:
                        print(
                            "函数get_single_stk_single_basic:cashflow指标数据为空!季度为:"
                            + str(year) + '0' + str(quarter))

    else:
        print("函数get_single_stk_single_basic:不识别的basic指标  " + basic_ele)

    try:
        result = DataFrame(result).sort_values(by='date', ascending=True)
    except:
        result = DataFrame()
        print("函数get_single_stk_single_basic:遇到没有数据的指标!" + basic_ele)

    return result
コード例 #4
0
def get_ss_sb_sq(codeParam, basic_ele, quarter):
    """
    下载“单个stk”的“单个basic方面”的“当前季度的basic信息”

    ss:single stk
    sb:single basic
    sq:single quarter
    :param codeParam:
    :return:
    """
    result = list()
    if basic_ele == "profit":

        table_name = 'profit' + quarter
        if is_table_exist(conn_profit, stk_profit_data_db_name, table_name):
            db_df = get_total_table_data(conn=conn_profit,
                                         table_name=table_name)
            single_basic_ele_data = db_df[db_df.code == codeParam]\
            .reset_index(drop=True)\
            .to_dict(orient='index')

            if len(single_basic_ele_data):
                single_basic_ele_data = single_basic_ele_data[0]
                single_basic_ele_data.update({'date': quarter})
                result.append(single_basic_ele_data)
            else:
                print("函数get_single_stk_single_basic:profit指标数据为空!季度为:" +
                      quarter)

    elif basic_ele == "growth":

        table_name = 'growth' + quarter
        if is_table_exist(conn_growth, stk_growth_data_db_name, table_name):

            db_df = get_total_table_data(conn=conn_growth,
                                         table_name=table_name)
            single_basic_ele_data = db_df[db_df.code == codeParam] \
                .reset_index(drop=True) \
                .to_dict(orient='index')

            if len(single_basic_ele_data):
                single_basic_ele_data = single_basic_ele_data[0]
                single_basic_ele_data.update({'date': quarter})
                result.append(single_basic_ele_data)
            else:
                print("函数get_single_stk_single_basic:growth指标数据为空!季度为:" +
                      quarter)

    elif basic_ele == "operation":

        table_name = 'operation' + quarter
        if is_table_exist(conn_profit, stk_operation_data_db_name, table_name):
            db_df = get_total_table_data(conn=conn_operation,
                                         table_name=table_name)
            single_basic_ele_data = db_df[db_df.code == codeParam] \
                .reset_index(drop=True) \
                .to_dict(orient='index')

            if len(single_basic_ele_data):
                single_basic_ele_data = single_basic_ele_data[0]
                single_basic_ele_data.update({'date': quarter})
                result.append(single_basic_ele_data)
            else:
                print("函数get_single_stk_single_basic:operation指标数据为空!季度为:" +
                      quarter)

    elif basic_ele == "debtpaying":

        table_name = 'debtpaying' + quarter
        if is_table_exist(conn_debtpaying, stk_debtpaying_data_db_name,
                          table_name):
            db_df = get_total_table_data(conn=conn_debtpaying,
                                         table_name=table_name)
            single_basic_ele_data = db_df[db_df.code == codeParam] \
                .reset_index(drop=True) \
                .to_dict(orient='index')

            if len(single_basic_ele_data):
                single_basic_ele_data = single_basic_ele_data[0]
                single_basic_ele_data.update({'date': quarter})
                result.append(single_basic_ele_data)
            else:
                print("函数get_single_stk_single_basic:debtpaying指标数据为空!季度为:" +
                      quarter)

    elif basic_ele == "cashflow":

        table_name = 'cashflow' + quarter
        if is_table_exist(conn_cashflow, stk_cashflow_data_db_name,
                          table_name):
            db_df = get_total_table_data(conn=conn_cashflow,
                                         table_name=table_name)
            single_basic_ele_data = db_df[db_df.code == codeParam] \
                .reset_index(drop=True) \
                .to_dict(orient='index')

            if len(single_basic_ele_data):
                single_basic_ele_data = single_basic_ele_data[0]
                single_basic_ele_data.update({'date': quarter})
                result.append(single_basic_ele_data)
            else:
                print("函数get_single_stk_single_basic:cashflow指标数据为空!季度为:" +
                      quarter)

    else:
        print("函数get_single_stk_single_basic:不识别的basic指标  " + basic_ele)

    try:
        result = DataFrame(result).sort_values(by='date', ascending=True)
    except:
        result = DataFrame()
        print("函数get_single_stk_single_basic:遇到没有数据的指标!" + basic_ele)

    return result