|
11 | 11 | ) |
12 | 12 |
|
13 | 13 |
|
| 14 | +def _empyrical_compat_perf_attrib_result(index, columns, data): |
| 15 | + if ep.__version__ < '0.5.2': |
| 16 | + # Newer columns were added in empyrical v0.5.2. These exist in older |
| 17 | + # and newer empyrical: |
| 18 | + columns = ['risk_factor1', 'risk_factor2', 'common_returns', |
| 19 | + 'specific_returns', 'total_returns'] |
| 20 | + data = {k: v for k, v in data.items() if k in columns} |
| 21 | + |
| 22 | + return pd.DataFrame(index=index, columns=columns, data=data) |
| 23 | + |
| 24 | + |
14 | 25 | def generate_toy_risk_model_output(start_date='2017-01-01', periods=10, |
15 | 26 | num_styles=2): |
16 | 27 | """ |
@@ -115,7 +126,7 @@ def test_perf_attrib_simple(self): |
115 | 126 | 'risk_factor2': [0.25, 0.25, 0.25, 0.25]} |
116 | 127 | ) |
117 | 128 |
|
118 | | - expected_perf_attrib_output = pd.DataFrame( |
| 129 | + expected_perf_attrib_output = _empyrical_compat_perf_attrib_result( |
119 | 130 | index=dts, |
120 | 131 | columns=['risk_factor1', 'risk_factor2', 'total_returns', |
121 | 132 | 'common_returns', 'specific_returns', |
@@ -158,7 +169,7 @@ def test_perf_attrib_simple(self): |
158 | 169 | factor_returns, |
159 | 170 | factor_loadings) |
160 | 171 |
|
161 | | - expected_perf_attrib_output = pd.DataFrame( |
| 172 | + expected_perf_attrib_output = _empyrical_compat_perf_attrib_result( |
162 | 173 | index=dts, |
163 | 174 | columns=['risk_factor1', 'risk_factor2', 'total_returns', |
164 | 175 | 'common_returns', 'specific_returns', |
|
0 commit comments