MAINT: Refactor AlgorithmSimulator.transform.

Breaks out the main snapshot processing loop into its own function, and does
some minor variable renaming-shuffling.

Adds `TradingAlgorithm.on_dt_changed`, a function to be called when the
simulation dt changes, prior to processing any events.

There should be no difference in behavior as a result of this change.
This commit is contained in:
Scott Sanderson
2014-07-18 15:04:20 -04:00
parent 8d16efc5c4
commit 0176279404
2 changed files with 101 additions and 62 deletions
+11 -1
View File
@@ -631,12 +631,22 @@ class TradingAlgorithm(object):
def set_logger(self, logger):
self.logger = logger
def set_datetime(self, dt):
def on_dt_changed(self, dt):
"""
Callback triggered by the simulation loop whenever the current dt
changes.
Any logic that should happen exactly once at the start of each datetime
group should happen here.
"""
assert isinstance(dt, datetime), \
"Attempt to set algorithm's current time with non-datetime"
assert dt.tzinfo == pytz.utc, \
"Algorithm expects a utc datetime"
self.datetime = dt
self.perf_tracker.set_date(dt)
self.blotter.set_date(dt)
@api_method
def get_datetime(self):