1
+ from pandas import DataFrame , Panel
1
2
from pandas .stats .api import fama_macbeth
2
3
from common import assert_almost_equal , BaseTest
3
4
5
+ import numpy as np
6
+
4
7
class TestFamaMacBeth (BaseTest ):
5
8
def testFamaMacBethRolling (self ):
6
- self .checkFamaMacBethExtended ('rolling' , self .panel_x , self .panel_y )
9
+ # self.checkFamaMacBethExtended('rolling', self.panel_x, self.panel_y,
10
+ # nw_lags_beta=2)
11
+
12
+ df = DataFrame (np .random .randn (50 , 10 ))
13
+ x = dict ((k , df ) for k in 'abcdefg' )
14
+ x = Panel .from_dict (x )
15
+ y = df + DataFrame (0.01 * np .random .randn (50 , 10 ))
16
+ self .checkFamaMacBethExtended ('rolling' , x , y , nw_lags_beta = 2 )
17
+ self .checkFamaMacBethExtended ('expanding' , x , y , nw_lags_beta = 2 )
7
18
8
19
def checkFamaMacBethExtended (self , window_type , x , y , ** kwds ):
9
20
window = 25
10
21
11
22
result = fama_macbeth (y = y , x = x , window_type = window_type , window = window ,
12
23
** kwds )
24
+ self ._check_stuff_works (result )
13
25
14
26
index = result ._index
15
27
time = len (index )
@@ -31,6 +43,18 @@ def checkFamaMacBethExtended(self, window_type, x, y, **kwds):
31
43
32
44
assert_almost_equal (reference ._stats , result ._stats [:, i ])
33
45
46
+ static = fama_macbeth (y = y2 , x = x2 , ** kwds )
47
+ self ._check_stuff_works (static )
48
+
49
+ def _check_stuff_works (self , result ):
50
+ # does it work?
51
+ attrs = ['mean_beta' , 'std_beta' , 't_stat' ]
52
+ for attr in attrs :
53
+ getattr (result , attr )
54
+
55
+ # does it work?
56
+ result .summary
57
+
34
58
if __name__ == '__main__' :
35
59
import nose
36
60
nose .runmodule (argv = [__file__ ,'-vvs' ,'-x' ,'--pdb' , '--pdb-failure' ],
0 commit comments