Types¶
Shared data types used across all pymlfinance modules.
| Type | Description |
|---|---|
TickData |
A single market tick with timestamp, price, and volume |
OhlcvBar |
An OHLCV bar with VWAP |
TripleBarrierConfig |
Configuration for the triple-barrier labeling method |
Event |
A labeled event from the triple-barrier method |
TrendScanResult |
Result of trend scanning label detection |
DrawdownResult |
Result of drawdown analysis |
CscvResult |
Result of Combinatorially Symmetric Cross-Validation |
KMeansResult |
Result of K-means clustering |
OncResult |
Result of Optimal Number of Clusters analysis |
AllocationComparison |
Comparison of HRP, CLA, and IVP allocations |
BootstrapComparison |
Comparison of sequential vs. standard bootstrap uniqueness |
FoldIndices |
Train/test split indices for a cross-validation fold |
All types are available at the root level:
import pymlfinance as ml
tick = ml.TickData(timestamp=1000, price=100.0, volume=50.0)
config = ml.TripleBarrierConfig(profit_taking=2.0, stop_loss=2.0, max_holding=20)
pymlfinance ¶
TickData ¶
A single market tick with timestamp, price, and volume.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timestamp
|
float
|
Unix timestamp in seconds (fractional seconds supported). |
required |
price
|
float
|
Trade price. |
required |
volume
|
float
|
Trade volume. |
required |
Examples:
OhlcvBar ¶
An OHLCV bar (Open, High, Low, Close, Volume) with VWAP.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timestamp
|
float
|
Unix timestamp of the bar open. |
required |
open
|
float
|
Opening price. |
required |
high
|
float
|
Highest price during the bar. |
required |
low
|
float
|
Lowest price during the bar. |
required |
close
|
float
|
Closing price. |
required |
volume
|
float
|
Total volume traded. |
required |
vwap
|
float
|
Volume-weighted average price (default 0.0). |
None
|
Attributes:
| Name | Type | Description |
|---|---|---|
mid_price() |
float
|
(high + low) / 2 |
typical_price() |
float
|
(high + low + close) / 3 |
dollar_volume() |
float
|
vwap * volume |
TripleBarrierConfig ¶
Configuration for the triple-barrier labeling method.
Defines the upper profit-taking barrier, lower stop-loss barrier, and maximum holding period for event labeling (AFML Ch. 3).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
upper_barrier
|
float
|
Profit-taking threshold as a fraction of daily volatility. |
None
|
lower_barrier
|
float
|
Stop-loss threshold as a fraction of daily volatility. |
None
|
max_holding_period
|
int
|
Maximum number of bars before forced exit (vertical barrier). |
None
|
Examples:
Event ¶
A labeled event from the triple-barrier method.
Attributes:
| Name | Type | Description |
|---|---|---|
entry_idx |
int
|
Index of the entry bar. |
exit_idx |
int
|
Index of the exit bar. |
touch_type |
str
|
Which barrier was touched first: |
return_value |
float
|
Return from entry to exit. |
TrendScanResult ¶
Result of trend scanning label detection.
Attributes:
| Name | Type | Description |
|---|---|---|
t_stat |
float
|
t-statistic of the best linear fit. |
label |
int
|
Trend direction: +1 (up), -1 (down), or 0 (no trend). |
best_window |
int
|
Look-ahead window that produced the highest |t-stat|. |
r_squared |
float
|
R-squared of the best linear fit. |
DrawdownResult ¶
Result of drawdown analysis on a return series.
Attributes:
| Name | Type | Description |
|---|---|---|
max_drawdown |
float
|
Maximum peak-to-trough decline. |
max_drawdown_duration |
int
|
Longest drawdown duration in bars. |
drawdown_series |
list[float]
|
Per-bar drawdown values. |
time_under_water |
list[int]
|
Per-bar count of consecutive bars in drawdown. |
CscvResult ¶
Result of Combinatorially Symmetric Cross-Validation (CSCV).
Attributes:
| Name | Type | Description |
|---|---|---|
pbo |
float
|
Probability of Backtest Overfitting. |
rank_logits |
list[float]
|
Log-odds of each strategy's rank degradation. |
KMeansResult ¶
Result of K-means clustering.
Attributes:
| Name | Type | Description |
|---|---|---|
labels |
list[int]
|
Cluster assignment for each data point. |
n_iterations |
int
|
Number of iterations until convergence. |
centroids |
list[list[float]]
|
Cluster centroids (k x n_features). |
OncResult ¶
Result of Optimal Number of Clusters (ONC) analysis.
Attributes:
| Name | Type | Description |
|---|---|---|
labels |
list[int]
|
Cluster assignment for each feature/variable. |
silhouette |
float
|
Silhouette score of the optimal clustering. |
n_clusters |
int
|
Optimal number of clusters found. |
AllocationComparison ¶
Comparison of HRP, CLA, and IVP portfolio allocations.
Attributes:
| Name | Type | Description |
|---|---|---|
hrp_sharpe |
float
|
Out-of-sample Sharpe ratio for HRP. |
cla_sharpe |
float
|
Out-of-sample Sharpe ratio for CLA (min-variance). |
ivp_sharpe |
float
|
Out-of-sample Sharpe ratio for Inverse Variance. |
hrp_variance |
float
|
Out-of-sample portfolio variance for HRP. |
cla_variance |
float
|
Out-of-sample portfolio variance for CLA. |
ivp_variance |
float
|
Out-of-sample portfolio variance for IVP. |
BootstrapComparison ¶
Comparison of sequential vs. standard bootstrap uniqueness.
Attributes:
| Name | Type | Description |
|---|---|---|
seq_uniqueness |
float
|
Average uniqueness from sequential bootstrap. |
std_uniqueness |
float
|
Average uniqueness from standard (IID) bootstrap. |
FoldIndices ¶
Train/test split indices for a single cross-validation fold.
Attributes:
| Name | Type | Description |
|---|---|---|
train |
list[int]
|
Indices of training samples. |
test |
list[int]
|
Indices of test samples. |