HybridLossΒΆ
Defined in fynance.models.loss
- class HybridLoss(loss_a, loss_b, alpha=0.5, learnable=False, **kwargs)[source]
Bases:
BaseLossConvex combination of two losses: \(\alpha L_a + (1-\alpha) L_b\).
Combines two differentiable objectives (e.g.
SharpeLossandDirectionalAccuracyLoss) with a weightalpha. The weight can be fixed or made learnable (annn.Parameterpassed through a sigmoid so it stays in(0, 1)and is optimized jointly with the model).- Parameters:
- loss_a, loss_bBaseLoss
The two component losses (any callables
(y_pred, y_true) -> scalar).- alphafloat, optional
Weight of
loss_ain[0, 1]. Default 0.5.- learnablebool, optional
If True,
alphabecomes a learnable parameter. Default False.- **kwargs
Forwarded to
BaseLoss.
- forward(y_pred, y_true=None)[source]
Compute the weighted sum of the two losses (scalar).