mirror of
https://github.com/wassname/catalyst.git
synced 2026-07-21 12:30:16 +08:00
tsc work
This commit is contained in:
@@ -3,9 +3,13 @@ from datetime import datetime, timedelta
|
||||
from zipline.utils.factory import create_trading_environment
|
||||
from zipline.test_algorithms import TestAlgorithm
|
||||
|
||||
from zipline.gens.composites import SourceBundle, TransformBundle, date_sorted_sources, merged_transforms
|
||||
from zipline.gens.composites import SourceBundle, TransformBundle, \
|
||||
date_sorted_sources, merged_transforms
|
||||
from zipline.gens.tradegens import SpecificEquityTrades
|
||||
from zipline.gens.transform import MovingAverage, Passthrough
|
||||
from zipline.gens.tradesimulation import trade_simulation_client as tsc
|
||||
|
||||
import zipline.protocol as zp
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -45,13 +49,20 @@ if __name__ == "__main__":
|
||||
sort_out = date_sorted_sources(source_bundles)
|
||||
|
||||
passthrough = TransformBundle(Passthrough, (), {})
|
||||
mavg_price = TransformBundle(MovingAverage, (timedelta(minutes = 20), ['price', 'volume']), {})
|
||||
mavg_price = TransformBundle(MovingAverage, (timedelta(minutes = 20), ['price']), {})
|
||||
tnfm_bundles = (passthrough, mavg_price)
|
||||
|
||||
merge_out = merged_transforms(sort_out, tnfm_bundles)
|
||||
|
||||
for message in merge_out:
|
||||
print "Event: \n", message.event
|
||||
print "Transforms: \n", message.tnfms
|
||||
|
||||
# for message in merge_out:
|
||||
# print "Event: \n", message.event
|
||||
# print "Transforms: \n", message.tnfms
|
||||
|
||||
algo = TestAlgorithm(2, 100, 100)
|
||||
environment = create_trading_environment()
|
||||
style = zp.SIMULATION_STYLE.PARTIAL_VOLUME
|
||||
|
||||
client_out = tsc(merge_out, algo, environment, style)
|
||||
|
||||
for message in client_out:
|
||||
print message
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
import logbook
|
||||
|
||||
from numbers import Integral
|
||||
|
||||
from zipline.gens import stateful_transform
|
||||
from zipline import ndict
|
||||
|
||||
from zipline.gens.transform import stateful_transform
|
||||
from zipline.finance.trading import TransactionSimulator
|
||||
from zipline.finance.performance import PerformanceTracker
|
||||
|
||||
@@ -44,20 +48,22 @@ def trade_simulation_client(stream_in, algo, environment, sim_style):
|
||||
|
||||
# Initialize txn_sim's dictionary of orders here so that we can
|
||||
# reference it from within the user's algorithm.
|
||||
|
||||
import nose.tools; nose.tools.set_trace()
|
||||
sids = algo.get_sid_filter()
|
||||
open_orders = {}
|
||||
|
||||
for sid in sids:
|
||||
open_orders[sids] = []
|
||||
open_orders[sid] = []
|
||||
|
||||
# Closure to pass into the user's algo to allow placing orders
|
||||
# into the txn_sim's dict of open orders.
|
||||
def order(self, sid, amount):
|
||||
assert sid in sids, "Order on invalid sid: %i" % sid
|
||||
order = zp.ndict({
|
||||
order = ndict({
|
||||
'dt' : self.current_dt,
|
||||
'sid' : sid,
|
||||
'amount' : int(amount)
|
||||
'amount' : int(amount),
|
||||
'filled' : 0
|
||||
})
|
||||
|
||||
@@ -75,7 +81,7 @@ def trade_simulation_client(stream_in, algo, environment, sim_style):
|
||||
algo.set_order(order)
|
||||
|
||||
# Provide a logbook logging interface to user code.
|
||||
algo.set_logger(Logger("Algolog"))
|
||||
algo.set_logger(logbook.Logger("Algolog"))
|
||||
|
||||
# Call user-defined initialize method before we process any
|
||||
# events.
|
||||
|
||||
Reference in New Issue
Block a user