Skip to content

Commit c729669

Browse files
committed
TST: fama macbeth tests
1 parent 93b909a commit c729669

File tree

2 files changed

+28
-8
lines changed

2 files changed

+28
-8
lines changed

pandas/stats/fama_macbeth.py

+3-7
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,6 @@ def std_beta(self):
7676
def t_stat(self):
7777
return self._make_result(self._t_stat_raw)
7878

79-
@cache_readonly
80-
def _result_index(self):
81-
mask = self._ols_result._rolling_ols_call[1]
82-
return self._index[mask]
83-
8479
@cache_readonly
8580
def _results(self):
8681
return {
@@ -195,8 +190,9 @@ def _make_result(self, result):
195190

196191
@cache_readonly
197192
def _result_index(self):
198-
mask = self._ols_result._rolling_ols_call[1]
199-
return self._index[mask]
193+
mask = self._ols_result._rolling_ols_call[2]
194+
# HACK XXX
195+
return self._index[mask.cumsum() >= self._window]
200196

201197
@cache_readonly
202198
def _results(self):

pandas/stats/tests/test_fama_macbeth.py

+25-1
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,27 @@
1+
from pandas import DataFrame, Panel
12
from pandas.stats.api import fama_macbeth
23
from common import assert_almost_equal, BaseTest
34

5+
import numpy as np
6+
47
class TestFamaMacBeth(BaseTest):
58
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)
718

819
def checkFamaMacBethExtended(self, window_type, x, y, **kwds):
920
window = 25
1021

1122
result = fama_macbeth(y=y, x=x, window_type=window_type, window=window,
1223
**kwds)
24+
self._check_stuff_works(result)
1325

1426
index = result._index
1527
time = len(index)
@@ -31,6 +43,18 @@ def checkFamaMacBethExtended(self, window_type, x, y, **kwds):
3143

3244
assert_almost_equal(reference._stats, result._stats[:, i])
3345

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+
3458
if __name__ == '__main__':
3559
import nose
3660
nose.runmodule(argv=[__file__,'-vvs','-x','--pdb', '--pdb-failure'],

0 commit comments

Comments
 (0)