def test_rolling_corr_pairwise(self): panel = mom.rolling_corr_pairwise(self.frame, 10, min_periods=5) correl = panel.ix[:, 1, 5] exp = mom.rolling_corr(self.frame[1], self.frame[5], 10, min_periods=5) tm.assert_series_equal(correl, exp)
def test_expanding_corr_pairwise(self): result = mom.expanding_corr_pairwise(self.frame) rolling_result = mom.rolling_corr_pairwise(self.frame, len(self.frame), min_periods=1) for i in result.items: assert_almost_equal(result[i], rolling_result[i])
def test_rolling_functions_window_non_shrinkage(self): # GH 7764 s = Series(range(4)) s_expected = Series(np.nan, index=s.index) df = DataFrame([[1, 5], [3, 2], [3, 9], [-1, 0]], columns=['A', 'B']) df_expected = DataFrame(np.nan, index=df.index, columns=df.columns) df_expected_panel = Panel(items=df.index, major_axis=df.columns, minor_axis=df.columns) functions = [ lambda x: mom.rolling_cov( x, x, pairwise=False, window=10, min_periods=5), lambda x: mom.rolling_corr( x, x, pairwise=False, window=10, min_periods=5), lambda x: mom.rolling_max(x, window=10, min_periods=5), lambda x: mom.rolling_min(x, window=10, min_periods=5), lambda x: mom.rolling_sum(x, window=10, min_periods=5), lambda x: mom.rolling_mean(x, window=10, min_periods=5), lambda x: mom.rolling_std(x, window=10, min_periods=5), lambda x: mom.rolling_var(x, window=10, min_periods=5), lambda x: mom.rolling_skew(x, window=10, min_periods=5), lambda x: mom.rolling_kurt(x, window=10, min_periods=5), lambda x: mom.rolling_quantile( x, quantile=0.5, window=10, min_periods=5), lambda x: mom.rolling_median(x, window=10, min_periods=5), lambda x: mom.rolling_apply(x, func=sum, window=10, min_periods=5), lambda x: mom.rolling_window( x, win_type='boxcar', window=10, min_periods=5), ] for f in functions: try: s_result = f(s) assert_series_equal(s_result, s_expected) df_result = f(df) assert_frame_equal(df_result, df_expected) except (ImportError): # scipy needed for rolling_window continue functions = [ lambda x: mom.rolling_cov( x, x, pairwise=True, window=10, min_periods=5), lambda x: mom.rolling_corr( x, x, pairwise=True, window=10, min_periods=5), # rolling_corr_pairwise is depracated, so the following line should be deleted # when rolling_corr_pairwise is removed. lambda x: mom.rolling_corr_pairwise(x, x, window=10, min_periods=5 ), ] for f in functions: df_result_panel = f(df) assert_panel_equal(df_result_panel, df_expected_panel)
def test_rolling_functions_window_non_shrinkage(self): # GH 7764 s = Series(range(4)) s_expected = Series(np.nan, index=s.index) df = DataFrame([[1,5], [3, 2], [3,9], [-1,0]], columns=['A','B']) df_expected = DataFrame(np.nan, index=df.index, columns=df.columns) df_expected_panel = Panel(items=df.index, major_axis=df.columns, minor_axis=df.columns) functions = [lambda x: mom.rolling_cov(x, x, pairwise=False, window=10, min_periods=5), lambda x: mom.rolling_corr(x, x, pairwise=False, window=10, min_periods=5), lambda x: mom.rolling_max(x, window=10, min_periods=5), lambda x: mom.rolling_min(x, window=10, min_periods=5), lambda x: mom.rolling_sum(x, window=10, min_periods=5), lambda x: mom.rolling_mean(x, window=10, min_periods=5), lambda x: mom.rolling_std(x, window=10, min_periods=5), lambda x: mom.rolling_var(x, window=10, min_periods=5), lambda x: mom.rolling_skew(x, window=10, min_periods=5), lambda x: mom.rolling_kurt(x, window=10, min_periods=5), lambda x: mom.rolling_quantile(x, quantile=0.5, window=10, min_periods=5), lambda x: mom.rolling_median(x, window=10, min_periods=5), lambda x: mom.rolling_apply(x, func=sum, window=10, min_periods=5), lambda x: mom.rolling_window(x, win_type='boxcar', window=10, min_periods=5), ] for f in functions: try: s_result = f(s) assert_series_equal(s_result, s_expected) df_result = f(df) assert_frame_equal(df_result, df_expected) except (ImportError): # scipy needed for rolling_window continue functions = [lambda x: mom.rolling_cov(x, x, pairwise=True, window=10, min_periods=5), lambda x: mom.rolling_corr(x, x, pairwise=True, window=10, min_periods=5), # rolling_corr_pairwise is depracated, so the following line should be deleted # when rolling_corr_pairwise is removed. lambda x: mom.rolling_corr_pairwise(x, x, window=10, min_periods=5), ] for f in functions: df_result_panel = f(df) assert_panel_equal(df_result_panel, df_expected_panel)