(同花顺量化)2021年_、主升起动、rsi小于65

用户头像神盾局量子研究部
2023-08-31 发布

问财量化选股策略逻辑

选股逻辑:在RSI小于65、主升起动以及2021年表现良好的股票作为投资标的。

选股逻辑分析

该选股策略在RSI和主升起动的基础上,更加强调2021年的表现,以寻找具有良好走势的股票。相比于前一个选股逻辑,该策略将涨停板条件去掉,注重基于时间的过滤。选取表现良好的股票,能够在一定程度上提高投资策略的稳定性和收益率。

有何风险?

  • 只考虑短期走势,没有考虑公司的基本面和宏观经济的影响,存在盲目跟风的风险;
  • 仅考虑2021年的表现,可能会忽略一些潜力较大的股票,降低策略收益率。

如何优化?

  • 在时间条件的基础上,可以增加其他技术指标的判断,如MA、MACD等,以降低选股的难度和提高策略的稳定性;
  • 结合基本面指标,如市盈率、市净率、营收增长率等,综合考量公司的财务状况;
  • 采用机器学习、深度学习等方法,构建更加完善的选股模型,减少视觉判断和主观干预的影响。

最终的选股逻辑

在RSI小于65、主升起动以及2021年表现良好的情况下,选取该股票作为投资标的。

同花顺指标公式代码参考

以下是选股策略中使用的同花顺指标公式代码:

// RSI小于65
RSI(CLOSE,14) < 65

// 主升起动
HHV(HIGH,30) == REF(HHV(HIGH,30),1) AND
LLV(LOW,30) == REF(LLV(LOW,30),1)

// 2021年表现良好
YEAR(CLOSE == MAX(CLOSE, 240)) == 2021

Python代码参考

以下是Python代码示例,仅供参考。

import tushare as ts
import datetime
import talib

def select_stocks():
    res = []

    # 自选股
    stk_concepts = ['300024', '300024']

    # 除去停牌、ST、科创板、上市不足6个月的新股
    stk_basics = ts.get_stock_basics()
    stk_basics = stk_basics[stk_basics.index.isin(stk_concepts)]
    today_dt = datetime.datetime.today().strftime('%Y-%m-%d')
    stk_basics = stk_basics[(stk_basics['timeToMarket'] <= (today_dt - datetime.timedelta(days=120).strftime('%Y%m%d'))) & (stk_basics['name'].str.contains('ST') == False) & (stk_basics['market'] != '科创板')]

    for idx, row in stk_basics.iterrows():
        if row['outstanding'] <= 0 or row['totals'] <= 0 or row['circulating'] <= 0:
            continue

        try:
            # 公司市值数据
            mcap = row['totals'] * row['price']

            if mcap < 10000000000:
                continue

            # 行情数据
            hist_data = ts.get_k_data(idx, index=True, start='2020-01-01', retry_count=3, pause=None)
            if hist_data is None or len(hist_data) < 31:
                continue

            # RSI小于65
            rsi_threshold = 65
            rsi = talib.RSI(hist_data['close'].values)[-1]
            if rsi >= rsi_threshold:
                continue

            # 主升起动
            highest_high = talib.MAX(hist_data['high'].values, timeperiod=30)[-1]
            lowest_low = talib.MIN(hist_data['low'].values, timeperiod=30)[-1]
            highest_high_ref = talib.MAX(hist_data['high'].values, timeperiod=30)[-2]
            lowest_low_ref = talib.MIN(hist_data['low'].values, timeperiod=30)[-2]
            if highest_high != highest_high_ref or lowest_low != lowest_low_ref:
                continue

            # 2021年表现良好
            if not has_good_performance(hist_data):
                continue

            # 股票代码
            res.append({'code': idx})

        except Exception:
            continue

    return [x['code'] for x in res]

def has_good_performance(hist_data):
    return hist_data.iloc[-1]['close'] >= hist_data.iloc[0]['close'] * 1.2 and hist_data.iloc[-1]['volume'] >= hist_data.iloc[:-5]['volume'].mean() * 2

res = select_stocks()
print(res)

注:在使用该代码时,请遵守国家法律法规和相关规定,严禁私自开展证券投资活动,自行承担相应风险。

    ## 如何进行量化策略实盘?
    请把您优化好的选股语句放入文章最下面模板的选股语句中即可。

    select_sentence = '市值小于100亿' #选股语句。

    模板如何使用?

    点击图标右上方的复制按钮,复制到自己的账户即可使用模板进行回测。


    ## 如果有任何问题请添加 下方的二维码进群提问。
    ![94c5cde12014f99e262a302741275d05.png](http://u.thsi.cn/imgsrc/pefile/94c5cde12014f99e262a302741275d05.png)
收益&风险
源码

评论