import torch


def tilted_loss(y_pred, y, q=0.5):
    """
    Loss function used to obtain quantile `q`.
    Parameters:
    - y_pred: Predicted Value
    - y: Target
    - q: Quantile
    """
    e = (y - y_pred)
    return q * torch.clamp_min(e, 0) + (1-q) * torch.clamp_min(-e, 0)