python量化交易 – 验证跳空高开策略的投资价值

python语言 workingTime 258℃ 0评论

改策略是验证个股跳空高开力度与之后5天涨幅的关系。

python包准备

  • numpy
  • tushare
  • pyecharts

获取沪深个股某一时间点日线数据

个股数据的获取API接口需在tushare网站上注册一个账号,然后获取token。注册地址

# 在tushare pro网站个人信息中查看toekn
token = ''
api = ts.pro_api(token)

# 设置查询日期
start_day = '20181115'
# 调用tushare接口,获取该日期的全部个股日线数据
df = api.daily(trade_date=start_day)

寻找跳空高开的股票

公式:今开价 > 昨收价 * 系数

  • 现在我们使用for循环,来查找出满足公式的股票,代码如下:
for row in np.arange(0, df.shape[0]):
    today = df.iloc[row]
    jump = today.pre_close * 1.03
    if today.low > jump:
        print("满足条件的股票代码是:", today.ts_code)

计算个股跳空高开力度

公式:(最低价 – 昨收价)/昨收价 * 100

  • 代码如下:
# 上跳力度
jump_num = ((today.low - today.pre_close) / today.pre_close) * 100

个股未来五日收益情况

# 获取指定日期5天内的日线数据
def get_pay_day(api, start_day, day):
    end_day = int(start_day) + day + 9
    return api.trade_cal(
        exchange='', start_date=start_day, end_date=str(end_day),
        is_open=1).loc[day, 'cal_date']

采样数据进行图表分析

2018年5月-10月,每月抽取两天为样本数据

采样日期 采样日大盘涨跌幅 数据结果
2018-05-04 0.317% ↓ ['002795.SZ', '300093.SZ', '300256.SZ', '300328.SZ', '300475.SZ', '300743.SZ', '603348.SH', '002169.SZ', '002848.SZ', '002889.SZ', '600157.SH', '603596.SH', '000014.SZ', '002903.SZ', '300690.SZ']
向上跳的能量: [4.79, 10.0, 3.23, 5.05, 4.55, 9.99, 10.02, 9.98, 3.48, 9.16, 3.26, 10.0, 3.15, 10.0, 3.76]
一周涨幅: [29.96, 14.3, 20.94, 10.01, 4.59, 50.0, 40.53, 22.93, 19.21, 17.45, 11.11, 49.98, 39.37, 12.23, -1.45]
2018-05-21 0.643% ↑ ['002172.SZ', '002235.SZ', '002648.SZ', '002828.SZ', '002847.SZ', '002850.SZ', '002930.SZ', '300084.SZ', '300228.SZ', '300454.SZ', '300471.SZ', '300540.SZ', '300644.SZ', '300742.SZ', '300743.SZ', '600026.SH', '600265.SH', '600428.SH', '601858.SH', '601872.SH', '601919.SH', '603013.SH', '603045.SH', '603223.SH', '603259.SH', '603603.SH', '603800.SH', '603903.SH']
向上跳的能量: [5.14, 3.35, 5.58, 5.97, 8.08, 3.62,10.01, 10.0, 3.95, 10.0, 6.88, 10.0, 10.01, 9.99, 10.0, 9.92, 5.01, 3.68, 3.52, 3.42, 4.54, 10.02, 10.01, 3.75, 10.01, 10.0, 9.99, 3.5]
一周涨幅: [1.9, 7.89, 7.08, 30.0, 16.73, 3.77, 30.31, 1.43, 7.05, 49.99, 27.39, 40.02, 30.02, 34.42, 27.37, 6.82, 10.26, 2.74, 6.39, -0.56,3.94, 41.94, 50.02, -0.31, 50.02, 14.91, 30.02, 3.24]
2018-06-12 0.885% ↑ ['000019.SZ', '300410.SZ', '300745.SZ', '300746.SZ', '300750.SZ', '600074.SH', '600560.SH', '600696.SH', '601138.SH', '601330.SH', '603486.SH', '603666.SH']
向上跳的能量: [6.07, 3.38, 3.87, 10.0, 10.0, 4.76, 4.26, 4.14, 10.0, 9.92, 5.11, 43.99]
一周涨幅: [10.08, -9.06, 2.66,47.05, 50.0, 2.75, -18.09, -4.63, -5.3, 49.81, -8.13, 83.97]
2018-06-19 3.775% ↓ ['600313.SH', '601330.SH', '601990.SH', '603666.SH', '603722.SH', '000713.SZ', '002225.SZ', '300345.SZ', '300487.SZ', '300750.SZ']
向上跳的能量: [5.23, 9.96, 9.98, 9.99, 6.06, 4.55, 3.22, 10.02, 10.0, 10.0]
一周涨幅: [6.62, 49.89, 39.3, 49.98, 12.84, 4.41, 15.61, 29.94, 2.33, 28.31]
2018-07-06 0.448% ↑ ['000401.SZ', '000922.SZ', '002356.SZ', '002866.SZ', '002890.SZ', '002927.SZ', '300022.SZ', '300038.SZ', '300390.SZ', '300637.SZ', '300747.SZ', '600265.SH', '601038.SH', '603045.SH', '603650.SH', '603693.SH']
向上跳的能量: [5.24, 3.67, 3.95, 4.32, 3.4, 9.49, 10.14, 6.48, 9.95, 3.17, 10.0, 5.02, 9.86, 10.0, 9.99, 10.01]
一周涨幅: [15.06, 8.51, 12.6, 14.74, 7.43, 14.47, 12.98, 19.8, 49.95, 22.28, 50.0, 7.92, 13.0, 10.97, 38.25, 50.05]
2018-07-19 0.528% ↓ ['600853.SH', '603105.SH', '603186.SH', '603338.SH', '603706.SH', '603709.SH', '603713.SH', '603738.SH', '002027.SZ', '002932.SZ', '300460.SZ', '300464.SZ', '300469.SZ', '300576.SZ', '300586.SZ']
向上跳的能量: [3.09, 10.02, 4.77, 4.51, 9.99, 3.77, 10.0, 8.97, 9.96, 10.01, 10.0, 10.0, 9.99, 9.99, 9.98]
一周涨幅: [13.0, 50.02, -5.61, 10.67, 34.4, 5.1, 50.01, 1.63, 13.82, 50.0, 2.3, 20.03, 16.77, 3.94, 10.16]
2018-08-01 1.803% ↓ ['000557.SZ', '002006.SZ', '002401.SZ', '300154.SZ', '600119.SH', '600278.SH', '600653.SH', '600720.SH', '603183.SH', '603648.SH', '603657.SH', '603988.SH']
向上跳的能量: [3.88, 10.04, 6.64, 4.31, 4.2, 10.04, 10.1, 3.05, 3.83, 4.51, 9.99, 9.98]
一周涨幅: [-11.28, 40.58, -0.4, -1.75, 14.55, 16.83, 5.33, 8.31, -0.45, -2.47, 50.0, 19.9]
2018-08-20 1.105% ↑ ['002913.SZ', '300289.SZ', '300295.SZ', '300609.SZ', '300724.SZ', '600604.SH', '600789.SH', '600793.SH', '601606.SH', '603035.SH']
向上跳的能量: [3.23, 9.97, 3.42, 4.26, 3.93, 10.04, 6.89, 3.54, 9.98, 4.15]
一周涨幅: [16.31, 23.72, 7.85, 1.14, -0.26, 0.21, 24.46, 17.53, 50.05, 11.95]
2018-09-05 1.681% ↓ ['000979.SZ', '002028.SZ', '002091.SZ', '002467.SZ', '002600.SZ', '002933.SZ', '002935.SZ', '300004.SZ', '300064.SZ', '300104.SZ', '300265.SZ', '300411.SZ', '300662.SZ', '600640.SH', '600929.SH', '601068.SH', '603192.SH']
向上跳的能量: [3.3, 9.99, 5.68, 4.53, 9.9, 10.01, 10.0, 4.59, 6.68, 6.9, 9.93, 9.98, 3.56, 9.97, 9.84, 9.97, 9.99]
一周涨幅: [9.89, 11.04, 1.85, 5.61, 0.69, 23.93, 50.04, -0.13, 0.57, 10.08, 8.42, 35.04, -4.53, 14.21, 5.83, 49.94, 9.07]
2018-09-18 1.816% ↑ ['000586.SZ', '000952.SZ', '002796.SZ', '002938.SZ', '300092.SZ', '300213.SZ', '300345.SZ', '300436.SZ', '603029.SH', '603636.SH', '603790.SH', '603810.SH']
向上跳的能量: [6.67, 6.0, 4.18, 19.98, 10.04, 4.15, 10.11, 4.33, 10.02, 3.25, 9.98, 9.99]
一周涨幅: [14.26, 13.11, 18.85, 48.06, 14.47, 4.83, 13.0, 5.26, 7.81, 6.08, 49.98, 33.85]
2018-10-10 0.117% ↑ ['000533.SZ', '000576.SZ', '000979.SZ', '002431.SZ', '002629.SZ', '002895.SZ', '002931.SZ', '002937.SZ', '300216.SZ', '300230.SZ', '300644.SZ', '300670.SZ', '300702.SZ', '300748.SZ', '300749.SZ', '600488.SH', '603177.SH', '603192.SH', '603633.SH']
向上跳的能量: [3.7, 3.79, 4.3, 3.23, 3.64, 5.1, 4.03, 9.98, 10.09, 3.03, 10.01, 4.41, 9.99, 10.04, 10.02, 3.99, 7.58, 3.0, 3.63]
一周涨幅: [-15.66, 9.02, -1.94, -19.63, -10.75, 0.81, 7.72, 29.99, 20.63, 9.7, -7.46, 40.54, -10.85, 49.98, 4.22, -7.13, 5.37, 6.9, 13.11]
2018-10-22 4.094% ↑ ['000007.SZ', '000609.SZ', '000610.SZ', '000622.SZ', '000633.SZ', '000668.SZ', '000679.SZ', '000691.SZ', '000707.SZ', '000737.SZ', '000890.SZ', '000929.SZ', '000953.SZ', '000972.SZ', '000995.SZ', '002058.SZ', '002072.SZ', '002112.SZ', '002122.SZ', '002127.SZ', '002207.SZ', '002211.SZ', '002213.SZ', '002260.SZ', '002271.SZ', '002289.SZ', '002306.SZ', '002333.SZ', '002384.SZ', '002413.SZ', '002419.SZ', '002451.SZ','002456.SZ', '002463.SZ', '002473.SZ', '002475.SZ', '002563.SZ', '002575.SZ', '002607.SZ', '002633.SZ', '002687.SZ', '002729.SZ', '002750.SZ', '002755.SZ', '002760.SZ', '002799.SZ', '002836.SZ', '002857.SZ', '300029.SZ', '300061.SZ', '300091.SZ', '300163.SZ', '300170.SZ', '300192.SZ', '300340.SZ', '300508.SZ', '300538.SZ', '300601.SZ', '300653.SZ', '300694.SZ', '300736.SZ', '300760.SZ', '600053.SH', '600071.SH', '600091.SH', '600099.SH', '600137.SH', '600143.SH', '600193.SH', '600202.SH', '600209.SH', '600250.SH', '600275.SH', '600301.SH', '600306.SH', '600319.SH', '600355.SH', '600421.SH', '600455.SH', '600493.SH', '600506.SH', '600556.SH', '600566.SH', '600579.SH', '600605.SH', '600608.SH', '600647.SH', '600678.SH', '600695.SH', '600732.SH', '600763.SH', '600768.SH', '600769.SH', '600817.SH', '600870.SH', '601162.SH', '601619.SH', '603016.SH', '603088.SH', '603098.SH', '603605.SH', '603725.SH', '603730.SH', '603838.SH', '603880.SH']
向上跳的能量: [10.0, 3.16, 4.14, 10.08, 3.53, 7.67, 4.76, 4.49, 3.88, 3.28, 3.02, 4.44, 4.86, 3.17, 4.91, 4.87, 8.93, 10.0, 3.45, 3.18, 3.12, 9.98, 4.12, 5.04, 3.85, 4.6, 5.07, 9.83, 5.02, 6.17, 5.07, 9.97, 3.93, 5.5, 5.07, 3.6, 4.61, 9.9, 3.09, 10.06, 9.98, 3.41, 4.67, 10.0, 9.97, 4.75, 4.82, 9.99,4.29, 4.17, 3.1, 3.21, 3.14, 3.08, 4.68, 10.0, 6.47, 3.01, 3.19, 7.63, 5.68, 3.3, 3.09, 3.47, 4.58, 5.23, 3.25, 10.08, 5.22, 4.27, 4.92, 3.24, 5.1, 4.68, 10.08, 4.14, 3.89, 4.35, 6.4, 3.89, 9.95, 3.48, 3.55, 3.27, 3.11, 4.56, 4.8, 4.95, 9.96, 4.01, 3.83, 6.33, 3.88, 4.94, 5.08, 10.08, 5.37, 9.99, 3.54, 3.31, 3.48, 4.86, 3.4, 5.14, 5.99]
一周涨幅: [10.98, 12.88, 9.35, 49.86, 11.65, 22.82, 13.48, 22.91, 9.76, 7.65, 8.02, 9.98, 24.78, 13.39, 12.82, 7.87, 10.27, 20.04, 8.73, 15.3, 4.23, 11.98, 10.54, 16.83, 10.12, 12.42, 8.84, 5.53, 6.85, 14.93, 6.75, 19.57, 3.95, 11.22, 16.73, 2.92, 1.18, 25.08, 13.87, 14.08, 39.96, 5.32, 3.78, 14.43, 11.68, 5.26, 3.13, 33.99, 9.97, 5.27, 8.0, 14.19, 2.11, 4.19, 6.71, 30.17, -1.51, -1.25, 9.11, 8.45, 3.79, 9.35, 7.7, -1.73, 16.62, 10.47, 9.36, 14.72, 14.48, 12.24, 16.95, 18.58, 17.25, 11.14, 13.64, 10.55, 11.21, 6.67, 6.16, 19.01, 16.32, 9.82, 6.48, 8.11, 7.93, 11.56, 8.02, 10.63, 46.78, 13.5, 3.91, 12.06, 12.22, 13.12, 21.79,49.86, 0.83, 3.88, 14.16, 5.2, 3.91, 5.88, 7.98, 7.28, 12.4]
  • 图表说明:柱状图代表上跳力度,折线图代表5日收益
采样日期 采样日大盘涨跌幅 图表展示
2018-05-04 0.317% ↓
2018-05-21 0.643% ↑
2018-06-12 0.885% ↑
2018-06-19 3.775% ↓
2018-07-06 0.448% ↑
2018-07-19 0.528% ↓
2018-08-01 1.803% ↓ 
2018-08-20 1.105% ↑
2018-09-05 1.681% ↓
2018-09-18 1.816% ↑
2018-10-10 0.117% ↑ 2018-10-22

总结

  • 大盘表现越好,跳空高开的股票越多
  • 9以上基本都是当日涨停的股票,可以看到如果你在下一个交易日可以买进,5日正收益率还是非常高的。
  • 跳空能力4-6的股票,5日收益为正的概率很高。

源码


import tushare as ts
import numpy as np
from pyecharts import Bar, Line, Overlap

token = ''
api = ts.pro_api(token)

# print(df.iloc[0].low)
# 从制定的开始日期,返回指定的交易天数


# 获取指定日期5天内的日线数据
def get_pay_day(api, start_day, day):
    end_day = int(start_day) + day + 9
    return api.trade_cal(
        exchange='', start_date=start_day, end_date=str(end_day),
        is_open=1).loc[day, 'cal_date']


# 开始日期
start_day = '20181022'
end_day = get_pay_day(api, start_day, 4)
df = api.daily(trade_date=start_day)
# 找出跳空高开的股票
code = []
jumpNum = []
riseNum = []

for row in np.arange(0, df.shape[0]):
    today = df.iloc[row]
    jump = today.pre_close * 1.03
    if today.low > jump:
        # 上跳力度
        jump_num = ((today.low - today.pre_close) / today.pre_close) * 100

        if jump_num < 100:
            # 查看调控高开的股票一周内的涨跌幅 和能力的关系
            # 从调控高开后的5天股价
            df_chil = api.daily(
                ts_code=today.ts_code,
                start_date=today.trade_date,
                end_date=end_day)
            #   获取5日涨跌额
            sh_data = np.array([df_chil["pct_chg"].values])
            # print(today.ts_code, "涨幅", sh_data)
            code.append(today.ts_code)
            jumpNum.append(round(jump_num, 2))
            riseNum.append(round(np.sum(sh_data, axis=1)[0], 2))

print(code, "向上跳的能量:", jumpNum, "一周涨幅:", riseNum)
bar = Bar("调控高开验证")
bar.add("向上跳的能量", code, jumpNum, tooltip_trigger="axis")
line = Line()
line.add("一周涨幅", code, riseNum, tooltip_trigger="axis")
overlap = Overlap()
overlap.add(bar)
overlap.add(line)
overlap.render()

转载请注明:R&M » python量化交易 – 验证跳空高开策略的投资价值

喜欢 (0)or分享 (0)
发表我的评论
取消评论

表情

联系我:rm@rmworking.com