0
# Volume Indicators
1
2
Volume-based technical indicators that analyze the relationship between price movements and trading volume. These indicators help identify buying and selling pressure, confirm price trends, and detect potential reversals by examining how volume relates to price action.
3
4
## Capabilities
5
6
### Accumulation/Distribution Index (ADI)
7
8
Acts as a leading indicator of price movements by measuring the flow of money into and out of a security.
9
10
```python { .api }
11
class AccDistIndexIndicator:
12
def __init__(self, high, low, close, volume, fillna=False):
13
"""
14
Accumulation/Distribution Index (ADI).
15
16
Parameters:
17
- high (Series): Dataset 'High' column
18
- low (Series): Dataset 'Low' column
19
- close (Series): Dataset 'Close' column
20
- volume (Series): Dataset 'Volume' column
21
- fillna (bool): If True, fill NaN values (default: False)
22
"""
23
24
def acc_dist_index(self):
25
"""Returns: Series with Accumulation/Distribution Index values"""
26
27
def acc_dist_index(high, low, close, volume, fillna=False):
28
"""Functional interface for Accumulation/Distribution Index"""
29
```
30
31
### On-Balance Volume (OBV)
32
33
Relates price and volume in the stock market by maintaining a running total of volume based on whether prices close higher or lower.
34
35
```python { .api }
36
class OnBalanceVolumeIndicator:
37
def __init__(self, close, volume, fillna=False):
38
"""
39
On-balance volume (OBV).
40
41
Parameters:
42
- close (Series): Dataset 'Close' column
43
- volume (Series): Dataset 'Volume' column
44
- fillna (bool): If True, fill NaN values (default: False)
45
"""
46
47
def on_balance_volume(self):
48
"""Returns: Series with On-balance volume values"""
49
50
def on_balance_volume(close, volume, fillna=False):
51
"""Functional interface for On-balance volume"""
52
```
53
54
### Chaikin Money Flow (CMF)
55
56
Measures the amount of Money Flow Volume over a specific period to assess buying and selling pressure.
57
58
```python { .api }
59
class ChaikinMoneyFlowIndicator:
60
def __init__(self, high, low, close, volume, window=20, fillna=False):
61
"""
62
Chaikin Money Flow (CMF).
63
64
Parameters:
65
- high (Series): Dataset 'High' column
66
- low (Series): Dataset 'Low' column
67
- close (Series): Dataset 'Close' column
68
- volume (Series): Dataset 'Volume' column
69
- window (int): Period for calculation (default: 20)
70
- fillna (bool): If True, fill NaN values (default: False)
71
"""
72
73
def chaikin_money_flow(self):
74
"""Returns: Series with Chaikin Money Flow values"""
75
76
def chaikin_money_flow(high, low, close, volume, window=20, fillna=False):
77
"""Functional interface for Chaikin Money Flow"""
78
```
79
80
### Force Index (FI)
81
82
Illustrates how strong the actual buying or selling pressure is by combining price and volume.
83
84
```python { .api }
85
class ForceIndexIndicator:
86
def __init__(self, close, volume, window=13, fillna=False):
87
"""
88
Force Index (FI).
89
90
Parameters:
91
- close (Series): Dataset 'Close' column
92
- volume (Series): Dataset 'Volume' column
93
- window (int): Period for smoothing (default: 13)
94
- fillna (bool): If True, fill NaN values (default: False)
95
"""
96
97
def force_index(self):
98
"""Returns: Series with Force Index values"""
99
100
def force_index(close, volume, window=13, fillna=False):
101
"""Functional interface for Force Index"""
102
```
103
104
### Ease of Movement (EoM, EMV)
105
106
Relates an asset's price change to its volume to identify the ease with which a price can move.
107
108
```python { .api }
109
class EaseOfMovementIndicator:
110
def __init__(self, high, low, volume, window=14, fillna=False):
111
"""
112
Ease of movement (EoM, EMV).
113
114
Parameters:
115
- high (Series): Dataset 'High' column
116
- low (Series): Dataset 'Low' column
117
- volume (Series): Dataset 'Volume' column
118
- window (int): Period for smoothing (default: 14)
119
- fillna (bool): If True, fill NaN values (default: False)
120
"""
121
122
def ease_of_movement(self):
123
"""Returns: Series with Ease of Movement values"""
124
125
def sma_ease_of_movement(self):
126
"""Returns: Series with Signal Ease of Movement (smoothed) values"""
127
128
def ease_of_movement(high, low, volume, window=14, fillna=False):
129
"""Functional interface for Ease of Movement"""
130
131
def sma_ease_of_movement(high, low, volume, window=14, fillna=False):
132
"""Functional interface for Signal Ease of Movement"""
133
```
134
135
### Volume-Price Trend (VPT)
136
137
Based on a running cumulative volume that adds or subtracts volume based on price changes.
138
139
```python { .api }
140
class VolumePriceTrendIndicator:
141
def __init__(self, close, volume, fillna=False, smoothing_factor=None, dropnans=False):
142
"""
143
Volume-price trend (VPT).
144
145
Parameters:
146
- close (Series): Dataset 'Close' column
147
- volume (Series): Dataset 'Volume' column
148
- fillna (bool): If True, fill NaN values (default: False)
149
- smoothing_factor (int, optional): Will smooth VPT with SMA if provided
150
- dropnans (bool): Drop NaNs after indicator calculated (default: False)
151
"""
152
153
def volume_price_trend(self):
154
"""Returns: Series with Volume-price trend values"""
155
156
def volume_price_trend(close, volume, fillna=False, smoothing_factor=None, dropnans=False):
157
"""Functional interface for Volume-price trend"""
158
```
159
160
### Negative Volume Index (NVI)
161
162
Focuses on days when volume decreases from the previous day, used to identify periods of smart money activity.
163
164
```python { .api }
165
class NegativeVolumeIndexIndicator:
166
def __init__(self, close, volume, fillna=False):
167
"""
168
Negative Volume Index (NVI).
169
170
Parameters:
171
- close (Series): Dataset 'Close' column
172
- volume (Series): Dataset 'Volume' column
173
- fillna (bool): If True, fill NaN values with 1000 (default: False)
174
"""
175
176
def negative_volume_index(self):
177
"""Returns: Series with Negative Volume Index values"""
178
179
def negative_volume_index(close, volume, fillna=False):
180
"""Functional interface for Negative Volume Index"""
181
```
182
183
### Money Flow Index (MFI)
184
185
Uses both price and volume to measure buying and selling pressure, often called the "volume-weighted RSI".
186
187
```python { .api }
188
class MFIIndicator:
189
def __init__(self, high, low, close, volume, window=14, fillna=False):
190
"""
191
Money Flow Index (MFI).
192
193
Parameters:
194
- high (Series): Dataset 'High' column
195
- low (Series): Dataset 'Low' column
196
- close (Series): Dataset 'Close' column
197
- volume (Series): Dataset 'Volume' column
198
- window (int): Period for calculation (default: 14)
199
- fillna (bool): If True, fill NaN values (default: False)
200
"""
201
202
def money_flow_index(self):
203
"""Returns: Series with Money Flow Index values (0-100 scale)"""
204
205
def money_flow_index(high, low, close, volume, window=14, fillna=False):
206
"""Functional interface for Money Flow Index"""
207
```
208
209
### Volume Weighted Average Price (VWAP)
210
211
Calculates the average price weighted by volume, providing a benchmark for intraday trading decisions.
212
213
```python { .api }
214
class VolumeWeightedAveragePrice:
215
def __init__(self, high, low, close, volume, window=14, fillna=False):
216
"""
217
Volume Weighted Average Price (VWAP).
218
219
Parameters:
220
- high (Series): Dataset 'High' column
221
- low (Series): Dataset 'Low' column
222
- close (Series): Dataset 'Close' column
223
- volume (Series): Dataset 'Volume' column
224
- window (int): Period for calculation (default: 14)
225
- fillna (bool): If True, fill NaN values (default: False)
226
"""
227
228
def volume_weighted_average_price(self):
229
"""Returns: Series with VWAP values"""
230
231
def volume_weighted_average_price(high, low, close, volume, window=14, fillna=False):
232
"""Functional interface for VWAP"""
233
```
234
235
## Usage Examples
236
237
### Using Class-Based API
238
239
```python
240
from ta.volume import MFIIndicator, OnBalanceVolumeIndicator
241
import pandas as pd
242
243
# Create indicators using classes
244
mfi = MFIIndicator(
245
high=df['High'],
246
low=df['Low'],
247
close=df['Close'],
248
volume=df['Volume'],
249
window=14
250
)
251
252
obv = OnBalanceVolumeIndicator(
253
close=df['Close'],
254
volume=df['Volume']
255
)
256
257
# Calculate indicator values
258
df['MFI'] = mfi.money_flow_index()
259
df['OBV'] = obv.on_balance_volume()
260
```
261
262
### Using Functional API
263
264
```python
265
from ta.volume import money_flow_index, on_balance_volume, chaikin_money_flow
266
267
# Calculate indicators using functions
268
df['MFI'] = money_flow_index(
269
df['High'], df['Low'], df['Close'], df['Volume'],
270
window=14, fillna=True
271
)
272
273
df['OBV'] = on_balance_volume(df['Close'], df['Volume'])
274
275
df['CMF'] = chaikin_money_flow(
276
df['High'], df['Low'], df['Close'], df['Volume'],
277
window=20
278
)
279
```
280
281
### Volume Analysis Workflow
282
283
```python
284
from ta.volume import *
285
import pandas as pd
286
287
# Comprehensive volume analysis
288
def analyze_volume_indicators(df):
289
# Trend confirmation indicators
290
df['OBV'] = on_balance_volume(df['Close'], df['Volume'])
291
df['ADI'] = acc_dist_index(df['High'], df['Low'], df['Close'], df['Volume'])
292
293
# Momentum indicators with volume
294
df['MFI'] = money_flow_index(df['High'], df['Low'], df['Close'], df['Volume'])
295
df['CMF'] = chaikin_money_flow(df['High'], df['Low'], df['Close'], df['Volume'])
296
297
# Price-volume relationship
298
df['VWAP'] = volume_weighted_average_price(df['High'], df['Low'], df['Close'], df['Volume'])
299
df['Force_Index'] = force_index(df['Close'], df['Volume'])
300
301
return df
302
303
# Apply to your data
304
df_with_volume = analyze_volume_indicators(df)
305
```