情绪指标,简称 ARBR 或 BRAR,由人气指标(AR)和意愿指标(BR)构成。 AR 和 BR 都是对通过对历史股价走势的分析,反映市场当前情况下多空双方的力量强弱对比,推断市场交易情绪,从而对趋势的形成与反转作出预判。
AR刻画的是市场交易人气,人气越旺,股价越高,而股价攀升带来的赚钱效应又会不断带动人气上升,但是物极必反。当AR值升高至一定限度时,代表能量已经消耗殆尽,缺乏推升力道的股价,出现反转概率增大。BR反映的是市场交易意愿,以“反市场心理”为基础,当市场人气狂热时卖出,人气悲观时买进。
1.计算原理 AR:人气指标是以当天开市价为基础,以当天开市价分别比较当天最高、最低价,通过一定时期内开市价在报价中的地位,反映市场买卖的人气。 一般设定的周期为14日或26日。
BR:意愿指标是以昨日收市价为基础,分别与当日最高,最低价相比,通过一定时期收市价在报价中的地位,反映市场买卖意愿的程度。
talib_arbr.py
# -*- coding: utf-8 -*-
import os, sys
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import tushare as ts
import talib as ta
if len(sys.argv) ==2:
code = sys.argv[1]
else:
print('usage: python talib_arbr.py stockcode ')
sys.exit(1)
if len(code) !=6:
print('stock code length: 6')
sys.exit(2)
df = ts.get_k_data(code)
if df.empty == True:
print(" df is empty ")
sys.exit(2)
df = df[ df['date'] > '2021-01-01']
if len(df) < 60:
print(len(df)," < 60")
sys.exit(2)
df = df[['open','high','low','close']]
print(df.tail())
df['HO']=df.high-df.open
df['OL']=df.open-df.low
df['HCY']=df.high-df.close.shift(1)
df['CYL']=df.close.shift(1)-df.low
# 计算AR、BR指标
df['AR']=ta.SUM(df.HO, timeperiod=26)/ta.SUM(df.OL, timeperiod=26)*100
df['BR']=ta.SUM(df.HCY, timeperiod=26)/ta.SUM(df.CYL, timeperiod=26)*100
df = df[['close','AR','BR']].dropna()
df.reset_index(inplace=True)
# 正常显示画图时出现的中文和负号
from pylab import mpl
mpl.rcParams['font.sans-serif']=['SimHei']
mpl.rcParams['axes.unicode_minus']=False
# 对价格和 AR,BR进行可视化
fig,axes = plt.subplots(2,1)
df['close'].plot(ax=axes[0], grid=True, title=code, color='r')
plt.xlabel('AR,BR')
df[['AR','BR']].plot(ax=axes[1], grid=True)
plt.legend(loc='best', shadow=True)
plt.show()
运行 python talib_brar.py 000661
2. 使用BRAR指标,如何找到买入点?
若AR<50,BR<40,能量已累积爆发力,行情将起死回生,应买入.
talib_brar.py
# -*- coding: utf-8 -*-
import os, sys
import pandas as pd
import numpy as np
import tushare as ts
import talib as ta
if len(sys.argv) ==2:
code = sys.argv[1]
else:
print('usage: python talib_brar.py stockcode ')
sys.exit(1)
if len(code) !=6:
print('stock code length: 6')
sys.exit(2)
df = ts.get_k_data(code)
if df.empty == True:
print(" df is empty ")
sys.exit(2)
df = df[ df['date'] > '2021-01-01']
if len(df) <60:
print(len(df)," < 60")
sys.exit(2)
df = df[['date','open','high','low','close']]
#print(df.tail())
df['HO']=df.high-df.open
df['OL']=df.open-df.low
df['HCY']=df.high-df.close.shift(1)
df['CYL']=df.close.shift(1)-df.low
# 计算AR、BR指标
df['AR']=ta.SUM(df.HO, timeperiod=26)/ta.SUM(df.OL, timeperiod=26)*100
df['BR']=ta.SUM(df.HCY, timeperiod=26)/ta.SUM(df.CYL, timeperiod=26)*100
df = df.dropna()
df.index = range(len(df))
print('df.len=',len(df))
print(df.tail())
alist =[] # 求买入点日期
for i in range(len(df)-30, len(df)):
if df.loc[i, 'AR'] <50 and df.loc[i, 'BR'] <40:
alist.append(i)
print(list(df.iloc[i])[0:5])
print('alist=',alist)
运行 python talib_brar.py 000661
['2022-01-24', 172.11, 180.0, 165.92, 171.24]
['2022-01-25', 167.08, 170.4, 164.0, 164.11]
['2022-01-27', 168.48, 171.55, 165.51, 169.83]
alist= [231, 232, 234]
参考:?【手把手教你】Python量化股票市场情绪指标ARBR - 知乎
|