Bootstrap

talib技术指标分析(1):AD Chaikin A/D Line

AD指标(Accumulation/Distribution)是一种用于衡量资金流入和流出的指标,它基于成交量和价格的关系。AD指标通过将成交量乘以价格变化的比率来计算资金流入和流出的情况。当价格上涨且成交量增加时,AD指标会增加,表示资金流入;当价格下跌且成交量增加时,AD指标会减少,表示资金流出。

AD指标的计算公式如下:

AD = AD_prev + ((close - low) - (high - close)) / (high - low) * volume

AD_prev                前一天的AD值

close                      当天的收盘价

low                        当天的最低价

high                       当天的最高价

volume                  当天的成交量。

以btc日线为例获取k线数据

symbol = 'BTCUSDT'
interval = "1d"
date = client_umf.klines(symbol=symbol, interval=interval)

df = pd.DataFrame(date,
				  columns=['open_time', 'open', 'high', 'low', 'close', 'volume', 'close_time', 'quote_volume', 'count',
						   'taker_buy_volume', 'taker_buy_quote_volume', 'ignore'])
df["time"] = df.open_time.map(lambda x: timeStamp_to_time(x / 1000))
df['date'] = pd.to_datetime(df['time']).dt.strftime('%Y-%m-%d')
import talib
df['ad'] = talib.AD(df['high'], df['low'], df['close'], df['volume'])#AD指标计算
df['diff'] = df['ad'] - df['ad'].shift(1)#将减前一天的值后:
df.dropna()
print(df[['high', 'low', 'close', 'volume', 'ad', 'diff']].tail(10))
from matplotlib import pyplot as plt
plt.plot(df['date'], df['diff'])
plt.show()
    date      high       low     close      volume           diff
2024-01-15  43376.00  41720.00  42515.00  240059.141   -9567.574460
2024-01-16  43589.00  42050.00  43133.00  287207.233  117010.354185
2024-01-17  43198.00  42200.00  42783.40  209396.081   35416.892257
2024-01-18  42932.30  40673.60  41323.10  335080.756 -142372.604389
2024-01-19  42197.00  40300.00  41662.20  345941.730  150886.761941
2024-01-20  41883.50  41453.60  41691.80   95866.062   10369.322826
2024-01-21  41880.90  41500.00  41580.00   67035.552  -38876.748324
2024-01-22  41692.30  39402.00  39567.00  459024.106 -392885.191893
2024-01-23  40172.70  38545.00  39890.00  414373.386  270436.104901
2024-01-24  40560.60  39550.00  40101.10  204579.713   18542.946478

diff为负表示表示资金流出,diff为正表示表示资金流入,由ad指标计算出资金流入流出情况

;