Exemplo n.º 1
0
def test_weighted_mean():
    means = np.array([1])
    weights = np.array([1])
    assert weighted_mean(means, weights) == 1
    means = np.array(range(5))
    weights = np.array(range(5, 10))
    assert weighted_mean(means, weights) == 80
Exemplo n.º 2
0
    def comp_expected_return(self, freq=252):
        """Computes the Expected Return of the portfolio.

        :Input:
         :freq: ``int`` (default: ``252``), number of trading days, default
             value corresponds to trading days in a year.

        :Output:
         :expected_return: ``float`` the Expected Return of the portfolio.
        """
        if not isinstance(freq, int):
            raise ValueError("freq is expected to be an integer.")
        pf_return_means = historical_mean_return(self.data, freq=freq)
        weights = self.comp_weights()
        expected_return = weighted_mean(pf_return_means.values, weights)
        self.expected_return = expected_return
        return expected_return