directional_accuracyΒΆ
Defined in fynance.features.stats
- directional_accuracy(y_true, y_pred, axis=0)[source]
Compute the directional accuracy of a prediction.
Fraction of periods where the predicted direction (sign) matches the true direction. A value of 1.0 means perfect directional alignment; 0.5 is random; 0.0 means systematically wrong direction.
- Parameters:
- y_truenp.ndarray[ndim=1 or 2, dtype]
Vector of true values (returns or price changes).
- y_prednp.ndarray[ndim=1 or 2, dtype]
Vector of predicted values.
- axis{0, 1}, optional
Axis along which the computation is done. Default is 0.
- Returns:
- float or np.ndarray[ndim=1, float]
Directional accuracy between 0 and 1.
See also
accuracy
Notes
\[directionalAccuracy = \frac{1}{T} \sum_{t=1}^{T} \mathbf{1}[\text{sign}(\hat{y}_t) = \text{sign}(y_t)]\]Examples
>>> y_true = np.array([1., .5, -.5, .8, -.2]) >>> y_pred = np.array([.5, .2, -.5, .1, .0]) >>> directional_accuracy(y_true, y_pred) 0.8