OHLCV Features¶
Overview¶
The OHLCV feature block derives return, volatility, trend, and price-dynamics features from daily underlying price data. These features operate only on canonical underlying daily data and do not depend on option-level information, implied volatility surfaces, or external joins. All computations are deterministic and strictly causal. The OHLCV block is typically the foundational feature set used in downstream modeling.
Required Input Columns¶
The following canonical columns must be present in the input DataFrame:
| Column Name | Description |
|---|---|
px_open |
Opening price of the underlying |
px_high |
Daily high price |
px_low |
Daily low price |
px_close |
Closing price |
volume |
Daily traded volume |
All prices are assumed to be positive and adjusted consistently.
Produced Feature Columns¶
Returns & Gaps¶
| Feature | Description |
|---|---|
ret_1d |
Close-to-close log return |
overnight_ret |
Simple overnight return (open vs previous close) |
gap_size |
Absolute overnight gap normalized by prior close |
Realized Volatility¶
All volatility measures are annualized assuming 252 trading days.
| Feature | Description |
|---|---|
realized_vol_21d |
Rolling close-to-close realized volatility |
parkinson_vol_21d |
Parkinson high–low volatility estimator |
garman_klass_vol_21d |
Garman–Klass OHLC volatility estimator |
yang_zhang_vol_21d |
Yang–Zhang volatility estimator |
Volatility of Volatility¶
| Feature | Description |
|---|---|
vol_of_vol_21d |
Rolling volatility of realized volatility |
Trend & Momentum¶
| Feature | Description |
|---|---|
ema_10 |
Exponential moving average (fast) |
ema_21 |
Exponential moving average (slow) |
bollinger_pct_b |
Normalized position within Bollinger Bands |
trend_up |
Directional trend indicator (+1, 0, −1) |
How to Call This Feature Block¶
Recommended (Public API)¶
Use the public feature API when working with canonical underlying data:
from ocf.features.api import ohlcv_features
features = ohlcv_features(underlying_daily)
This validates the input schema and guarantees a stable output contract.
Direct Builder Access (Advanced)¶
For advanced or internal usage, the feature builder can be called directly:
from ocf.features.ohlcv import build_ohlcv_features
features = build_ohlcv_features(
underlying_daily,
vol_window=21,
ema_fast=10,
ema_slow=21,
bb_window=20,
)
This bypasses schema validation and is intended for controlled environments or testing.
As Part of the Composite Feature Set¶
The OHLCV block is included automatically when using the composite feature API:
from ocf.features.api import underlying_features
features = underlying_features(
underlying_daily,
include=["ohlcv"],
)
or together with other feature blocks:
features = underlying_features(
underlying_daily,
include=["ohlcv", "iv", "liquidity"],
)
Feature Definitions¶
Returns¶
- Log returns are computed using
log(px_close_t / px_close_{t-1}). - Overnight return measures open-to-previous-close movement.
- Gap size captures absolute discontinuity risk across sessions.
Volatility Estimators¶
The block implements multiple realized volatility estimators:
- Close-to-close volatility (baseline estimator)
- Parkinson estimator (high–low range based)
- Garman–Klass estimator (OHLC-based)
- Yang–Zhang estimator (accounts for overnight jumps)
These estimators capture different microstructure effects and are commonly used in empirical volatility modeling.
Trend Measures¶
- EMAs provide smoothed trend signals at different horizons.
- Bollinger %B normalizes price position within rolling volatility bands.
- Trend persistence encodes the sign of daily price changes.
Masking & Edge Cases¶
- Rolling features are undefined until sufficient history exists.
- Initial rows may contain null values due to differencing or rolling windows.
- No forward-looking information is used at any point.
Configuration¶
The OHLCV feature block supports the following optional parameters:
| Parameter | Default | Description |
|---|---|---|
vol_window |
21 |
Rolling window for volatility calculations |
ema_fast |
10 |
Fast EMA span |
ema_slow |
21 |
Slow EMA span |
bb_window |
20 |
Bollinger band window |
Note¶
- All features are computed in a single pass without joins.
- No smoothing or fitting is applied beyond standard rolling operations.