0%

JoinQuant量化策略开发-基本指标分析

记录一下炒股用到的指标,主要是介绍原理和计算公式,包括不同的库可能计算方式不一样,整理了一下网上的资料。

CCI指标

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
def CCI(stock, timeperiod=14):
'''
计算CCI指标
'''
cci = 0
security_data = attribute_history(stock, timeperiod*2, '1d',['close','high','low'] , df=True)
# attribute_history的第二个参数是返回的行数,筛选了双休日等非交易日的日期
nan_count = list(np.isnan(security_data['close'])).count(True)
if nan_count == len(security_data['close']):
log.info("股票 %s 输入数据全是 NaN,该股票可能已退市或刚上市,返回 NaN 值数据。" %stock)
cci[stock] = array([np.nan])
else:
close_CCI = security_data['close']
high_CCI = security_data['high']
low_CCI = security_data['low']
cci = talib.CCI(high_CCI, low_CCI, close_CCI, timeperiod)
# print(type(cci))
# print(50*'@')
return cci

RSI指标

1
2
3
4
5
6
7
8
9
def RSI(stock, timeperiod=14):
'''
计算RSI指标
'''
#print("正在进入RSI函数")
security_data = attribute_history(stock, timeperiod*2, '1d', ['close'] , df=True)
rsi = talib.RSI(security_data['close'], timeperiod)
#print("RSI是:", rsi)
return rsi

KDJ指标

1
2
3
4
5
6
7
8
9
10
11
12
13
14
def KDJ(stock, timeperiod=14):
'''
计算KDJ指标
'''
security_data = attribute_history(stock, timeperiod*2, '1d', ['close', 'high', 'low'], df=True)
k, d = talib.STOCH(security_data['high'].values,
security_data['low'].values,
security_data['close'].values,
fastk_period=9,
slowk_period=2*3-1,
slowk_matype=1,
slowd_period=2*3-1,
slowd_matype=1)
return k, d

KDJ使用talib库计算的时候需要注意一下参数的设置,如果使用默认参数,则算出来的数值与通达信等软件上的不一样,具体可以参考:

https://xueqiu.com/1747761477/198676825

If you like my blog, please donate for me.