How should I write this "Custom Loss Function"?

Hi, I want to custom a loss function in Pytorch to implement the following functions:

  1. This is a binary classification problem. This loss function evaluates the Precision of the sample that exceeds a certain probability ranking quantile
  2. This is an example: y_prob_ preds = [0.3, 0.5, 0.7, 0.8,0.9], y_ true=[0, 0, 0, 1, 1]
    When the prediction probability is greater than 60% quantile of all probs, the precision (loss) = 2 / 3

Is there anyone who can offer some professional advice?

Thank you very much !