Esempio n. 1
0
def updatePotInfo():
    """
    :param df_H_L_Pot:
    :return:
    """
    # h_l_pot_info_url = '.\InfoRestore\df_H_L_Pot.pkl'
    if os.path.exists(h_l_pot_info_url):
        with open(h_l_pot_info_url, 'rb') as f:
            try:
                h_l_pot_info = pickle.load(f)
            except:
                h_l_pot_info = pd.DataFrame()
    else:
        h_l_pot_info = pd.DataFrame()

    if h_l_pot_info.empty:
        h_l_pot_info = initPotInfo(get_h_l_pot(stk_list))
    else:
        new_pot_info = get_h_l_pot(stk_list)

        h_l_pot_info = pd.concat([
            h_l_pot_info.drop([
                'half_year_high', 'half_year_low', 'month_high', 'month_low',
                'year_high', 'year_low'
            ], 1),
            new_pot_info.drop('stk', 1)
        ],
                                 axis=1)

    # 将结果序列化
    with open(h_l_pot_info_url, 'wb') as f:
        pickle.dump(h_l_pot_info, f)

    send_qq(u'影子', '高底线信息更新成功!')
Esempio n. 2
0
def judgeAndSendMsg():
    """
    按频率调用,
    :return:
    """
    if os.path.exists(h_l_pot_info_url):
        with open(h_l_pot_info_url, 'rb') as f:
            h_l_pot_info = pickle.load(f)
    else:
        print('函数 judgeAndSendMsg: 加载高低信息失败!')
        return

    df_H_L_Pot = h_l_pot_info

    for stk in df_H_L_Pot.index:

        # 获取该股票的实时价格
        current_price = float(
            ts.get_realtime_quotes(df_H_L_Pot.loc[stk,
                                                  'stk'])['price'].values[0])

        # 将当前价格保存,用于验证计算准确性
        df_H_L_Pot.loc[stk, 'current_price'] = current_price
        """ 年线判断 """
        df_H_L_Pot = lineJudge(df_H_L_Pot_index=stk,
                               current_price=current_price,
                               df_info=df_H_L_Pot,
                               line_str='year')
        """ ----------------- 半年线判断 -----------------"""
        df_H_L_Pot = lineJudge(df_H_L_Pot_index=stk,
                               current_price=current_price,
                               df_info=df_H_L_Pot,
                               line_str='half_year')
        """ ----------------- 月线判断 ----------------"""
        df_H_L_Pot = lineJudge(df_H_L_Pot_index=stk,
                               current_price=current_price,
                               df_info=df_H_L_Pot,
                               line_str='month')
    """ 检查并发送消息 """
    for idx in df_H_L_Pot.index:

        # 遍历年线、半年线和月线
        for sts in ['year_status', 'half_year_status', 'month_status']:
            if (df_H_L_Pot.loc[idx, sts] != u'正常') & (df_H_L_Pot.loc[
                    idx, sts] != df_H_L_Pot.loc[idx, sts + '_last']):
                send_qq(
                    u'影子', 'stk:' + getNameByStkCode(
                        g_total_stk_info_mysql, df_H_L_Pot.loc[idx, 'stk']) +
                    '\n' + '当前价格:' +
                    str(df_H_L_Pot.loc[idx, 'current_price']) + '\n' +
                    '事件: “' + df_H_L_Pot.loc[idx, sts + '_last'] + '” --> “' +
                    df_H_L_Pot.loc[idx, sts] + '”' + '\n\n')

                df_H_L_Pot.loc[idx, sts + '_last'] = df_H_L_Pot.loc[idx, sts]

    with open(h_l_pot_info_url, 'wb') as f:
        pickle.dump(h_l_pot_info, f)

    print('函数 judgeAndSendMsg: 完成本次判断!')
Esempio n. 3
0
def update_price_ratio_info():
    """
    :param df_H_L_Pot:
    :return:
    """

    # 将结果序列化
    with open(price_ratio_info_url, 'wb') as f:
        pickle.dump(h_l_pot_info, f)

    send_qq(u'影子', '高底线信息更新成功!')
Esempio n. 4
0
File: Sub.py Progetto: dxcv/My_Quant
def updateConcernStkMData():
    """
    定时器定时调用,更新各stk的M离心度历史数据
    :return:
    """
    try:
        for stk in stk_list:
            saveStkMRankHistoryData(stk_code=stk,
                                    history_days=400,
                                    m_days=9,
                                    save_dir='./M_data/')
            send_qq('影子', '更新' + stk + '离心度历史数据成功!')
    except:
        send_qq('影子', '更新离心度历史数据失败!')
Esempio n. 5
0
File: Sub.py Progetto: dxcv/My_Quant
def checkDivergeLowLevel():
    """
    供定时器调用的回调函数,按频率检查关心的stk的,对高于80分的进行提示
    :return:
    """
    for stk in stk_list:

        r = calRealtimeRank(stk_code=stk,
                            M_days=9,
                            history_data_dir=MDataPWD + '/M_data/')

        if r > 80:
            send_qq('影子',
                    'Attention:\n' + stk + '趋向高分!分数为:' + str('%0.2f') % r)
        else:
            print(stk + '分数处于正常状态!分数为:' + str('%0.2f') % r)
Esempio n. 6
0
def JudgeSingleStk(stk_code, stk_price_last, stk_amount_last, earn_threshold):

    # 获取该股票的实时价格
    current_price = float(ts.get_realtime_quotes(stk_code)['price'].values[0])
    price_diff = current_price - stk_price_last

    if current_price == 0.0:
        print(stk_code + 'price==0.0! 返回!')
        return

    buy_amount = math.floor((money_each_opt / current_price) / 100) * 100

    # 计算其离心度分数
    try:
        rank9 = calRealtimeRank(stk_code=stk_code,
                                M_days=9,
                                history_data_dir=MDataPWD + '/M_data/')
    except:
        rank9 = -1

    if (price_diff * stk_amount_last > earn_threshold * remind_ratio) & (
            price_diff * stk_amount_last < earn_threshold):

        send_qq(
            '影子', "Near! S! " + stk_code + '\nAmount:' + str(stk_amount_last) +
            '\nP_now:' + str(current_price) + '\nP_last:' +
            str(stk_price_last) + '\nthreshold:' + str(earn_threshold) +
            '\nM9_rank:' + str('%0.2f' % rank9))

    elif price_diff * stk_amount_last > earn_threshold:
        send_qq(
            '影子', "Reach! S! " + stk_code + '\nAmount:' +
            str(stk_amount_last) + '\nP_now:' + str(current_price) +
            '\nP_last:' + str(stk_price_last) + '\nthreshold:' +
            str(earn_threshold) + '\nM9_rank:' + str('%0.2f' % rank9))

    elif (price_diff * buy_amount > -earn_threshold) & (
            price_diff * buy_amount < -earn_threshold * remind_ratio):
        send_qq(
            '影子', "Near! B! " + stk_code + '\nAmount:' + str(buy_amount) +
            '\nP_now:' + str(current_price) + '\nP_last:' +
            str(stk_price_last) + '\nthreshold:' + str(earn_threshold) +
            '\nM9_rank:' + str('%0.2f' % rank9))

    elif price_diff * buy_amount < -earn_threshold:
        send_qq(
            '影子', "Reach! B! " + stk_code + '\nAmount:' + str(buy_amount) +
            '\nP_now:' + str(current_price) + '\nP_last:' +
            str(stk_price_last) + '\nthreshold:' + str(earn_threshold) +
            '\nM9_rank:' + str('%0.2f' % rank9))

    else:
        print('未触发任何警戒线!')
Esempio n. 7
0
File: Sub.py Progetto: dxcv/My_Quant
def checkDivergeLowLevel_Sea():
    """
    供定时器调用的回调函数,按频率检查关心的stk的,对高于80分的进行提示
    :return:
    """
    for stk in stk_pool:

        try:
            r = calRealtimeRank(stk_code=stk,
                                M_days=9,
                                history_data_dir=SeaSelectDataPWD +
                                '/stk_pool_data/')

            if r > 94:
                send_qq('影子',
                        'Attention:\n' + stk + '趋向高分!分数为:' + str('%0.2f') % r)
            else:
                print(stk + '分数处于正常状态!分数为:' + str('%0.2f') % r)
        except:
            print(stk + '判断时出现异常!')
Esempio n. 8
0
def saveWeightFile():
    """
    将持仓股票的权值存为文件
    :param dir:
    :return:
    """

    # 新方式:lacalDBInfo包括除了“数据库名”之外的其他参数
    localDBInfo = {
        'host': 'localhost',
        'port': 3306,
        'user': '******',
        'password': '******',
        'charset': 'utf8'
    }

    db_name = 'stk_opt_info'

    table_history = 'history'
    table_now = 'now'

    (conn_opt, engine_opt) = genDbConn(localDBInfo, db_name)
    df = pd.read_sql(con=conn_opt, sql='select * from now')

    if not df.empty:
        df['weight'] = df.apply(lambda x: calWeight(x['stk_code']), axis=1)

        dumpPickle(data=df, saveLocation='./Weight/', fileName='weight')
        send_qq('影子',
                '更新股票的权值成功!\n' + str(df.loc[:, ['stk_name', 'weight']].values))

    else:
        dumpPickle(data=pd.DataFrame(),
                   saveLocation='./Weight/',
                   fileName='weight')
        send_qq('影子', '更新股票权值时发现 now 表为空!')

    conn_opt.close()