Пример #1
0
def check_point():
    stock_list_file = 'basic-no3.csv'
    df = pd.read_csv(Path().joinpath(stock_list_file), converters={'code': lambda x: str(x)})
    if df.empty:
        print('no stock list, quit')
        quit()

    result_string = ''
    tick_dir = Path().joinpath('..', '..', 'stockdata', 'day')
    result_df = mylib2.hist_callback(df, tick_dir, 5, check_point_one_for_day,
                              0,
                              0,
                              20)

    if not result_df.empty:
        result_string2 = result_string + "\n\n meet checkpoint 1 \n" + result_df.to_string()
    else:
        result_string2 = result_string + '\n\n no meet checkpoint 1\n'
    #print(result_string2)

    tick_dir_week = Path().joinpath('..', '..', 'stockdata', 'week')
    result_df2 = mylib2.hist_callback(df, tick_dir_week, 3, check_point_one_for_week,
                                     0,
                                     0,
                                     20)

    if not result_df2.empty:
        result_df2 = result_df[result_df['code'].isin(result_df2['code'])]
        result_string2 = "\n\n meet checkpoint 1 \n" + result_df2.to_string()
    else:
        result_string2 = '\n\n no week meet checkpoint 1\n'
    print(result_string2)
Пример #2
0
def get_a_across_b(df, cross_above, cross_type, num_of_days_periods,
                   period_type, rank):
    result_string = ''
    tick_dir = getPath(period_type)
    result_list = mylib2.hist_callback(df, tick_dir, num_of_days_periods,
                                       mylib6.find_a_cross_b, cross_above,
                                       cross_type, 30)

    df_result = pd.DataFrame(result_list,
                             columns=[
                                 'name', 'code', 'start_date', 'end_date',
                                 'days', 'p_change', 'p1', 'p2', 'p3'
                             ])
    df_result.code = df_result.code.astype('str')

    str_time = datetime.datetime.now().strftime("%Y-%m-%d-%H-%M-%S")
    tmpfile = Path().joinpath(
        'tmp', 'get_a_across_b-' + str(mylib2.head_offset) + '_' +
        period_type + cross_type + '_' + str(num_of_days_periods) + '_days_' +
        "-" + str_time + '.csv')
    if rank:
        df_result = add_columns_and_rank_stock(df_result)
    df_result.set_index('code', inplace=True)
    df_result.to_csv(tmpfile)
    return df_result
Пример #3
0
def get_latest_n_periods_price_up(df, num_of_periods, type, period_type):
    result_string = ''
    tick_dir = Path().joinpath('..', '..', get_data_dir(), type)
    result_df = mylib2.hist_callback(df, tick_dir, num_of_periods,
                                     mylib2.find_price_go_up_for_n_period,
                                     period_type, 0, 20)
    return result_df
Пример #4
0
def get_w_shape(df, num_of_periods, type='day'):
    result_string = ''
    tick_dir = Path().joinpath('..', '..', get_data_dir(), type)
    df_result = mylib2.hist_callback(df, tick_dir, num_of_periods,
                                     mylib4.find_w_shape, 0, 0, num_of_periods)

    df_result = fill_columns(df, df_result)
    str_time = datetime.datetime.now().strftime("%Y-%m-%d-%H-%M-%S")
    df_result = rank_stock(df_result)
    tmpfile = Path().joinpath('tmp', 'w-shape-' + str_time + '.csv')
    df_result.to_csv(tmpfile)
    return df_result
Пример #5
0
def get_current_price_up_periods(df):
    tick_dir = Path().joinpath('..', '..', get_data_dir(), 'day')
    df_result = mylib2.hist_callback(df, tick_dir, 60,
                                     mylib5.find_current_price_up_for_n_period,
                                     60, 0, 60)
    df_result = fill_columns(df, df_result)
    str_time = datetime.datetime.now().strftime("%Y-%m-%d-%H-%M-%S")
    tmpfile = Path().joinpath('tmp', 'get_no_touch_ma5-' + str_time + '.csv')
    df_result = rank_stock(df_result)
    df_result.sort_values('days', inplace=True, ascending=False)
    df_result.to_csv(tmpfile)
    return df_result
Пример #6
0
def get_history_high_price(df, event_to_now, num_of_days_periods, period_type):
    tick_dir = getPath(period_type)
    df_result = mylib2.hist_callback(df, tick_dir, num_of_days_periods,
                                     mylib4.find_history_high_v2, event_to_now,
                                     0, 60)

    str_time = datetime.datetime.now().strftime("%Y-%m-%d-%H-%M-%S")
    tmpfile = Path().joinpath(
        'tmp', 'get_history_high_price-' + str_time + '_' +
        str(num_of_days_periods) + '_days_' + '.csv')
    df_result.set_index('code', inplace=True)
    df_result.to_csv(tmpfile)
    return df_result
Пример #7
0
def get_latest_sum_of_week_price_up(stock_list_file, num_of_weeks):
    # stock_list_file = 'basic-no3.csv'
    # num_of_weeks = 2
    df = pd.read_csv(Path().joinpath(stock_list_file),
                     converters={'code': lambda x: str(x)})
    if df.empty:
        print('no stock list, quit')
        quit()
    result_string = ''
    tick_dir = Path().joinpath('..', '..', get_data_dir(), 'week')
    result_df = mylib2.hist_callback(df, tick_dir, num_of_weeks,
                                     mylib2.sum_of_latest_n_days_price_up, 0,
                                     0, 20)
    return result_df
Пример #8
0
def get_price_above(df, type, num_of_days_periods, period_type):
    result_string = ''
    tick_dir = getPath(period_type)
    df_result = mylib2.hist_callback(df, tick_dir, num_of_days_periods,
                                     mylib6.find_price_above, type, 0, 60)

    str_time = datetime.datetime.now().strftime("%Y-%m-%d-%H-%M-%S")
    tmpfile = Path().joinpath(
        'tmp', 'get_price_above-' + period_type + '_' +
        str(num_of_days_periods) + '_days_' + '.csv')
    #df_result = rank_stock(df_result)
    #pdb.set_trace()
    df_result.set_index('code', inplace=True)
    df_result.to_csv(tmpfile)
    return df_result
Пример #9
0
def get_first_history_high_volume_in_n(df, num_of_days, num_of_days_periods=0):
    result_string = ''
    tick_dir = Path().joinpath('..', '..', get_data_dir(), 'day')
    df_result = mylib2.hist_callback(df, tick_dir, num_of_days_periods,
                                     mylib4.find_first_history_high_volume,
                                     num_of_days, 0, 60)

    df_result = fill_columns(df, df_result)
    str_time = datetime.datetime.now().strftime("%Y-%m-%d-%H-%M-%S")
    tmpfile = Path().joinpath(
        'tmp', 'get_first_history_high_volume-' + str_time + '_' +
        str(num_of_days_periods) + '_days_' + '.csv')
    df_result = rank_stock(df_result)
    df_result.to_csv(tmpfile)
    return df_result
Пример #10
0
def get_price_continuous_down_in_n(df, num_of_days_down, price_down_sum,
                                   num_of_days_periods, period_type):
    result_string = ''
    tick_dir = getPath(period_type)
    df_result = mylib2.hist_callback(
        df, tick_dir, num_of_days_periods,
        mylib6.find_price_continuous_down_for_n_period, num_of_days_down,
        price_down_sum, 60)

    df_result = fill_columns(df, df_result)
    str_time = datetime.datetime.now().strftime("%Y-%m-%d-%H-%M-%S")
    tmpfile = Path().joinpath(
        'tmp', 'get_price_continuous_down_in_n-' + period_type + str_time +
        '_' + str(num_of_days_periods) + '_days_' + '.csv')
    df_result = rank_stock(df_result)
    df_result.to_csv(tmpfile)
    return df_result
Пример #11
0
def get_price_up_with_percentage(df, percentage, num_of_days_periods,
                                 period_type):
    result_string = ''
    tick_dir = getPath(period_type)
    result_list = mylib2.hist_callback(df, tick_dir, num_of_days_periods,
                                       mylib6.find_price_up_with_percentage,
                                       percentage, 0, 60)

    df_result = pd.DataFrame(
        result_list,
        columns=['name', 'code', 'start_date', 'end_date', 'days', 'p_change'])
    df_result.code = df_result.code.astype('str')

    str_time = datetime.datetime.now().strftime("%Y-%m-%d-%H-%M-%S")
    tmpfile = Path().joinpath(
        'tmp', 'get_price_up_with_percentage-' + period_type + '_' +
        str(num_of_days_periods) + '_days_' + str_time + '.csv')
    #df_result = rank_stock(df_result)
    #pdb.set_trace()
    df_result.set_index('code', inplace=True)
    df_result.to_csv(tmpfile)
    return df_result
Пример #12
0
def get_miminum_price_sum_in_n(df, is_price_up, min_price_range, min_day_range,
                               num_of_days_periods, period_type):
    tick_dir = getPath(period_type)
    result_list = mylib2.hist_callback(
        df, tick_dir, num_of_days_periods,
        mylib6.find_minimum_price_sum_for_n_period, is_price_up,
        (min_price_range, min_day_range), 60)

    df_result = pd.DataFrame(
        result_list,
        columns=['name', 'code', 'start_date', 'end_date', 'days', 'p_change'])
    df_result.code = df_result.code.astype('str')
    #df_result = fill_columns(df, df_result)
    str_time = datetime.datetime.now().strftime("%Y-%m-%d-%H-%M-%S")
    tmpfile = Path().joinpath(
        'tmp', 'get_price_sum_in_n-' + period_type + str_time + '_' +
        str(num_of_days_periods) + '_days_' + '.csv')
    #df_result = rank_stock(df_result)
    #pdb.set_trace()
    df_result.sort_values('p_change', inplace=True, ascending=not is_price_up)
    df_result.set_index('code', inplace=True)
    df_result.to_csv(tmpfile)
    return df_result