写在前面:
1. 本文中提到的“K线形态查看工具”的具体使用操作请查看该博文;
2. K线形体所处背景,诸如处在上升趋势、下降趋势、盘整等,背景内容在K线形态策略代码中没有体现;
3. 文中知识内容来自书籍《K线技术分析》by邱立波。
目录
解说
螺旋桨K线是上下影线都很长、实体很小的十字星线,因为K线形状像飞机的螺旋桨而得名。螺旋桨K线是较强的转势信号。
和长十字线一样,出现螺旋桨是转势信号。螺旋桨长长的上下影线,其技术含义也和长十字线的相同。螺旋桨的实体是小阴线和小阳线,表明至收盘时多方或空方占有一定的优势,因而螺旋桨发出的转势信号比长十字线更为强烈一些。
技术特征
1)K线实体(阴阳均可)很小。
2)上下影线很长。
3)上涨和下跌行情中都会出现。
技术含义
1)在股价有较大涨幅后出现螺旋桨,为见顶信号。
2)在股价有较大跌幅后出现螺旋桨为见底信号。
K线形态策略代码
def excute_strategy(daily_file_path):
'''
名称:螺旋桨
识别:上下影线都很长、实体很小的十字星线
自定义:
1. 影线很长=》超过上一交易日价格2%;
2. 实体很小=》实体小于等于上一交易日价格的0.5%
前置条件:计算时间区间 2021-01-01 到 2022-01-01
:param daily_file_path: 股票日数据文件路径
:return:
'''
import pandas as pd
import os
start_date_str = '2021-01-01'
end_date_str = '2022-01-01'
df = pd.read_csv(daily_file_path,encoding='utf-8')
# 删除停牌的数据
df = df.loc[df['openPrice'] > 0].copy()
df['o_date'] = df['tradeDate']
df['o_date'] = pd.to_datetime(df['o_date'])
df = df.loc[(df['o_date'] >= start_date_str) & (df['o_date']<=end_date_str)].copy()
# 保存未复权收盘价数据
df['close'] = df['closePrice']
# 计算前复权数据
df['openPrice'] = df['openPrice'] * df['accumAdjFactor']
df['closePrice'] = df['closePrice'] * df['accumAdjFactor']
df['highestPrice'] = df['highestPrice'] * df['accumAdjFactor']
df['lowestPrice'] = df['lowestPrice'] * df['accumAdjFactor']
# 开始计算
df.loc[df['closePrice']>=df['openPrice'],'type'] = 1
df.loc[df['closePrice']<df['openPrice'],'type'] = -1
df['body_length'] = abs(df['closePrice'] - df['openPrice'])
df.loc[df['type']==1,'top_shadow_length'] = df['highestPrice'] - df['closePrice']
df.loc[df['type']==-1,'top_shadow_length'] = df['highestPrice'] - df['openPrice']
df.loc[df['type']==1,'bottom_shadow_length'] = df['openPrice'] - df['lowestPrice']
df.loc[df['type']==-1,'bottom_shadow_length'] = df['closePrice'] - df['lowestPrice']
df['signal'] = 0
df['signal_name'] = ''
long_len = 0.02
short_len = 0.005
df.loc[(df['body_length']/df['closePrice'].shift(1)<=short_len) & (df['top_shadow_length']/df['closePrice'].shift(1)>=long_len) & (df['bottom_shadow_length']/df['closePrice'].shift(1)>=long_len),'signal'] = 1
df.loc[(df['body_length']/df['closePrice'].shift(1)<=short_len) & (df['top_shadow_length']/df['closePrice'].shift(1)>=long_len) & (df['bottom_shadow_length']/df['closePrice'].shift(1)>=long_len),'ext_0'] = (df['top_shadow_length']/df['closePrice'].shift(1))*100
df.loc[(df['body_length']/df['closePrice'].shift(1)<=short_len) & (df['top_shadow_length']/df['closePrice'].shift(1)>=long_len) & (df['bottom_shadow_length']/df['closePrice'].shift(1)>=long_len),'ext_1'] = (df['bottom_shadow_length']/df['closePrice'].shift(1))*100
df = df.round({'ext_0':5,'ext_1':5})
df['signal_name'] = df['ext_0'].astype('str') + ';' + df['ext_1'].astype('str')
file_name = os.path.basename(daily_file_path)
title_str = file_name.split('.')[0]
line_data = {
'title_str':title_str,
'whole_header':['日期','收','开','高','低'],
'whole_df':df,
'whole_pd_header':['tradeDate','closePrice','openPrice','highestPrice','lowestPrice'],
'start_date_str':start_date_str,
'end_date_str':end_date_str,
'signal_type':'line'
}
return line_data