0%

腾落线

The advance–decline line is a plot of the cumulative sum of the daily difference between the number of issues advancing, i.e., above the previous day's closing price, and the number of issues declining in a particular stock market index. Thus it moves up when the index contains more advancing than declining issues, and moves down when there are more declining than advancing issues. The formula for ADL is: \[ {\rm \displaystyle ADline=today's\ advancing\ stocks-today's\ declining\ stocks+yesterday's\ AD\ line\ value} \]

The Advance/Decline Line formula could be applied to volume of the advancing and declining stocks. \[ {\rm \displaystyle AD\ volume\ line=Advanced\ Volume-Declined\ Volume+yesterday's\ AD\ volume\ line} \] The ADL is one of the oldest indicators based on the Advance-Decline Data and it was the most popular of all internal indicators.

如下图,沪深300指数日线计算的腾落线,指标显示在2020-07单日暴涨之后,指数的普涨行情就结束了,进入选股的行情了,“权重股保持指数的虚假点位”。 adline

JoinQuant Notebook

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# 设置cell宽度
from IPython.core.display import display, HTML
display(HTML("<style>.container { width:100% !important; }</style>"))
from warnings import filterwarnings
filterwarnings('ignore')

from numpy import maximum, minimum
from tqdm import tqdm
from pandas import DataFrame
from matplotlib import pyplot
from matplotlib.pylab import date2num
import matplotlib.ticker as ticker
import matplotlib.pyplot as plt
plt.rcParams["font.sans-serif"]=["SimHei"] #设置字体
plt.rcParams["axes.unicode_minus"]=False #该语句解决图像中的“-”负号的乱码问题


def plot_adline(index_symbol = "000300.XSHG", start_date="2021-01-01", end_date="2021-12-22"):
cal_dates = get_price(index_symbol, start_date=start_date, end_date=end_date).dropna().index.tolist()
cal_dates = [i.strftime("%Y-%m-%d") for i in cal_dates]
cal_dates.sort()

ad_df = []
for date in tqdm(cal_dates):
universe = get_index_stocks(index_symbol, date=date)

data = get_price(security=universe, end_date=date, count=2, fields="close", panel=False)
data = data.sort_values("time")
size = int(data.shape[0]/2)
pre_data = data.iloc[:size]
data = data.iloc[size:]

data = data.set_index("code")["close"]
pre_data = pre_data.set_index("code")["close"]
diff = data - pre_data
a = sign(maximum(diff, 0)).sum()
d = sign(minimum(diff, 0)).sum()
ad_df.append([date, a, d, a+d])

ad_df = DataFrame(ad_df)
ad_df.columns = ["date", "a", "d", "diff"]
ad_df["ad_line"] = ad_df["diff"].cumsum()

ad_df = ad_df.set_index("date")
index_price = get_price(index_symbol, start_date=cal_dates[0], end_date=cal_dates[-1])["close"]
index_price.index = index_price.index.strftime("%Y-%m-%d")
ad_df["index"] = index_price

fig = pyplot.figure(figsize=(30, 6))
ax = fig.add_subplot(111)
ad_df["index"].reset_index(drop=True).plot(ax=ax)
ax = ax.twinx()
ad_df["ad_line"].reset_index(drop=True).plot(ax=ax, color="r", linestyle="-")

ax.xaxis.set_major_locator(ticker.MultipleLocator(120))
date_tickers = ad_df.index.tolist()
ax.xaxis.set_major_formatter(ticker.FuncFormatter(lambda x, y: "" if (x<0 or x>len(date_tickers)-1) else date_tickers[int(x)]))
pyplot.xlim(0, ad_df.shape[0])
pyplot.title("Index Symbol: {}".format(index_symbol))
pyplot.grid()
return ad_df

data = plot_adline("000300.XSHG", "2013-01-01", "2021-12-23")