Exemple #1
0
def test_get_annualized_mean(data_cube, frequency):
    expected = [
        -1.58544394e-04, 3.95923527e-05, 8.10572621e-04, -3.15037014e-03,
        -8.93454642e-04
    ]
    assert_almost_equal(get_annualized_mean(data_cube, frequency), expected)
    assert_almost_equal(
        [get_annualized_mean(data_cube[..., i], frequency) for i in range(N)],
        expected)
Exemple #2
0
        def mean_best_guess():
            space = 2**np.linspace(-15, 4, 30)
            space = np.sort([*-space, *space])
            f_space = np.array([
                get_annualized_mean(self.data + x, self.time_unit) - mean
                for x in space
            ])
            mask: np.ndarray = (f_space[:-1] * f_space[1:]) <= 0

            return get_by_bisection(space, f_space,
                                    mask) if any(mask) else get_closest_to_0(
                                        space, f_space)
Exemple #3
0
    def statistics(self):
        """
        Returns the statistics (4 moments) of the cube

        Returns
        -------
        DataFrame
            The first 4 moments of the cube for each asset (last axis)
        """
        return pd.DataFrame({
            "Mean":
            get_annualized_mean(self, self.time_unit),
            "SD":
            get_annualized_sd(self, self.time_unit),
            "Skew":
            get_annualized_skew(self, self.time_unit),
            "Kurt":
            get_annualized_kurtosis(self, self.time_unit),
        })
Exemple #4
0
 def annualized_moments(self, x: np.ndarray, mean: float, sd: float):
     calibrated_data = self.data * x[1] + x[0]
     return (get_annualized_mean(calibrated_data, self.time_unit) - mean,
             get_annualized_sd(calibrated_data, self.time_unit) - sd)
Exemple #5
0
 def annualized_mean(self, x: float, target: float):
     return get_annualized_mean(self.data + x, self.time_unit) - target