OmegaLossΒΆ
Defined in fynance.models.loss
- class OmegaLoss(threshold=0., **kwargs)[source]
Bases:
BaseLossNegative Omega ratio as a differentiable loss.
\(\Omega = \frac{E[\max(r - L, 0)]}{E[\max(L - r, 0)] + \varepsilon}\), the ratio of expected gains to expected losses relative to a threshold
L. Fully differentiable throughtorch.relu. Minimizing the loss maximizes the Omega ratio.- Parameters:
- thresholdfloat, optional
Return threshold
Lseparating gains from losses. Default 0.- **kwargs
Forwarded to
BaseLoss(rf,period,eps).
Notes
Both gains and losses are \(O(|r - L|)\), so a fixed absolute
epsis dimensionally wrong: on an all-gains batch (zero losses) the ratio would explode (e.g.-1e6) and dominate gradients. The denominator is therefore floored with a returns-scaled epsilon,eps * |r - L|.mean(), keeping the loss finite and bounded while preserving the sign convention (minimizing it maximizes the ratio).- forward(y_pred, y_true=None)[source]
Compute the negative Omega ratio (scalar).