mirror of
https://github.com/wassname/catalyst.git
synced 2026-07-12 10:39:22 +08:00
FIX: Crashing on calculating benchmarking when no trading days
When we run a simulation that starts and ends on the same weekend, return an empty series for the benchmark so as to not crash
This commit is contained in:
@@ -155,6 +155,7 @@ from zipline.test_algorithms import (
|
||||
call_with_good_kwargs_get_open_orders,
|
||||
call_with_no_kwargs_get_open_orders,
|
||||
empty_positions,
|
||||
set_benchmark_algo,
|
||||
no_handle_data,
|
||||
)
|
||||
from zipline.utils.api_support import ZiplineAPI, set_algo_instance
|
||||
@@ -1819,6 +1820,28 @@ def handle_data(context, data):
|
||||
self.assertTrue(all(num_positions == 0))
|
||||
self.assertTrue(all(amounts == 0))
|
||||
|
||||
@parameterized.expand([
|
||||
('noop_algo', noop_algo),
|
||||
('with_benchmark_set', set_benchmark_algo)]
|
||||
)
|
||||
def test_zero_trading_days(self, name, algocode):
|
||||
"""
|
||||
Test that when we run a simulation with no trading days (e.g. beginning
|
||||
and ending the same weekend), we don't crash on calculating the
|
||||
benchmark
|
||||
"""
|
||||
sim_params = factory.create_simulation_parameters(
|
||||
start=pd.Timestamp('2006-01-14', tz='UTC'),
|
||||
end=pd.Timestamp('2006-01-15', tz='UTC')
|
||||
)
|
||||
|
||||
algo = TradingAlgorithm(
|
||||
script=algocode,
|
||||
sim_params=sim_params,
|
||||
env=self.env
|
||||
)
|
||||
algo.run(self.data_portal)
|
||||
|
||||
|
||||
class TestGetDatetime(WithLogger,
|
||||
WithSimParams,
|
||||
|
||||
Reference in New Issue
Block a user