Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion empyrical/perf_attrib.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,4 @@ def compute_exposures(positions, factor_loadings):
2017-01-02 0.821872 1.520515
"""
risk_exposures = factor_loadings.multiply(positions, axis='rows')
return risk_exposures.groupby(level='dt').sum()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a test we can add/modify to go along with this change?

return risk_exposures.groupby(level=0).sum()
11 changes: 6 additions & 5 deletions empyrical/tests/test_perf_attrib.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def test_perf_attrib_simple(self):
)

index = pd.MultiIndex.from_product(
[dts, tickers], names=['dt', 'ticker'])
[dts, tickers], names=['date', 'ticker'])

positions = pd.Series([0.2857142857142857, 0.7142857142857143,
0.2857142857142857, 0.7142857142857143],
Expand All @@ -40,8 +40,9 @@ def test_perf_attrib_simple(self):
'risk_factor2': [0.25, 0.25, 0.25, 0.25]}
)

expected_index = dts.set_names(['date'])
expected_perf_attrib_output = pd.DataFrame(
index=dts,
index=expected_index,
columns=['risk_factor1', 'risk_factor2', 'common_returns',
'specific_returns', 'total_returns'],
data={'risk_factor1': [0.025, 0.025],
Expand All @@ -52,7 +53,7 @@ def test_perf_attrib_simple(self):
)

expected_exposures_portfolio = pd.DataFrame(
index=dts,
index=expected_index,
columns=['risk_factor1', 'risk_factor2'],
data={'risk_factor1': [0.25, 0.25],
'risk_factor2': [0.25, 0.25]}
Expand All @@ -78,7 +79,7 @@ def test_perf_attrib_simple(self):
factor_loadings)

expected_perf_attrib_output = pd.DataFrame(
index=dts,
index=expected_index,
columns=['risk_factor1', 'risk_factor2', 'common_returns',
'specific_returns', 'total_returns'],
data={'risk_factor1': [0.0, 0.0],
Expand All @@ -89,7 +90,7 @@ def test_perf_attrib_simple(self):
)

expected_exposures_portfolio = pd.DataFrame(
index=dts,
index=expected_index,
columns=['risk_factor1', 'risk_factor2'],
data={'risk_factor1': [0.0, 0.0],
'risk_factor2': [0.0, 0.0]}
Expand Down