SimulatedLite

This commit is contained in:
scottsanderson
2012-08-21 14:34:18 -04:00
parent 3bcdf0f2af
commit d24bfbbf43
2 changed files with 27 additions and 3 deletions
+23 -1
View File
@@ -121,7 +121,6 @@ class SimulatedTrading(object):
# exit status flag
self.success = False
def simulate(self, blocking=True, send_sighup=False):
# for non-blocking,
@@ -356,3 +355,26 @@ class SimulatedTrading(object):
#-------------------
return sim
class SimulatedTradingLite(object):
"""
SimulatedTrading without multiprocess and without zmq.
Useful for profiling the core logic and for rapid testing
of new features.
"""
def __init__(self,
sources,
transforms,
algorithm,
environment,
style):
self.date_sorted = date_sorted_sources(*sources)
self.transforms = transforms
# Formerly merged_transforms.
self.with_tnfms = sequential_transforms(self.date_sorted, *self.transforms)
self.trading_client = tsc(algorithm, environment, style)
self.gen = self.trading_client.simulate(self.with_tnfms)
def get_results(self):
return self.gen
+4 -2
View File
@@ -11,6 +11,8 @@ class Timeout(Exception):
def __init__(self, frame, message=''):
self.frame = frame
self.message = message
# TODO: fix code replication here.
class timeout(object):
"""
@@ -33,7 +35,7 @@ class timeout(object):
@wraps(fn)
def call_fn_with_timeout(*args, **kwargs):
# Set the alarm.
# Set the alarm, saving any handler that existed previously.
signal.signal(signal.SIGALRM, self.handler)
signal.setitimer(signal.ITIMER_REAL, self.seconds, 0)
try:
@@ -45,7 +47,7 @@ class timeout(object):
# call to fn takes too long.
finally:
signal.setitimer(signal.ITIMER_REAL, 0, 0)
signal.signal(signal.SIGALRM, signal.SIG_DFL)
signal.signal(signal.SIGALRM, self.prior_handler)
# Return the value of fn if it finished before the alarm. This
# won't execute if the Timeout was raised.