Skip to content

Commit

Permalink
BUG: Check for no_benchmark was flipped
Browse files Browse the repository at this point in the history
  • Loading branch information
richafrank committed Aug 24, 2020
1 parent d76116a commit 94841eb
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
36 changes: 29 additions & 7 deletions tests/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@
import tarfile

import matplotlib
from nose_parameterized import parameterized
import pandas as pd

from zipline import examples
from zipline.data.bundles import register, unregister
from zipline.testing import test_resource_path
from zipline.testing import test_resource_path, parameter_space
from zipline.testing.fixtures import (
WithTmpDir,
ZiplineTestCase,
Expand Down Expand Up @@ -61,10 +60,29 @@ def init_class_fixtures(cls):
serialization='pickle',
)

cls.benchmark_returns = read_checked_in_benchmark_data()
cls.no_benchmark_expected_perf = {
example_name: cls._no_benchmark_expectations_applied(
expected_perf.copy()
)
for example_name, expected_perf in cls.expected_perf.items()
}

@parameterized.expand(sorted(EXAMPLE_MODULES))
def test_example(self, example_name):
@staticmethod
def _no_benchmark_expectations_applied(expected_perf):
# With no benchmark, expect zero results for these metrics:
expected_perf[['alpha', 'beta']] = None
for col in ['benchmark_period_return', 'benchmark_volatility']:
expected_perf.loc[
~pd.isnull(expected_perf[col]),
col,
] = 0.0
return expected_perf

@parameter_space(
example_name=sorted(EXAMPLE_MODULES),
benchmark_returns=[read_checked_in_benchmark_data(), None]
)
def test_example(self, example_name, benchmark_returns):
actual_perf = examples.run_example(
EXAMPLE_MODULES,
example_name,
Expand All @@ -73,9 +91,13 @@ def test_example(self, example_name):
environ={
'ZIPLINE_ROOT': self.tmpdir.getpath('example_data/root'),
},
benchmark_returns=self.benchmark_returns,
benchmark_returns=benchmark_returns,
)
expected_perf = self.expected_perf[example_name]
if benchmark_returns is not None:
expected_perf = self.expected_perf[example_name]
else:
expected_perf = self.no_benchmark_expected_perf[example_name]

# Exclude positions column as the positions do not always have the
# same order
columns = [column for column in examples._cols_to_check
Expand Down
2 changes: 1 addition & 1 deletion zipline/utils/run_algo.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ def from_returns(cls, benchmark_returns):
benchmark_file=None,
benchmark_sid=None,
benchmark_symbol=None,
no_benchmark=benchmark_returns is not None,
no_benchmark=benchmark_returns is None,
)

def resolve(self, asset_finder, start_date, end_date):
Expand Down

0 comments on commit 94841eb

Please sign in to comment.