def calculate_statistics(delta_pred, delta_real, delta_pred_bin, delta_real_bin):
  """
  Computes the accuracy statistics for the predicted and real changes in price. Provides validation
  for the model if the accuracy of the binary predictions are within a target threshold. Also
  computes the number of predictions that are within a threshold deviation of the average.

  Args:
    delta_pred      (tensor) - the predicted deltas
    delta_real      (tensor) - the real deltas
    delta_pred_bin  (tensor) - the binary predictions
    delta_real_bin  (tensor) - the binary real values

  Returns:
    avg_p            (float) - the avg percent difference between the real and predicted data
    avg_pos_correct  (float) - the proportion of correct positive ids
    avg_neg_correct  (float) - the proportion of negative correct ids
  """
  # true_pos, false_pos, true_neg, false_neg
  res = [0] * 4
  P = 0
  N = delta_real_bin.shape[0]

  for i in range(N):
    P += abs(delta_pred[i][0] - delta_real[i][0]) / delta_real[i][0]
    real, pred = delta_real[i][0], delta_pred[i][0]
    if real == 1 and pred == 1:
      res[0] += 1
    elif real == 0 and pred == 1:
      res[1] += 1
    elif real == 0 and pred == 0:
      res[2] += 1
    elif real == 1 and pred == 0:
      res[3] += 1

  avg_p = P / N
  avg_pos_correct = res[0] / (res[0] + res[1])
  avg_neg_correct = res[2] / (res[2] + res[3])
  return avg_p, avg_pos_correct, avg_neg_correct