Example #1
0
def merge_length(start, end):

    lens = np.arange(start=0.0100, stop=0.0200, step=0.0001)
    columns = []
    for x in lens:
        columns.append("%.4f" % x)
    print(columns)
    df =pd.DataFrame(columns=columns)
    eq = ts.Equity()
    all = eq.Equ(equTypeCD='A', listStatusCD='L', field='ticker')
    all['ticker'] = all['ticker'].map(lambda x:str(x).zfill(6))
    for i, row in all.iterrows():
        path = cfg.get_length_ratio_path(row['ticker'], start, end)
        try:
            if os.path.exists(path):
                len_df = pd.DataFrame.from_csv(path)
                len_df.index = len_df.index.map(lambda x : "%.4f" % x)
                # print(len_df.index)
                for len in columns:
                    # print(len_df.loc[len, 'ratio'])
                    df.loc[row['ticker'], len] = len_df.loc[len, 'ratio']
                print(row['ticker'])
        except Exception as e:
            print(e.message)
            continue

    df.to_csv("/home/chengang/tab.csv")
Example #2
0
def merge_length(start, end):

    lens = np.arange(start=0.0100, stop=0.0200, step=0.0001)
    columns = []
    for x in lens:
        columns.append("%.4f" % x)
    print(columns)
    df = pd.DataFrame(columns=columns)
    eq = ts.Equity()
    all = eq.Equ(equTypeCD='A', listStatusCD='L', field='ticker')
    all['ticker'] = all['ticker'].map(lambda x: str(x).zfill(6))
    for i, row in all.iterrows():
        path = cfg.get_length_ratio_path(row['ticker'], start, end)
        try:
            if os.path.exists(path):
                len_df = pd.DataFrame.from_csv(path)
                len_df.index = len_df.index.map(lambda x: "%.4f" % x)
                # print(len_df.index)
                for len in columns:
                    # print(len_df.loc[len, 'ratio'])
                    df.loc[row['ticker'], len] = len_df.loc[len, 'ratio']
                print(row['ticker'])
        except Exception as e:
            print(e.message)
            continue

    df.to_csv("/home/chengang/tab.csv")
Example #3
0
def export_ratio_table(code, start, end, thread_id):
    # queue_lock.acquire()
    ts.set_token(cfg.get_datayes_key())
    mkt = ts.Market()

    # print("exporting " + code + " from " + start + " to " + end)
    st = time.time()
    df = mkt.MktEqud(ticker=code, beginDate=start, endDate=end,
                     field='ticker,tradeDate,preClosePrice,openPrice,highestPrice,lowestPrice,closePrice')
    print("        Thread {0} fetch online: {1}".format(thread_id, time.time()-st))
    # queue_lock.release()
    # df = ts.get_h_data(code, start, end)
    # print(df)
    wave_ratio_df = pd.DataFrame(columns=["max_ratio", "min_ratio"])

    for i, row in df.iterrows():
        dict = wv.calc_wave_ratio(row["preClosePrice"], row["openPrice"],
                                  row["highestPrice"], row["lowestPrice"])
        wave_ratio_df.loc[row["tradeDate"]] = dict

    st = time.time()
    idx_col = wv.calc_ratio_table_index_and_columns(max_ratio=0.03, min_ratio=-0.03)
    index, columns = idx_col["index"], idx_col["columns"]
    ratio_table = wv.calc_ratio_table(wave_ratio_df, index, columns)
    print("        Thread {0} calc ratio table: {1}".format(thread_id, time.time()-st))

    st = time.time()
    length_ratio_df = wv.calc_length_ratio(ratio_table, len(wave_ratio_df.index))
    print("        Thread {0} calc length ratio: {1}".format(thread_id, time.time()-st))

    # write csv
    st = time.time()
    ratio_table.to_csv(cfg.get_ratio_table_path(code, start, end))
    length_ratio_df.to_csv(cfg.get_length_ratio_path(code, start, end))
    # print("  save csv: {0}".format(time.time()-st))

    return length_ratio_df