CalmarLossΒΆ

Defined in fynance.models.loss

class CalmarLoss(rf=0., period=252, eps=1e-8)[source]

Bases: BaseLoss

Negative Calmar ratio as a differentiable loss.

Calmar = annualized return / maximum drawdown. Minimizing this loss maximizes return per unit of worst peak-to-trough loss. The maximum drawdown is computed differentiably from the cumulative return path via torch.cummax.

Parameters are inherited from BaseLoss (period, eps).

Notes

Drawdowns are \(O(\text{returns})\), so a fixed absolute eps (e.g. 1e-8) is dimensionally wrong: on a low- or zero-drawdown batch the ratio would explode and dominate gradients. The drawdown is therefore floored with a returns-scaled epsilon, eps * |equity|.mean(), keeping the loss finite and bounded while preserving its sign convention (minimizing it maximizes the ratio).

forward(y_pred, y_true=None)[source]

Compute the negative Calmar ratio (scalar).