@@ -586,6 +586,10 @@ def test_rolling_cov(self):
586
586
result = mom .rolling_cov (A , B , 50 , min_periods = 25 )
587
587
assert_almost_equal (result [- 1 ], np .cov (A [- 50 :], B [- 50 :])[0 , 1 ])
588
588
589
+ def test_rolling_cov_pairwise (self ):
590
+ self ._check_pairwise_moment (mom .rolling_cov_pairwise ,
591
+ mom .rolling_cov , 10 , min_periods = 5 )
592
+
589
593
def test_rolling_corr (self ):
590
594
A = self .series
591
595
B = A + randn (len (A ))
@@ -603,12 +607,15 @@ def test_rolling_corr(self):
603
607
assert_almost_equal (result [- 1 ], a .corr (b ))
604
608
605
609
def test_rolling_corr_pairwise (self ):
606
- panel = mom .rolling_corr_pairwise (self .frame , 10 , min_periods = 5 )
610
+ self ._check_pairwise_moment (mom .rolling_corr_pairwise ,
611
+ mom .rolling_corr , 10 , min_periods = 5 )
612
+
613
+ def _check_pairwise_moment (self , func_pairwise , func , * args , ** kwargs ):
614
+ panel = func_pairwise (self .frame , self .frame , * args , ** kwargs )
607
615
608
- correl = panel .ix [:, 1 , 5 ]
609
- exp = mom .rolling_corr (self .frame [1 ], self .frame [5 ],
610
- 10 , min_periods = 5 )
611
- tm .assert_series_equal (correl , exp )
616
+ actual = panel .ix [:, 1 , 5 ]
617
+ expected = func (self .frame [1 ], self .frame [5 ], * args , ** kwargs )
618
+ tm .assert_series_equal (actual , expected )
612
619
613
620
def test_flex_binary_moment (self ):
614
621
# GH3155
@@ -666,9 +673,17 @@ def _check(method):
666
673
def test_ewmcov (self ):
667
674
self ._check_binary_ew (mom .ewmcov )
668
675
676
+ def test_ewmcov_pairwise (self ):
677
+ self ._check_pairwise_moment (mom .ewmcov_pairwise , mom .ewmcov , 10 ,
678
+ min_periods = 5 )
679
+
669
680
def test_ewmcorr (self ):
670
681
self ._check_binary_ew (mom .ewmcorr )
671
682
683
+ def test_ewmcorr_pairwise (self ):
684
+ self ._check_pairwise_moment (mom .ewmcorr_pairwise , mom .ewmcorr , 10 ,
685
+ min_periods = 5 )
686
+
672
687
def _check_binary_ew (self , func ):
673
688
A = Series (randn (50 ), index = np .arange (50 ))
674
689
B = A [2 :] + randn (48 )
@@ -746,6 +761,16 @@ def test_expanding_cov(self):
746
761
def test_expanding_max (self ):
747
762
self ._check_expanding (mom .expanding_max , np .max , preserve_nan = False )
748
763
764
+ def test_expanding_cov_pairwise (self ):
765
+ result = mom .expanding_cov_pairwise (self .frame )
766
+
767
+ rolling_result = mom .rolling_cov_pairwise (self .frame ,
768
+ len (self .frame ),
769
+ min_periods = 1 )
770
+
771
+ for i in result .items :
772
+ assert_almost_equal (result [i ], rolling_result [i ])
773
+
749
774
def test_expanding_corr_pairwise (self ):
750
775
result = mom .expanding_corr_pairwise (self .frame )
751
776
0 commit comments