예제 #1
0
def calRSVRank(stk_code, Mdays, history_length=400):

    df = get_k_data_JQ(stk_code,
                       count=history_length,
                       end_date=get_current_date_str())

    # 移动平均线+RSV(未成熟随机值)
    M = Mdays

    df['low_M' + str(M)] = df['low'].rolling(window=M).mean()
    df['high_M' + str(M)] = df['high'].rolling(window=M).mean()
    df['close_M' + str(M)] = df['close'].rolling(window=M).mean()

    # df['low_M'+str(M)+'_min'] = df['low_M'+str(M)].rolling(window=M).min()
    # df['high_M'+str(M)+'_max'] = df['high_M'+str(M)].rolling(window=M).max()

    df['RSV'] = df.apply(lambda x:
                         (x['close_M' + str(M)] - x['low_M' + str(M)]) /
                         (x['high_M' + str(M)] - x['low_M' + str(M)]),
                         axis=1)

    # df['RSV_abs'] = df.apply(lambda x: (x['close_M'+str(M)] - x['low_M'+str(M)+'_min']), axis=1)
    # df['RSV_Rank'] = df.apply(lambda x: relativeRank(df['RSV'], x['RSV']), axis=1)

    return df.tail(1)['RSV'].values[0]
예제 #2
0
파일: Demo1.py 프로젝트: ccliuyang/My_Quant
def checkWeekStrayForAll():

    win_qq_name = '影子'

    df_total = ts.get_stock_basics()
    for stk in df_total.index:
        if int(str(df_total.loc[stk, 'timeToMarket'])[:4]) >= int(get_current_date_str()[:4]) - 4:
            print('函数 checkWeekStrayForAll:'+stk+'年龄不够4岁!')
            continue

        try:
            stray_flag = week_macd_stray_judge(stk, win_qq_name)
        except:
            print('函数 checkWeekStrayForAll:' + stk + '判断翻转出错!')
            stray_flag = False

        if stray_flag:
            df = get_k_data_JQ(stk, count=400, end_date=get_current_date_str())
            fig, _ = genStkPicForQQ(df)

            plt.title(str(stk))
            send_pic_qq(win_qq_name, fig)
            plt.close()

            fig, _ = genStkIdxPicForQQ(df)

            plt.title(str(stk))
            send_pic_qq(win_qq_name, fig)
            plt.close()
        else:
            print('No weed-stray in '+stk)
예제 #3
0
def printStkListPic2QQ(code_list, win_qq_name, title=None):

    if title is not None:
        title_str = title
    else:
        title_str = ''

    for x in code_list:
        df = get_k_data_JQ(x, 400)
        fig, _ = genStkPicForQQ(df)

        plt.title(str(x) + title_str)
        send_pic_qq(win_qq_name, fig)
        plt.close()

        fig, _ = genStkIdxPicForQQ(df)

        plt.title(str(x) + title_str)
        send_pic_qq(win_qq_name, fig)
        plt.close()
예제 #4
0
def sendMainIndexStkPic2Public():
    """
    将自己关心的数据打印出图,发送到qq
    :return:
    """

    for x in ['sh', 'sz', 'cyb']:

        df = get_k_data_JQ(x, 400)
        fig, _ = genStkPicForQQ(df)

        plt.title(str(x))
        send_pic_qq('大盘上涨概率公示', fig)
        plt.close()

        fig, _ = genStkIdxPicForQQ(df)

        plt.title(str(x))
        send_pic_qq('大盘上涨概率公示', fig)
        plt.close()
예제 #5
0
def sendConcernedStkPicToSelf_T():
    """
    将自己关心的数据打印出图,发送到qq
    :return:
    """

    for x in stk_list:

        df = get_k_data_JQ(x, 400)
        fig, _ = genStkPicForQQ(df)

        plt.title(str(x))
        send_pic_qq('影子2', fig)
        plt.close()

        fig, _ = genStkIdxPicForQQ(df)

        plt.title(str(x))
        send_pic_qq('影子2', fig)
        plt.close()
예제 #6
0
net_amount_xl	                超大单净额(万)	        超大单:大于等于50万股或者100万元的成交单
net_pct_xl	                    超大单净占比(%)	        超大单净占比 = 超大单净额 / 成交额
net_amount_l	                大单净额(万)	        大单:大于等于10万股或者20万元且小于50万股或者100万元的成交单
net_pct_l	                    大单净占比(%)	        大单净占比 = 大单净额 / 成交额
net_amount_m	                中单净额(万)	        中单:大于等于2万股或者4万元且小于10万股或者20万元的成交单
net_pct_m	                    中单净占比(%)	        中单净占比 = 中单净额 / 成交额
net_amount_s	                小单净额(万)	        小单:小于2万股或者4万元的成交单
net_pct_s	                    小单净占比(%)	        小单净占比 = 小单净额 / 成交额
"""

df_m_f = get_money_flow('300508.XSHE',
                        start_date='2019-04-01',
                        end_date=None,
                        fields=None,
                        count=None)
df = get_k_data_JQ('300508', start_date='2019-04-01')

# 获取300508所在的通信行业的估值
df = finance.run_query(
    query(finance.SW1_DAILY_VALUATION).filter(
        finance.SW1_DAILY_VALUATION.code == '801770'))
df = df.set_index('date').sort_index(ascending=True)
"""
表名: valuation

列名	                                列的含义	                解释	                公式
code	                                stk代码	                带后缀.XSHE/.XSHG	
day	                                    日期	                    取数据的日期	
capitalization	                        总股本(万股)	            公司已发行的普通股股份总数(包含A股,B股和H股的总股本)	
circulating_cap	                        流通股本(万股)	            公司已发行的境内上市流通、以人民币兑换的股份总数(A股市场的流通股本)	
market_cap	                            总市值(亿元)	            A股收盘价*已发行stk总股本(A股+B股+H股)	
예제 #7
0
# encoding=utf-8
import tushare as ts

from RelativeRank.Sub import relativeRank, get_k_data_JQ
from SDK.MyTimeOPT import add_date_str, get_current_date_str
"""
测试单个stk的相对排名
"""

stk_code = '600487'
df = get_k_data_JQ(stk_code=stk_code, count=400)

# 测试相对均值偏移度
df['m9'] = df['close'].rolling(window=9).mean()
df['diff_m9'] = df.apply(lambda x: (x['close'] - x['m9']) / x['close'], axis=1)

df['rank'] = df.apply(lambda x: relativeRank(df['diff_m9'], x['diff_m9']),
                      axis=1)
"""
df.plot('date', ['close', 'diff_m9', 'rank'], subplots=True)
"""

end = 0
예제 #8
0
파일: Demo1.py 프로젝트: ccliuyang/My_Quant
def week_macd_stray_judge(stk_code, win_qq_name):

    # 获取今天的大盘走势,涨幅没有超过3%的不考虑
    df_now = get_k_data_JQ(stk_code, count=2, end_date=get_current_date_str()).reset_index()

    if (df_now.tail(1)['close'].values[0]-df_now.head(1)['close'].values[0])/df_now.head(1)['close'].values[0] < 0.03:
        print('函数week_macd_stray_judge:' + stk_code + '涨幅不够!')
        return False


    df = get_k_data_JQ(stk_code, count=400, end_date=get_current_date_str()).reset_index()

    if len(df) < 350:
        print('函数week_macd_stray_judge:'+stk_code + '数据不足!')
        return False

    # 规整
    df_floor = df.tail(math.floor(len(df)/20)*20-19)

    # 增加每周的星期几
    df_floor['day'] = df_floor.apply(
        lambda x: calendar.weekday(int(x['date'].split('-')[0]), int(x['date'].split('-')[1]),
                                   int(x['date'].split('-')[2])), axis=1)

    # 取均值
    # df_floor['close_m5'] = df_floor['close'].rolling(window=5).mean()


    # 增加每周的星期几
    df_floor['day'] = df_floor.apply(lambda x: calendar.weekday(int(x['date'].split('-')[0]), int(x['date'].split('-')[1]), int(x['date'].split('-')[2])), axis=1)

    # 隔着5个取一个
    if df_floor.tail(1)['day'].values[0] != 4:
        df_floor_slice_5 = pd.concat([df_floor[df_floor.day == 4], df_floor.tail(1)], axis=0)
    else:
        df_floor_slice_5 = df_floor[df_floor.day == 4]

    # 计算指标
    df_floor_slice_5['MACD'], df_floor_slice_5['MACDsignal'], df_floor_slice_5['MACDhist'] = talib.MACD(df_floor_slice_5.close,
                                                                          fastperiod=6, slowperiod=12,
                                                                          signalperiod=9)

    # 隔着20个取一个(月线)
    df_floor_slice_20 = df_floor.loc[::20, :]

    # 计算指标
    df_floor_slice_20['MACD'], df_floor_slice_20['MACDsignal'], df_floor_slice_20['MACDhist'] = talib.MACD(
        df_floor_slice_20.close,
        fastperiod=4,
        slowperiod=8,
        signalperiod=9)

    # 获取最后的日期
    date_last = df_floor_slice_5.tail(1)['date'].values[0]

    # 判断背离
    macd_5 = df_floor_slice_5.tail(3)['MACD'].values
    macd_20 = df_floor_slice_20.tail(4)['MACD'].values
    if (macd_5[1] == np.min(macd_5)) & (macd_20[1] != np.max(macd_20)) & (macd_20[2] != np.max(macd_20)):

        df_floor_slice_5.plot('date', ['close', 'MACD'], subplots=True, style=['--', '*'])
        plt.title(stk_code + 'week-stray'+date_last)

        output = BytesIO()  # BytesIO实现了在内存中读写byte
        buf_save = BytesIO()

        plt.savefig(output)
        output.seek(0)
        img = Image.open(output)  # Image.open可以打开网络图片与本地图片。

        img.convert("RGB").save(buf_save, "BMP")  # 以RGB模式保存图像
        data = buf_save.getvalue()[14:]
        buf_save.close()
        output.close()
        plt.close()

        send_pic_qq_data(win_qq_name, data)

        # 打印月线图
        df_floor_slice_20.plot('date', ['close', 'MACD'], subplots=True, style=['--', '*'])
        plt.title(stk_code + 'month-stray' + date_last)

        output = BytesIO()  # BytesIO实现了在内存中读写byte
        buf_save = BytesIO()

        plt.savefig(output)
        output.seek(0)
        img = Image.open(output)  # Image.open可以打开网络图片与本地图片。

        img.convert("RGB").save(buf_save, "BMP")  # 以RGB模式保存图像
        data = buf_save.getvalue()[14:]
        buf_save.close()
        output.close()
        plt.close()

        send_pic_qq_data(win_qq_name, data)

        return True
    else:
        return False
예제 #9
0
파일: Demo1.py 프로젝트: ccliuyang/My_Quant



if __name__ == '__main__':


    r = calendar.weekday(2019, 12, 5)
    from JQData_Test.auth_info import *

    # week_macd_stray_judge('300183', '影子')

    checkWeekStrayForAll()

    stk_code = '600707'
    df = get_k_data_JQ(stk_code, count=600, end_date=get_current_date_str()).reset_index()

    # 规整
    df_floor = df.tail(math.floor(len(df)/20)*20-19)

    # 取均值
    df_floor['close_m5'] = df_floor['close'].rolling(window=5).mean()

    # 增加每周的星期几
    df_floor['day'] = df_floor.apply(lambda x: calendar.weekday(int(x['date'].split('-')[0]), int(x['date'].split('-')[1]), int(x['date'].split('-')[2])), axis=1)

    # 隔着5个取一个
    # df_floor_slice_5 = df_floor.loc[::5, :]
    if df_floor.tail(1)['day'].values[0] != 4:
        df_floor_slice_5 = pd.concat([df_floor[df_floor.day==4], df_floor.tail(1)], axis=0)
    else: