mirror of
https://github.com/wassname/catalyst.git
synced 2026-07-23 12:50:22 +08:00
TST: Added testing of order timings and price.
This commit is contained in:
@@ -20,7 +20,8 @@ import numpy as np
|
||||
from zipline.utils.test_utils import setup_logger
|
||||
import zipline.utils.factory as factory
|
||||
from zipline.test_algorithms import (TestRegisterTransformAlgorithm,
|
||||
RecordAlgorithm)
|
||||
RecordAlgorithm,
|
||||
TestOrderAlgorithm)
|
||||
from zipline.sources import (SpecificEquityTrades,
|
||||
DataFrameSource,
|
||||
DataPanelSource)
|
||||
@@ -164,3 +165,10 @@ 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)
|
||||
|
||||
@@ -216,6 +216,25 @@ class RecordAlgorithm(TradingAlgorithm):
|
||||
self.incr += 1
|
||||
self.record(incr=self.incr)
|
||||
|
||||
|
||||
class TestOrderAlgorithm(TradingAlgorithm):
|
||||
def initialize(self):
|
||||
self.incr = 0
|
||||
self.sale_price = None
|
||||
|
||||
def handle_data(self, data):
|
||||
print data[0]
|
||||
if self.incr == 0:
|
||||
assert 0 not in self.portfolio.positions
|
||||
else:
|
||||
assert self.portfolio.positions[0]['amount'] == \
|
||||
self.incr, "Orders not filled immediately."
|
||||
assert self.portfolio.positions[0]['last_sale_price'] == \
|
||||
data[0].price, "Orders not filled at current price."
|
||||
self.incr += 1
|
||||
self.order(0, 1)
|
||||
|
||||
|
||||
from zipline.algorithm import TradingAlgorithm
|
||||
from zipline.transforms import BatchTransform, batch_transform
|
||||
from zipline.transforms import MovingAverage
|
||||
|
||||
Reference in New Issue
Block a user