mirror of
https://github.com/wassname/catalyst.git
synced 2026-07-12 15:37:45 +08:00
TST: Added tests for new order methods.
This commit is contained in:
+21
-7
@@ -21,7 +21,13 @@ from zipline.utils.test_utils import setup_logger
|
||||
import zipline.utils.factory as factory
|
||||
from zipline.test_algorithms import (TestRegisterTransformAlgorithm,
|
||||
RecordAlgorithm,
|
||||
TestOrderAlgorithm)
|
||||
TestOrderAlgorithm,
|
||||
TestOrderValueAlgorithm,
|
||||
TestTargetAlgorithm,
|
||||
TestOrderPercentAlgorithm,
|
||||
TestTargetPercentAlgorithm,
|
||||
TestTargetValueAlgorithm)
|
||||
|
||||
from zipline.sources import (SpecificEquityTrades,
|
||||
DataFrameSource,
|
||||
DataPanelSource)
|
||||
@@ -166,9 +172,17 @@ class TestTransformAlgorithm(TestCase):
|
||||
self.assertEqual(algo.data_frequency, 'minute')
|
||||
self.assertEqual(algo.annualizer, 10)
|
||||
|
||||
def test_orders_executed(self):
|
||||
algo = TestOrderAlgorithm(
|
||||
sim_params=self.sim_params,
|
||||
data_frequency='daily'
|
||||
)
|
||||
algo.run(self.df)
|
||||
def test_order_methods(self):
|
||||
AlgoClasses = [TestOrderAlgorithm,
|
||||
TestOrderValueAlgorithm,
|
||||
TestTargetAlgorithm,
|
||||
TestOrderPercentAlgorithm,
|
||||
TestTargetPercentAlgorithm,
|
||||
TestTargetValueAlgorithm]
|
||||
|
||||
for AlgoClass in AlgoClasses:
|
||||
algo = AlgoClass(
|
||||
sim_params=self.sim_params,
|
||||
data_frequency='daily'
|
||||
)
|
||||
algo.run(self.df)
|
||||
|
||||
@@ -231,7 +231,7 @@ class TestBatchTransform(TestCase):
|
||||
# consecutive (of window length) numbers up till the end.
|
||||
for i in range(algo.window_length, len(test_history)):
|
||||
np.testing.assert_array_equal(
|
||||
range(i - algo.window_length + 1, i + 1),
|
||||
range(i - algo.window_length + 2, i + 2d),
|
||||
test_history[i].values.flatten()
|
||||
)
|
||||
|
||||
|
||||
@@ -326,7 +326,7 @@ def create_test_df_source(sim_params=None, bars='daily'):
|
||||
if i >= market_open and i <= market_close:
|
||||
new_index.append(i)
|
||||
index = new_index
|
||||
x = np.arange(0, len(index))
|
||||
x = np.arange(1, len(index) + 1)
|
||||
|
||||
df = pd.DataFrame(x, index=index, columns=[0])
|
||||
|
||||
|
||||
Reference in New Issue
Block a user