问财量化选股策略逻辑
在问财量化选股策略中,我们使用了至少5根均线重合的股票作为筛选条件。具体来说,我们选择将5日、10日、20日、60日和120日均线相交的股票纳入筛选范围。这个策略的目的是寻找那些在不同时间周期内都处于趋势中的股票,从而提高投资组合的稳定性和收益率。
选股逻辑分析
这个策略的优点在于它能够有效地筛选出那些趋势明显的股票。当5根均线重合时,通常意味着股票的价格走势在一个相对稳定的区域内,而且未来可能会出现趋势性的变化。另外,这个策略也能够过滤掉那些短期波动较大的股票,从而提高投资组合的稳定性。
然而,这个策略也存在一些风险。首先,如果市场出现极端行情,可能会导致一些股票的价格在短时间内出现大幅波动,从而使得筛选出的股票不符合我们的要求。其次,如果市场走势过于复杂,可能会使得我们的策略无法准确地预测股票的趋势,从而导致投资组合的收益率受到影响。
如何优化?
为了优化这个策略,我们可以考虑以下几个方面:
-
增加筛选条件的数量:除了5根均线重合之外,我们还可以考虑加入其他筛选条件,例如市盈率、市净率等,以更好地筛选出那些具有投资价值的股票。
-
调整筛选周期:我们可以根据不同的市场环境和投资风格,调整筛选周期的长短,以更好地适应市场变化。
-
使用量化交易工具:我们可以使用一些量化交易工具,例如Quantopian、Zipline等,来自动执行这个策略,从而提高执行效率和准确性。
最终的选股逻辑
在最终的选股逻辑中,我们使用了至少5根均线重合的股票作为筛选条件,并结合了市盈率、市净率等其他筛选条件。我们还根据不同的市场环境和投资风格,调整了筛选周期的长短。最后,我们使用了量化交易工具来自动执行这个策略,从而提高执行效率和准确性。
以下是这个策略的python代码参考:
import pandas as pd
from talib import *
def get_rolling_average(data, n):
"""计算n日的滚动平均值"""
result = pd.Series(data).rolling(n).mean()
return result
def get_rolling_std(data, n):
"""计算n日的滚动标准差"""
result = pd.Series(data).rolling(n).std()
return result
def get_intersection(ma1, ma2, ma3, ma4, ma5):
"""获取5根均线的交点"""
if ma1[-1] == ma2[-1] == ma3[-1] == ma4[-1] == ma5[-1]:
return ma1[-1]
else:
return None
def get_intersection_prices(prices):
"""获取所有股票的交点价格"""
intersection_prices = []
for i in range(len(prices)):
ma1 = prices[i:i+5]
ma2 = prices[i+1:i+6]
ma3 = prices[i+2:i+7]
ma4 = prices[i+3:i+8]
ma5 = prices[i+4:i+9]
intersection = get_intersection(ma1, ma2, ma3, ma4, ma5)
if intersection is not None:
intersection_prices.append(intersection)
return intersection_prices
def get_top_intersection_prices(prices, n):
"""获取前n个交点价格"""
intersection_prices = get_intersection_prices(prices)
sorted_prices = sorted(intersection_prices, reverse=True)
return sorted_prices[:n]
def get筛选条件(prices, n):
"""获取n日的筛选条件"""
intersection_prices = get_top_intersection_prices(prices, n)
ma1 = prices.rolling(n).mean()
ma2 = prices.rolling(n).std()
return ma1, ma2
def get筛选结果(prices, ma1, ma2):
"""根据筛选条件筛选股票"""
filtered_prices = prices[prices.index.isin(get_intersection_prices(prices, 5))]
filtered_prices = filtered_prices[filtered_prices.index >= ma1[-1]]
filtered_prices = filtered_prices[filtered_prices.index <= ma2[-1]]
return filtered_prices
def get_top_n筛选结果(prices, n):
"""获取前n个筛选结果"""
filtered_prices = get筛选结果(prices, ma1, ma2)
sorted_prices = sorted(filtered_prices, reverse=True)
return sorted_prices[:n]
如何进行量化策略实盘?
请把您优化好的选股语句放入文章最下面模板的选股语句中即可。
select_sentence = '市值小于100亿' #选股语句。
模板如何使用?
点击图标右上方的复制按钮,复制到自己的账户即可使用模板进行回测。