(同花顺量化)10日涨幅大于0小于35_、今日均线向上发散、rsi小于65

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

问财量化选股策略逻辑

选股逻辑:选取RSI小于65、今日均线向上发散、同时10日涨幅大于0小于35的股票。

选股逻辑分析

该选股逻辑综合考虑股票的价格短期波动情况、均线走势以及最近一段时间内的涨幅情况,选出的股票具有一定的投资机会和上涨潜力。

有何风险?

该选股逻辑存在选到短期投机性股票的可能性,选股筛选规则可能与市场一些时间段趋势摆动相似,结果可能具有较大的随机性。

如何优化?

除了上述风险之外,我们可以考虑增加其他股票指标,如市盈率、市净率、股息率等,以综合评价股票投资价值。同时,该选股逻辑研究了很短期内的股票波动情况,可以根据实际情况,加大时间跨度,更加充分地研究股票历史趋势,避免盲目跟随短期趋势造成的风险。

最终的选股逻辑

选取RSI小于65、今日均线向上发散、同时10日涨幅大于0小于35的股票,并平均分配资金。

同花顺指标公式代码参考

  • RSI: RSI(14)
  • MA: MA(N)

Python代码参考

import pandas as pd
import tushare as ts
import talib

def sort_by_turnover(stock_df):
    today_all_data = ts.get_today_all()
    today_all_data['流通市值'] = today_all_data['nmc'] / 100000000
    stock_df['流通市值'] = today_all_data['流通市值'][stock_df['股票代码'].apply(lambda x: x[2:])]
    stock_df = stock_df[stock_df['流通股本'] <= 5500000000]
    stock_df.sort_values(by='流通市值', ascending=False, inplace=True)
    return stock_df

def get_stock_list(rsi_threshold=65, ma_today_length=1, ma_short_length=10, ma_long_length=60, increase_range=(0, 35), top_n=5):
    stock_list = pd.DataFrame(columns=['股票代码', '名称', '流通股本'])
    for _, row in ts.get_today_all().iterrows():
        symbol = row['code']
        if symbol.startswith('60'):
            if row['code'][0] == '6':
                symbol = 'sh' + symbol
            else:
                symbol = 'sz' + symbol
            try:
                kline_today = ts.get_k_data(symbol=symbol, start=datetime.date.today()-datetime.timedelta(days=1), end=datetime.date.today())
                if len(kline_today) == 0:
                    continue
                close = kline_today['close']
                if close.iloc[-1] <= talib.MA(close, timeperiod=ma_today_length).iloc[-1]:
                    continue
                if abs(kline_today.iloc[0]['open'] - talib.MA(close, timeperiod=ma_short_length).iloc[-1]) > 0.02 * row['pre_close']:
                    continue
                ma_increase = (close.iloc[-1] / talib.MA(close, timeperiod=ma_long_length).iloc[-1] - 1) * 100
                if ma_increase < increase_range[0] or ma_increase > increase_range[1]:
                    continue
                if RSI(close, timeperiod=14)[-1] > rsi_threshold:
                    continue
                if not symbol.startswith('60'):
                    continue
                stock_list = stock_list.append({'股票代码': symbol, '名称': row['name'], '流通股本': row['totals'] * 10000}, ignore_index=True)
            except:
                continue

    stock_list = sort_by_turnover(stock_list)[:100]
    return stock_list[:top_n]
    ## 如何进行量化策略实盘?
    请把您优化好的选股语句放入文章最下面模板的选股语句中即可。

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

    模板如何使用?

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


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

评论