mirror of
https://github.com/wassname/catalyst.git
synced 2026-08-12 11:50:11 +08:00
refactored so that slippage is implemented as pluggable classes.
This commit is contained in:
@@ -4,8 +4,7 @@ from collections import defaultdict
|
||||
|
||||
from zipline.test_algorithms import ExceptionAlgorithm, DivByZeroAlgorithm, \
|
||||
InitializeTimeoutAlgorithm, TooMuchProcessingAlgorithm
|
||||
from zipline.finance.trading import SIMULATION_STYLE
|
||||
from zipline.core.devsimulator import AddressAllocator
|
||||
from zipline.finance.slippage import FixedSlippage
|
||||
from zipline.lines import SimulatedTrading
|
||||
from zipline.gens.transform import StatefulTransform
|
||||
from zipline.utils.timeout import TimeoutException
|
||||
@@ -29,7 +28,7 @@ class ExceptionTestCase(TestCase):
|
||||
def setUp(self):
|
||||
self.zipline_test_config = {
|
||||
'sid' : 133,
|
||||
'simulation_style' : SIMULATION_STYLE.FIXED_SLIPPAGE
|
||||
'slippage' : FixedSlippage()
|
||||
}
|
||||
setup_logger(self)
|
||||
|
||||
|
||||
+9
-11
@@ -16,11 +16,12 @@ from zipline.lines import SimulatedTrading
|
||||
from zipline.finance.performance import PerformanceTracker
|
||||
from zipline.utils.protocol_utils import ndict
|
||||
from zipline.finance.trading import TransactionSimulator
|
||||
from zipline.utils.test_utils import \
|
||||
setup_logger, \
|
||||
teardown_logger,\
|
||||
from zipline.finance.slippage import VolumeShareSlippage
|
||||
from zipline.utils.test_utils import(
|
||||
setup_logger,
|
||||
teardown_logger,
|
||||
assert_single_position
|
||||
|
||||
)
|
||||
|
||||
DEFAULT_TIMEOUT = 15 # seconds
|
||||
EXTENDED_TIMEOUT = 90
|
||||
@@ -258,7 +259,7 @@ class FinanceTestCase(TestCase):
|
||||
|
||||
sid = 1
|
||||
trading_environment = factory.create_trading_environment()
|
||||
trade_sim = TransactionSimulator([sid])
|
||||
trade_sim = TransactionSimulator()
|
||||
price = [10.1] * trade_count
|
||||
volume = [100] * trade_count
|
||||
start_date = trading_environment.first_open
|
||||
@@ -315,12 +316,9 @@ class FinanceTestCase(TestCase):
|
||||
for trade in generated_trades:
|
||||
if trade_delay:
|
||||
trade.dt = trade.dt + trade_delay
|
||||
txn = trade_sim.apply_trade_to_open_orders(trade)
|
||||
if txn:
|
||||
transactions.append(txn)
|
||||
trade.TRANSACTION = txn
|
||||
else:
|
||||
trade.TRANSACTION = None
|
||||
trade_sim.update(trade)
|
||||
if trade.TRANSACTION:
|
||||
transactions.append(trade.TRANSACTION)
|
||||
|
||||
tracker.process_event(trade)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user