写在前面:
1. 本文中提到的“K线形态查看工具”的具体使用操作请查看该博文;
2. K线形体所处背景,诸如处在上升趋势、下降趋势、盘整等,背景内容在K线形态策略代码中没有体现;
3. 文中知识内容来自书籍《K线技术分析》by邱立波。
目录
解说
圆底是下跌过程中或横向整理时,一根大阴线或中阴线后,在阴线底部收出若干走势呈向上圆弧形的小阴线和小阳线,最后以向上跳空缺口确认成立的K线组合。
技术特征
1)出现在下跌趋势或整理过程中。
2)先收出一根大阴线或中阴线,然后在其底部由若干小阴线、小阳线形成一个圆弧底。
3)一个向上跳空缺口确认圆底形态成立。
技术含义
圆底形态是见底信号,后市看涨。和塔形底一样,圆底也是一种比较可靠的反转形态,并且由于圆底向上突破时留下跳空缺口,因此其转势信号强于塔形底。
圆底的形状和塔形底很类似,其转势原理以及交易者心理变化也与塔形底差不多。交易者见到圆底后,可以适量介入。
K线形态策略代码
def excute_strategy(daily_file_path):
'''
名称:圆底
识别:一根大阴线或中阴线后,在阴线底部收出若干走势呈向上圆弧形的小阳线或小阴线,最后以向上跳空缺口确认成立
自定义:
1. 是否是圆弧 =》代码不判断,先依靠肉眼
2. 若干 =》 至少3根
3. 阴线底部 =》最高价在阴线实体底部三分之一以下
前置条件:计算时间区间 2021-01-01 到 2022-01-01
:param daily_file_path: 股票日数据文件路径
:return:
'''
import pandas as pd
import os
start_date_str = '2017-01-01'
end_date_str = '2018-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['type'] = 0
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['m_body_type'] = 0
df.loc[(df['type']==-1) & (df['body_length']/df['closePrice'].shift(1)>0.02),'m_body_type'] = 2
df['small_type'] = 0
df.loc[df['body_length']/df['closePrice'].shift(1)<0.015,'small_type'] = 1
# 向上跳空缺口
df['breakaway_gap'] = 0
df.loc[(df['type']==1) & (df['type'].shift(1)==1),'breakaway_gap'] = df['openPrice'] - df['closePrice'].shift(1)
df.loc[(df['type']==1) & (df['type'].shift(1)==-1),'breakaway_gap'] = df['openPrice'] - df['openPrice'].shift(1)
df.loc[(df['type']==-1) & (df['type'].shift(1)==1),'breakaway_gap'] = df['closePrice'] - df['closePrice'].shift(1)
df.loc[(df['type']==-1) & (df['type'].shift(1)==-1),'breakaway_gap'] = df['closePrice'] - df['openPrice'].shift(1)
df.reset_index(inplace=True)
df['i_row'] = [i for i in range(0,len(df))]
df_m_n = df.loc[df['m_body_type']==2].copy()
df_m_p = df.loc[df['breakaway_gap']>0].copy()
i_row_n = df_m_n['i_row'].values.tolist()
i_row_p = df_m_p['i_row'].values.tolist()
i_row_two = i_row_n + i_row_p
i_row_two.sort()
n_list = []
p_list = []
for i in range(0,len(i_row_two)-1):
if i_row_two[i] in i_row_n and i_row_two[i+1] in i_row_p:
n_list.append(i_row_two[i])
p_list.append(i_row_two[i+1])
pass
df['signal'] = 0
df['signal_name'] = ''
for n,p in zip(n_list,p_list):
if p-n < 3:
continue
enter_yeah = True
for i in range(n+1,p):
if df.iloc[i]['small_type']!=1:
enter_yeah = False
break
pass
if enter_yeah:
final_yeah = False
target_body_length = df.iloc[n]['body_length']
for m_i in range(n+1,p):
if (df.iloc[n]['closePrice'] + target_body_length*0.33) < df.iloc[m_i]['highestPrice']:
final_yeah = True
break
if final_yeah:
continue
df.loc[(df['i_row']>=n) & (df['i_row']<=p),'signal'] = 1
df.loc[(df['i_row']>=n) & (df['i_row']<=p),'signal_name'] = str(p-n)
pass
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':'duration_detail',
'duration_len':[],
'temp':len(df.loc[df['signal']==1])
}
return line_data