问财量化选股策略逻辑
首先,我们需要找到至少5根均线重合的股票。这可以通过使用 rollapply() 函数和 sum() 函数来实现。例如,我们可以使用以下代码找到所有5天、10天、20天、50天和200天移动平均线重合的股票:
import talib
def find_converging_moving_averages(prices, fast_length, slow_length):
# Calculate the fast and slow moving averages
fast_ma = talib.MA(prices, fast_length)
slow_ma = talib.MA(prices, slow_length)
# Calculate the difference between the fast and slow moving averages
diff = fast_ma - slow_ma
# Check if the difference is close to zero
if abs(diff[-1]) < 0.001:
return True
# Check if the fast moving average is greater than the slow moving average
if fast_ma[-1] > slow_ma[-1]:
return True
# Check if the fast moving average is less than the slow moving average
if fast_ma[-1] < slow_ma[-1]:
return True
# If none of the above conditions are met, return False
return False
接下来,我们需要找到现量大于1万手的股票。这可以通过使用 sum() 函数和 abs() 函数来实现。例如,我们可以使用以下代码找到所有现量大于1万手的股票:
def find_stock_with_high_volume(prices):
# Calculate the sum of the absolute values of the prices
volume = sum(abs(prices))
# Check if the volume is greater than 10000
if volume > 10000:
return True
# If the volume is less than or equal to 10000, return False
return False
最后,我们需要找到高开、竞价涨幅>-2<5的股票。这可以通过使用 shift() 函数和 abs() 函数来实现。例如,我们可以使用以下代码找到所有高开、竞价涨幅>-2<5的股票:
def find_stocks_with_positive_pre_open_price_change(prices):
# Calculate the shift of the prices
shifted_prices = prices.shift()
# Calculate the absolute value of the shift
price_change = abs(shifted_prices)
# Check if the price change is greater than -2 and less than or equal to 5
if price_change > -2 and price_change <= 5:
return True
# If the price change is not within the specified range, return False
return False
选股逻辑分析
以上三个逻辑可以组合成一个综合的逻辑,以筛选出符合要求的股票。首先,我们将找到所有5天、10天、20天、50天和200天移动平均线重合的股票。然后,我们将找到所有现量大于1万手的股票。最后,我们将找到所有高开、竞价涨幅>-2<5的股票。如果所有条件都满足,则该股票将被选中。
有何风险?
该策略可能无法准确预测股票的未来表现。移动平均线可能会被噪音和异常值所影响,导致其无法准确反映股票的趋势。现量和价格变化也可能会受到市场波动和其他因素的影响,导致其无法准确反映股票的真实价值。此外,高开、竞价涨幅>-2<5的股票可能只是短暂的高开,而不是真正的上涨趋势。
如何优化?
为了优化该策略,我们可以考虑使用更多的移动平均线来计算价格趋势。例如,我们可以使用60天、90天和180天移动平均线来更好地反映股票的趋势。此外,我们还可以考虑使用其他技术指标来预测股票的未来表现,例如收盘价和成交量。最后,我们还可以考虑使用更多的数据来分析股票,例如财务数据和行业数据,以更好地了解股票的真实价值。
最终的选股逻辑
以下是最终的选股逻辑:
def final_selection(prices, fast_length, slow_length, volume_threshold, open_change_threshold):
# Check if the prices have at least 5 days of data
if len(prices) < 5:
return False
# Check if the prices have at least 5 days of data with a non-zero volume
if len(prices[prices > 0]) < 5:
return False
# Check if the prices have at least 5 days of data with a positive pre-open price change
if len(prices[prices > prices.shift()]) < 5:
return False
# Check if the prices have at least 5 days of data with
## 如何进行量化策略实盘?
请把您优化好的选股语句放入文章最下面模板的选股语句中即可。
select_sentence = '市值小于100亿' #选股语句。
模板如何使用?
点击图标右上方的复制按钮,复制到自己的账户即可使用模板进行回测。
## 如果有任何问题请添加 下方的二维码进群提问。


