Esempio n. 1
0
    def growth_of_x(self, x=1.):
        """Ending value from growth of `x`, a scalar.

        Returns
        -------
        float
        """

        return nanprod(self.ret_rels()) * x
Esempio n. 2
0
    def geomean(self):
        """Geometric mean return over the entire sample.

        Returns
        -------
        float
        """

        return nanprod(self.ret_rels())**(1. / self.count()) - 1.
Esempio n. 3
0
    def anlzd_ret(self, freq=None):
        """Annualized (geometric) return.

        Parameters
        ----------
        freq : str or None, default None
            A frequency string used to create an annualization factor.
            If None, `self.freq` will be used.  If that is also None,
            a frequency will be inferred.  If none can be inferred,
            an exception is raised.

            It may be any frequency string or anchored offset string
            recognized by Pandas, such as 'D', '5D', 'Q', 'Q-DEC', or
            'BQS-APR'.

        Returns
        -------
        float
        """

        if self.index.is_all_dates:
            # TODO: Could be more granular here,
            #       for cases with < day frequency.
            td = self.index[-1] - self.index[0]
            n = td.total_seconds() / SECS_PER_CAL_YEAR
        else:
            # We don't have a datetime-like Index, so assume
            # periods/dates are consecutive and simply count them.
            # We do, however, need an explicit frequency.
            freq = freq if freq is not None else self.freq
            if freq is None:
                raise FrequencyError('Must specify a `freq` when a'
                                     ' datetime-like index is not used.')

            n = len(self) / utils.get_anlz_factor(freq)
        return nanprod(self.ret_rels())**(1. / n) - 1.