def period_returns(self): # check series is indeed a series # assert isinstance(returns, pd.Series) # check that all indices are increasing # assert returns.index.is_monotonic_increasing # make sure all entries non-negative # assert not (prices < 0).any() return period_returns(returns=self, today=self.index[-1])
def test_periods(self): y = period_returns(ts.pct_change(), offset=periods(ts.index[-1])) pdt.assert_series_equal(y, read_series("periods.csv", parse_dates=False), check_names=False)
def period_returns(self): n = self.__nav.pct_change() return period_returns(n, periods(today=n.index[-1]))
def test_period_returns(returns): p = periods(today=pd.Timestamp("2015-05-01")) x = 100 * period_returns(returns=returns, offset=p) assert x["Three Years"] == pytest.approx(1.1645579858904798, 1e-10)