• K线形态识别_身怀六甲和十字胎


    写在前面:
    1. 本文中提到的“K线形态查看工具”的具体使用操作请查看该博文
    2. K线形体所处背景,诸如处在上升趋势、下降趋势、盘整等,背景内容在K线形态策略代码中没有体现;
    3. 文中知识内容来自书籍《K线技术分析》by邱立波。

    目录

    解说

    技术特征

    技术含义

    K线形态策略代码

    结果


    解说

            身怀六甲,又称母子线、孕线,因其K线形态好像一个怀胎的孕妇而得名。身怀六甲由实体一长一短的两根K线组成,其中第二根较短的K线实体完全被第一根较长的K线实体包容。当第二根K线是十字线时,称为十字胎。

    技术特征

    1)既可以出现在上涨趋势中,也可以出现在下跌趋势中。

    2)由两根K线组成,第一根较长的K线实体完全包容第二根较短的K线实体。

    3)两根K线可以是一阴一阳,也可以是两根阳线或阴线。

    4)第二根K线可以是小阴线、小阳线,也可以是十字线。

    技术含义

    1)大幅上涨后出现身怀六甲是见顶信号,后市看淡。

    2)出现大幅下跌后是见底信号。

    3)十字胎和身怀六甲的技术含义相同,是身怀六甲中信号最强的K线组合,这是因为单根的十字线本身就具有见顶和见底的意味。

    K线形态策略代码

    1. def excute_strategy(daily_file_path):
    2. '''
    3. 名称:身怀六甲和十字胎
    4. 识别:
    5. 1. 第二根K线实体完全被第一根较长的K线实体包容,第二根K线是小阴线、小阳线
    6. 2. 第二根K线是十字线
    7. 前置条件:计算时间区间 2021-01-01 到 2022-01-01
    8. :param daily_file_path: 股票日数据文件路径
    9. :return:
    10. '''
    11. import pandas as pd
    12. import os
    13. start_date_str = '2021-01-01'
    14. end_date_str = '2022-01-01'
    15. df = pd.read_csv(daily_file_path,encoding='utf-8')
    16. # 删除停牌的数据
    17. df = df.loc[df['openPrice'] > 0].copy()
    18. df['o_date'] = df['tradeDate']
    19. df['o_date'] = pd.to_datetime(df['o_date'])
    20. df = df.loc[(df['o_date'] >= start_date_str) & (df['o_date']<=end_date_str)].copy()
    21. # 保存未复权收盘价数据
    22. df['close'] = df['closePrice']
    23. # 计算前复权数据
    24. df['openPrice'] = df['openPrice'] * df['accumAdjFactor']
    25. df['closePrice'] = df['closePrice'] * df['accumAdjFactor']
    26. df['highestPrice'] = df['highestPrice'] * df['accumAdjFactor']
    27. df['lowestPrice'] = df['lowestPrice'] * df['accumAdjFactor']
    28. # 开始计算
    29. df['type'] = 0
    30. df.loc[df['closePrice']>=df['openPrice'],'type'] = 1
    31. df.loc[df['closePrice']'openPrice'],'type'] = -1
    32. df['body_length'] = abs(df['closePrice']-df['openPrice'])
    33. df['second_yeah'] = 0
    34. df.loc[df['body_length']/df['closePrice'].shift(1)<0.015,'second_yeah'] = 1
    35. df['sort_type'] = 0
    36. # 阳 阳
    37. df.loc[(df['type']==1) & (df['type'].shift(1)==1),'sort_type'] = 1
    38. # 阳 阴
    39. df.loc[(df['type'] == 1) & (df['type'].shift(1) == -1), 'sort_type'] = 2
    40. # 阴 阳
    41. df.loc[(df['type'] == -1) & (df['type'].shift(1) == 1), 'sort_type'] = 3
    42. # 阴 阴
    43. df.loc[(df['type'] == -1) & (df['type'].shift(1) == -1), 'sort_type'] = 4
    44. df['signal'] = 0
    45. df['signal_name'] = ''
    46. df.loc[(df['sort_type']==1) & (df['second_yeah']==1) & (df['closePrice']'closePrice'].shift(1)) & (df['openPrice']>df['openPrice'].shift(1)),'signal'] = 1
    47. df.loc[(df['sort_type']==1) & (df['second_yeah']==1) & (df['closePrice']'closePrice'].shift(1)) & (df['openPrice']>df['openPrice'].shift(1)),'signal_name'] = '阳 阳'
    48. df.loc[(df['sort_type']==2) & (df['second_yeah']==1) & (df['closePrice']'openPrice'].shift(1)) & (df['openPrice']>df['closePrice'].shift(1)),'signal'] = 1
    49. df.loc[(df['sort_type']==2) & (df['second_yeah']==1) & (df['closePrice']'openPrice'].shift(1)) & (df['openPrice']>df['closePrice'].shift(1)),'signal_name'] = '阳 阴'
    50. df.loc[(df['sort_type']==3) & (df['second_yeah']==1) & (df['openPrice']'closePrice'].shift(1)) & (df['closePrice']>df['openPrice'].shift(1)),'signal'] = 1
    51. df.loc[(df['sort_type']==3) & (df['second_yeah']==1) & (df['openPrice']'closePrice'].shift(1)) & (df['closePrice']>df['openPrice'].shift(1)),'signal_name'] = '阴 阳'
    52. df.loc[(df['sort_type']==4) & (df['second_yeah']==1) & (df['openPrice']'openPrice'].shift(1)) & (df['closePrice']>df['closePrice'].shift(1)),'signal'] = 1
    53. df.loc[(df['sort_type']==4) & (df['second_yeah']==1) & (df['openPrice']'openPrice'].shift(1)) & (df['closePrice']>df['closePrice'].shift(1)),'signal_name'] = '阴 阴'
    54. file_name = os.path.basename(daily_file_path)
    55. title_str = file_name.split('.')[0]
    56. line_data = {
    57. 'title_str':title_str,
    58. 'whole_header':['日期','收','开','高','低'],
    59. 'whole_df':df,
    60. 'whole_pd_header':['tradeDate','closePrice','openPrice','highestPrice','lowestPrice'],
    61. 'start_date_str':start_date_str,
    62. 'end_date_str':end_date_str,
    63. 'signal_type':'duration',
    64. 'duration_len':[2],
    65. 'temp':len(df.loc[df['signal']==1])
    66. }
    67. return line_data

    结果

  • 相关阅读:
    C++ 构造函数不能声明为虚函数的原因
    AD学习笔记
    C语言解决exe程序闪退最简单的方法。
    第四章 玩转捕获数据包
    【C++】C++ 引用详解 ⑩ ( 常量引用案例 )
    ubuntu 操作杂项
    开源医疗大模型排行榜: 健康领域大模型基准测试
    【数据分析】京东订单数据分析思路及Python代码
    【Unity3D日常开发】Unity3D中打包WEBGL后读取本地文件数据
    java毕业生设计毕业生交流学习平台计算机源码+系统+mysql+调试部署+lw
  • 原文地址:https://blog.csdn.net/m0_37967652/article/details/127733693