Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More benchmark fixes #2762

Merged
merged 3 commits into from
Aug 24, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
BUG: Check for no_benchmark was flipped
  • Loading branch information
richafrank committed Aug 24, 2020
commit 94841eb94801a7a2e730bbbf95946a0885f3af95
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