def get_optimal_number_of_bins(num_obs: int, corr_coef: float=None) ->int:
    """
    Get optimal number of bins for discretization based on number of observations
    and correlation coefficient (univariate case).
    The algorithm is described in https://papers.ssrn.com/sol3/papers.cfm?abstract_id=3512994&download=yes (p.26)

    :param num_obs: (int) number of observations.
    :param corr_coef: (int) correlation coefficient, used to estimate the number of bins for univariate case.
    :return: (int) optimal number of bins.
    """
    if corr_coef is None or abs(corr_coef - 1) <= 0.0001:
        z = (8 + 324 * num_obs + 12 * (36 * num_obs + 729 * num_obs ** 2) **
            0.5) ** (1 / 3.0)
        bins = round(z / 6.0 + 2.0 / (3 * z) + 1.0 / 3)
    else:
        bins = round(2 ** -0.5 * (1 + (1 + 24 * num_obs / (1.0 - corr_coef **
            2)) ** 0.5) ** 0.5)
    return int(bins)
