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 value|r - L|.mean() / MAX_RATIO(plus a bareepsbackstop for the degenerate all-zero-diff batch), capping the ratio at roughlyMAX_RATIOin the low-loss regime regardless of the return scale.The ratio is then passed through a smooth saturating map,
MAX_RATIO * tanh(ratio / MAX_RATIO), instead of a hard clamp. A hard clamp pins the loss to a constant on an all-gains batch and so zeroes the gradient in exactly the regime training still wants to push on;tanhis near-linear for normal-regime ratios (leaving their numerics unchanged) yet keeps a residual, non-zero gradient when the ratio is large. This keeps 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).