• 策略验证_卖出口诀_长箭射天股价落地


    写在前面:
    1. 本文中提到的“股票策略校验工具”的具体使用操作请查看该博文
    2. 文中知识内容来自书籍《同花顺炒股软件从入门到精通》
    3. 本系列文章是用来学习技法,文中所得内容都仅仅只是作为演示功能使用

    目录

    解说

    策略代码

    结果


    解说

            所谓“长剑射天,股价落地”,是指股价进入高位后,出现一条长上影小实体K线,该形态具备如下特征。

            1)应是上影较长的星形小阳或小阴线,而且长影长度是实体的2倍以上。

            2)当天成交量有较大幅度的提升。

            3)必须是处于股价高位或者波段顶部。

             出现“长剑射天,股价落地”的形态后,股票投资者需遵循以下操作原则。

            1)此形态出现在上升行情的价格顶部是强烈卖出信号。

            2)本形态出现频率相当高,能在任何部位形成,但只有在高位出现时,方为可信卖出信号。

    策略代码

    1. def excute_strategy(base_data,data_dir):
    2. '''
    3. 卖出口诀 - 长箭射天,股价落地
    4. 解析:
    5. 1. 出现一条长上影小实体K线
    6. 2. 长影长度是实体的2倍以上
    7. 3. 成交量有较大幅度的提升
    8. 4. 上影线要高于前一日高点
    9. 自定义:
    10. 1. 较大幅度的提升 =》 前一日的两倍
    11. 2. 小实体 =》 K线实体是前一日收盘价的1.5%以下0.5%以上
    12. 3. 卖出时点 =》 形态出现后下一交易日
    13. 4. 胜 =》 卖出后第三个交易日收盘价下跌,为胜
    14. 只计算最近两年的数据
    15. :param base_data:股票代码与股票简称 键值对
    16. :param data_dir:股票日数据文件所在目录
    17. :return:
    18. '''
    19. import pandas as pd
    20. import numpy as np
    21. import talib,os
    22. from datetime import datetime
    23. from dateutil.relativedelta import relativedelta
    24. from tools import stock_factor_caculate
    25. def res_pre_two_year_first_day():
    26. pre_year_day = (datetime.now() - relativedelta(years=2)).strftime('%Y-%m-%d')
    27. return pre_year_day
    28. caculate_start_date_str = res_pre_two_year_first_day()
    29. dailydata_file_list = os.listdir(data_dir)
    30. total_count = 0
    31. total_win = 0
    32. check_count = 0
    33. list_list = []
    34. detail_map = {}
    35. factor_list = ['VOL']
    36. ma_list = []
    37. for item in dailydata_file_list:
    38. item_arr = item.split('.')
    39. ticker = item_arr[0]
    40. secName = base_data[ticker]
    41. file_path = data_dir + item
    42. df = pd.read_csv(file_path,encoding='utf-8')
    43. # 删除停牌的数据
    44. df = df.loc[df['openPrice'] > 0].copy()
    45. df['o_date'] = df['tradeDate']
    46. df['o_date'] = pd.to_datetime(df['o_date'])
    47. df = df.loc[df['o_date'] >= caculate_start_date_str].copy()
    48. # 保存未复权收盘价数据
    49. df['close'] = df['closePrice']
    50. # 计算前复权数据
    51. df['openPrice'] = df['openPrice'] * df['accumAdjFactor']
    52. df['closePrice'] = df['closePrice'] * df['accumAdjFactor']
    53. df['highestPrice'] = df['highestPrice'] * df['accumAdjFactor']
    54. df['lowestPrice'] = df['lowestPrice'] * df['accumAdjFactor']
    55. if len(df)<=0:
    56. continue
    57. # 开始计算
    58. for item in factor_list:
    59. df = stock_factor_caculate.caculate_factor(df,item)
    60. for item in ma_list:
    61. df = stock_factor_caculate.caculate_factor(df,item)
    62. df.reset_index(inplace=True)
    63. df['i_row'] = [i for i in range(len(df))]
    64. df['three_chg'] = round(((df['close'].shift(-3) - df['close']) / df['close']) * 100, 4)
    65. df['three_after_close'] = df['close'].shift(-3)
    66. df['body_length'] = abs(df['closePrice']-df['openPrice'])
    67. df['up_shadow'] = 0
    68. df.loc[df['closePrice']>df['openPrice'],'up_shadow'] = df['highestPrice'] - df['closePrice']
    69. df.loc[df['closePrice']'openPrice'],'up_shadow'] = df['highestPrice'] - df['openPrice']
    70. df['target_yeah'] = 0
    71. df.loc[(df['body_length']/df['closePrice'].shift(1)>0.005) & (df['body_length']/df['closePrice'].shift(1)<0.015) & (df['highestPrice']>df['highestPrice'].shift(1)) & (df['up_shadow']>2*df['body_length']) & (df['turnoverVol']>=2*df['turnoverVol'].shift(1)),'target_yeah'] = 1
    72. df_target = df.loc[df['target_yeah']==1].copy()
    73. # 临时 start
    74. # df.to_csv('D:/temp006/'+ticker + '.csv',encoding='utf-8')
    75. # 临时 end
    76. node_count = 0
    77. node_win = 0
    78. duration_list = []
    79. table_list = []
    80. i_row_list = df_target['i_row'].values.tolist()
    81. for i,row0 in enumerate(i_row_list):
    82. row = row0 + 1
    83. if row >= len(df):
    84. continue
    85. date_str = df.iloc[row]['tradeDate']
    86. cur_close = df.iloc[row]['close']
    87. three_after_close = df.iloc[row]['three_after_close']
    88. three_chg = df.iloc[row]['three_chg']
    89. table_list.append([
    90. i,date_str,cur_close,three_after_close,three_chg
    91. ])
    92. duration_list.append([row-2,row+3])
    93. node_count += 1
    94. if three_chg<0:
    95. node_win +=1
    96. pass
    97. list_list.append({
    98. 'ticker':ticker,
    99. 'secName':secName,
    100. 'count':node_count,
    101. 'win':0 if node_count<=0 else round((node_win/node_count)*100,2)
    102. })
    103. detail_map[ticker] = {
    104. 'table_list': table_list,
    105. 'duration_list': duration_list
    106. }
    107. total_count += node_count
    108. total_win += node_win
    109. check_count += 1
    110. pass
    111. df = pd.DataFrame(list_list)
    112. results_data = {
    113. 'check_count':check_count,
    114. 'total_count':total_count,
    115. 'total_win':0 if total_count<=0 else round((total_win/total_count)*100,2),
    116. 'start_date_str':caculate_start_date_str,
    117. 'df':df,
    118. 'detail_map':detail_map,
    119. 'factor_list':factor_list,
    120. 'ma_list':ma_list
    121. }
    122. return results_data

    结果

     

     本文校验的数据是随机抽取的81个股票

  • 相关阅读:
    面向对象、设计原则、编程规范、重构技巧
    Python数据挖掘项目实战——自动售货机销售数据分析
    集成华为AGC认证服务实用教程-MacOS
    打破汽车零部件企业供应链壁垒,数商云SCM供应链系统实现一体化采购协同
    【栈】736. Lisp 语法解析
    C++ 类和对象(4)构造函数
    Android 12.0 SystemUI状态栏屏蔽掉通知栏不显示通知
    1022 D进制的A+B
    第五章 循环结构程序设计
    【Java】Java中对List进行排序
  • 原文地址:https://blog.csdn.net/m0_37967652/article/details/127947493