Volatility
Volatility indicators measure the degree of price variation in financial instruments. They help traders assess market uncertainty, risk levels, and potential breakout conditions. OpenAlgo provides a comprehensive collection of volatility indicators optimized for performance and accuracy.
Import Statement
from openalgo import ta
from openalgo import api
# Initialize API client
client = api(api_key='your_api_key_here', host='http://127.0.0.1:5000')
# Get sample data
df = client.history(symbol="SBIN", exchange="NSE", interval="5m",
start_date="2025-04-01", end_date="2025-04-08")Available Volatility Indicators
Average True Range (ATR)
ATR measures market volatility by decomposing the entire range of an asset price for that period. It's one of the most widely used volatility indicators.
Usage
atr_result = ta.atr(high, low, close, period=14)Parameters
high (array-like): High prices
low (array-like): Low prices
close (array-like): Closing prices
period (int, default=14): Number of periods for ATR calculation
Returns
array: ATR values in the same format as input
Example
Bollinger Bands
Bollinger Bands consist of a middle band (SMA) and two outer bands that are standard deviations away from the middle band, used to identify overbought and oversold conditions.
Usage
Parameters
data (array-like): Price data (typically closing prices)
period (int, default=20): Number of periods for moving average and standard deviation
std_dev (float, default=2.0): Number of standard deviations for the bands
Returns
tuple: (upper_band, middle_band, lower_band) arrays
Example
Keltner Channel
Keltner Channels are volatility-based envelopes set above and below an exponential moving average, using ATR to set channel distance.
Usage
Parameters
high (array-like): High prices
low (array-like): Low prices
close (array-like): Closing prices
ema_period (int, default=20): Period for the EMA calculation
atr_period (int, default=10): Period for the ATR calculation
multiplier (float, default=2.0): Multiplier for the ATR
Returns
tuple: (upper_channel, middle_line, lower_channel) arrays
Example
Donchian Channel
Donchian Channels are formed by taking the highest high and lowest low of the last n periods, providing dynamic support and resistance levels.
Usage
Parameters
high (array-like): High prices
low (array-like): Low prices
period (int, default=20): Number of periods for the channel calculation
Returns
tuple: (upper_channel, middle_line, lower_channel) arrays
Example
Chaikin Volatility
Chaikin Volatility measures the rate of change of the trading range, indicating periods of increasing or decreasing volatility.
Usage
Parameters
high (array-like): High prices
low (array-like): Low prices
ema_period (int, default=10): Period for EMA of high-low range
roc_period (int, default=10): Period for rate of change calculation
Returns
array: Chaikin Volatility values
Example
Normalized Average True Range (NATR)
NATR is ATR expressed as a percentage of closing price, making it useful for comparing volatility across different price levels.
Usage
Parameters
high (array-like): High prices
low (array-like): Low prices
close (array-like): Closing prices
period (int, default=14): Period for ATR calculation
Returns
array: NATR values (percentage)
Example
Relative Volatility Index (RVI)
RVI applies the RSI calculation to standard deviation instead of price changes, measuring volatility momentum.
Usage
Parameters
data (array-like): Price data (typically closing prices)
stdev_period (int, default=10): Period for standard deviation calculation
rsi_period (int, default=14): Period for RSI calculation
Returns
array: RVI values (0-100 range)
Example
Ultimate Oscillator
Ultimate Oscillator combines short, medium, and long-term price action into one oscillator, incorporating volatility analysis.
Usage
Parameters
high (array-like): High prices
low (array-like): Low prices
close (array-like): Closing prices
period1 (int, default=7): Short period
period2 (int, default=14): Medium period
period3 (int, default=28): Long period
Returns
array: Ultimate Oscillator values (0-100 range)
Example
True Range
True Range measures volatility that accounts for gaps between periods.
Usage
Parameters
high (array-like): High prices
low (array-like): Low prices
close (array-like): Closing prices
Returns
array: True Range values
Example
Mass Index
Mass Index uses the high-low range to identify trend reversals based on range expansion.
Usage
Parameters
high (array-like): High prices
low (array-like): Low prices
length (int, default=10): Period for sum calculation
Returns
array: Mass Index values
Example
Bollinger Bands %B
%B shows where price is in relation to the Bollinger Bands, with 1 indicating price at upper band and 0 at lower band.
Usage
Parameters
data (array-like): Price data (typically closing prices)
period (int, default=20): Period for moving average and standard deviation
std_dev (float, default=2.0): Number of standard deviations for the bands
Returns
array: %B values
Example
Bollinger Bandwidth
Bollinger Bandwidth measures the width of the Bollinger Bands, useful for identifying volatility squeezes.
Usage
Parameters
data (array-like): Price data (typically closing prices)
period (int, default=20): Period for moving average and standard deviation
std_dev (float, default=2.0): Number of standard deviations for the bands
Returns
array: Bandwidth values
Example
Chandelier Exit
Chandelier Exit is a trailing stop-loss technique that follows price action using highest/lowest values and ATR.
Usage
Parameters
high (array-like): High prices
low (array-like): Low prices
close (array-like): Closing prices
period (int, default=22): Period for highest/lowest and ATR calculation
multiplier (float, default=3.0): ATR multiplier
Returns
tuple: (long_exit, short_exit) arrays
Example
Historical Volatility
Historical Volatility measures the standard deviation of logarithmic returns over a specified period.
Usage
Parameters
close (array-like): Closing prices
length (int, default=10): Period for volatility calculation
annual (int, default=365): Annual periods for scaling
per (int, default=1): Timeframe periods (1 for daily/intraday, 7 for weekly+)
Returns
array: Historical volatility values (annualized percentages)
Example
Ulcer Index
Ulcer Index measures downside risk by calculating the depth and duration of drawdowns from recent highs.
Usage
Parameters
data (array-like): Price data (typically closing prices)
length (int, default=14): Period for highest calculation
smooth_length (int, default=14): Period for smoothing squared drawdowns
signal_length (int, default=52): Period for signal line calculation
signal_type (str, default="SMA"): Signal smoothing type ("SMA" or "EMA")
return_signal (bool, default=False): Whether to return signal line
Returns
array or tuple: Ulcer Index values (and signal if return_signal=True)
Example
STARC Bands
STARC Bands use a Simple Moving Average and Average True Range to create volatility-based bands.
Usage
Parameters
high (array-like): High prices
low (array-like): Low prices
close (array-like): Closing prices
ma_period (int, default=5): Period for SMA calculation
atr_period (int, default=15): Period for ATR calculation
multiplier (float, default=1.33): ATR multiplier
Returns
tuple: (upper_band, middle_line, lower_band) arrays
Example
Complete Example: Volatility Analysis
Common Use Cases
Volatility Breakouts: Use BB Width and Mass Index to identify low volatility periods before breakouts
Risk Management: Use ATR and NATR for position sizing and stop-loss placement
Overbought/Oversold: Use BB %B and RVI to identify extreme price levels
Trend Strength: Higher volatility often accompanies strong trends
Market Regime: Compare different volatility measures to understand market conditions
Performance Tips
Efficient Calculations: Use vectorized operations for multiple timeframes
Memory Management: Calculate only needed indicators to save memory
Parameter Optimization: Test different periods for your specific market and timeframe
Combination Analysis: Use multiple volatility indicators together for confirmation
Last updated
Was this helpful?