ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

期货:高频日内交易

2022-04-28 18:05:06  阅读:77  来源: 互联网

标签:loc name index 日内 KneePointType df 期货 close 高频


高频交易基于低手续费,且交易判断成功的概率远大于失败的基础上的。

朴素的思路是判断拐点,在拐点处产生快速交易。

首先导入某一期货品种(分钟K线). 

df = pd.read_csv("JqData/RB2205.csv", index_col='date',parse_dates=['date'])[['open','close','low','high']]

分K线走势是这样子的:

df = df[:120]
df[['close']].plot()
plt.show()

 

 

找到拐点,并标记出来。(注意:拐点判断有延时性,交易具有延时性)

算法;

求导(dx=1),根据本点的前两点,和上一拐点的性质和距离判断前一点是否是拐点(knee point),本点是否买入或卖出

# Create new columns to store the knee point flag, type, and open direction.
df['kpFlag'] = np.NaN
df['kpType'] = np.NaN
df['oDirection'] = np.NaN

prevKpClose = 0
minDistance = 3
prevKpType = KneePointType.Unknown
for i in range(2, len(df)):
    if (df['dy1'][i-1] >=0) and (df['dy1'][i] < 0):   # flat/up -> down
        df.loc[df.index[i-1], 'kpType'] = KneePointType.Down.name
        if (prevKpType != KneePointType.Down):
            df.loc[df.index[i-1], 'kpFlag'] = True
            prevKpType = KneePointType.Down       
            if (df['close'][i-1] - prevKpClose >= minDistance * 1):
                df.loc[df.index[i], 'oDirection'] = OpenDirection.Sell.name
                prevKpClose = df.loc[df.index[i-1], 'close'] 
    elif (df['dy1'][i-1] <=0) and (df['dy1'][i] > 0):   # flat/down -> up
        df.loc[df.index[i-1], 'kpType'] = KneePointType.Up.name
        if (prevKpType != KneePointType.Up):
            df.loc[df.index[i-1], 'kpFlag'] = True
            prevKpType = KneePointType.Up       
            if (df['close'][i-1] - prevKpClose <= minDistance * -1):
                df.loc[df.index[i], 'oDirection'] = OpenDirection.Buy.name
                prevKpClose = df.loc[df.index[i-1], 'close'] 

 

 

 

把拐点(K),买点(B),和卖点(S)图形化显示一下:

from matplotlib import pylab
z = df[['close','kpFlag']]
z.plot(marker='o') # Plot the data, with a marker set.
#pylab.xlim(0,3) # Change the axes limits so that we can see the annotations.
#pylab.ylim(0,4)
plt.rcParams["figure.figsize"] = (36,20)
ax = pylab.gca()

for i in z.index: # iterate through each index in the dataframe
    v = df.loc[i, 'close'] 
    f = df.loc[i, 'kpFlag'] 
    d = df.loc[i, 'oDirection']
    if f == True:
        ax.annotate('K',xy=(i,v),  bbox=dict(boxstyle='round,pad=0.2', fc='pink', alpha=0.5),)
    if d == OpenDirection.Buy.name:
        ax.annotate('B',xy=(i,v),bbox=dict(boxstyle='round,pad=0.2', fc='red', alpha=0.5),fontsize=20)
    if d == OpenDirection.Sell.name:
        ax.annotate('S',xy=(i,v),  bbox=dict(boxstyle='round,pad=0.2', fc='green', alpha=0.5), fontsize=20)

 

 看起来这个震荡行情下的表现还不错,单边行情中还需要做一些微调

 

标签:loc,name,index,日内,KneePointType,df,期货,close,高频
来源: https://www.cnblogs.com/fdyang/p/16203865.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有