(同花顺量化)500日内至少2次涨停_、PE_0、至少5根均线重合的股票

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

问财量化选股策略逻辑

1. 至少5根均线重合的股票

首先,我们需要找到至少5根均线重合的股票。这可以通过计算股票的移动平均线来实现。具体来说,我们可以计算股票的5日、10日、20日、50日和200日移动平均线。如果这些移动平均线在某个点上重合,那么我们可以认为该股票至少有5根均线重合。

代码实现如下:

def find_crossing_moving_average_prices(prices):
    # 计算5日、10日、20日、50日和200日移动平均线
    moving_average_prices = pd.Series(prices.rolling(window=5).mean(), name='5MA')
    moving_average_prices = pd.Series(prices.rolling(window=10).mean(), name='10MA')
    moving_average_prices = pd.Series(prices.rolling(window=20).mean(), name='20MA')
    moving_average_prices = pd.Series(prices.rolling(window=50).mean(), name='50MA')
    moving_average_prices = pd.Series(prices.rolling(window=200).mean(), name='200MA')
    
    # 计算移动平均线的交叉点
    crossing_points = pd.DataFrame()
    for i in range(1, len(prices)):
        if moving_average_prices.iloc[i] > moving_average_prices.iloc[i-1] and moving_average_prices.iloc[i] > moving_average_prices.iloc[i+1]:
            crossing_points = crossing_points.append(prices.iloc[i])
    
    # 返回至少5根均线重合的股票
    return crossing_points

2. PE>0

接下来,我们需要找到PE>0的股票。PE(市盈率)是指股票价格与每股收益的比率。通常情况下,PE越低越好,因为这意味着股票的价格相对较低,而收益相对较高。因此,我们希望找到PE>0的股票。

代码实现如下:

def find_p_e_prices(prices):
    # 计算PE
    pe = prices / prices.rolling(window=12).mean()
    
    # 返回PE>0的股票
    return pe[pe > 0]

3. 500日内至少2次涨停

最后,我们需要找到500日内至少

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

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

模板如何使用?

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


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

评论