Esempio n. 1
0
def get_latest_temp_datas(write_file_name=fc.ALL_TEMP_FILE,
                          data_dir=fc.ALL_TEMP_DIR,
                          files=[]):
    """
    获取所有回测最后一个K线的数据:特定目录下
    """
    #columns = ['date', 'close', 'id', 'trade', 'p_change', 'position', 'operation', 's_price', 'b_price', 'profit', 'cum_prf', 'fuli_prf', 'hold_count']
    columns = pds.get_data_columns(dest_dir=data_dir)
    #df = combine_file(tail_num=1,dest_dir=data_dir,keyword='bs_',prefile_slip_num=3,columns=columns)
    df = combine_file(tail_num=1,
                      dest_dir=data_dir,
                      keyword='',
                      prefile_slip_num=0,
                      columns=columns,
                      file_list=files)
    if df.empty:
        return df
    df['counts'] = df.index
    df = df[columns + ['counts', 'code']]
    df['code'] = df['code'].apply(lambda x: pds.format_code(x))
    df['name'] = df['code'].apply(
        lambda x: pds.format_name_by_code(x, CHINESE_DICT))
    df = df.set_index('code')
    if write_file_name:
        df.to_csv(write_file_name, encoding='utf-8')
    return df
def get_latest_yh_k_stocks(write_file_name=fc.ALL_YH_KDATA_FILE,
                           data_dir=fc.YH_SOURCE_DATA_DIR):
    """
    获取所有银河最后一个K线的数据:特定目录下
    """
    columns = ['date', 'open', 'high', 'low', 'close', 'volume', 'amount']
    columns = pds.get_data_columns(dest_dir=data_dir)
    df = combine_file(tail_num=1,
                      dest_dir=data_dir,
                      keyword='',
                      prefile_slip_num=0,
                      columns=columns)
    if df.empty:
        return df
    df['counts'] = df.index
    df = df[['date', 'open', 'high', 'low', 'close', 'volume', 'amount'] +
            ['counts', 'code']]
    df['code'] = df['code'].apply(lambda x: pds.format_code(x))
    df['name'] = df['code'].apply(
        lambda x: pds.format_name_by_code(x, CHINESE_DICT))
    df = df.set_index('code')
    """
    if CHINESE_DICT:#添加中文代码
            try:
                tail_df['name'] = CHINESE_DICT[prefile_name]
            except:
                tail_df['name'] = '某指数'
    """
    if write_file_name:
        try:
            df.to_csv(write_file_name, encoding='utf-8')
        except Exception as e:
            print('get_latest_yh_k_stocks: ', e)
    return df
Esempio n. 3
0
def get_latest_temp_datas_from_csv(file_name=fc.ALL_TEMP_FILE):
    """
    获取所有回测最后一个K线的数据
    """
    #file_name = 'D:/work/backtest/all_bs_stocks.csv'
    #columns = ['date', 'close', 'id', 'trade', 'p_change', 'position', 'operation', 's_price', 'b_price', 'profit', 'cum_prf', 'fuli_prf', 'hold_count']
    columns = pds.get_data_columns(
        dest_dir=fc.ALL_TEMP_DIR) + ['counts', 'code', 'name']
    try:
        df = pd.read_csv(file_name, usecols=columns)
        df['code'] = df['code'].apply(lambda x: pds.format_code(x))
        df = df.set_index('code')
        return df
    except:
        return get_latest_backtest_datas(write_file_name=file_name)
def get_latest_yh_k_stocks_from_csv(file_name=fc.ALL_YH_KDATA_FILE):
    """
    获取股票K线数据,数据来源银河证券
    """
    #file_name = 'C:/work/result/all_yh_stocks.csv'
    #columns = ['date', 'open', 'high', 'low', 'close', 'volume', 'amount']+['counts','code']
    columns = pds.get_data_columns(
        dest_dir=fc.YH_SOURCE_DATA_DIR) + ['counts', 'code']
    #try:
    if True:
        df = pd.read_csv(file_name)  #,usecols=columns)
        #print(df)
        #print(type(df['code']))
        df['code'] = df['name'].apply(lambda x: pds.format_code(x))
        df['name'] = df['code'].apply(
            lambda x: pds.format_name_by_code(x, CHINESE_DICT))
        df = df.set_index('code')
        return df