PERF: Only update the portfolio once per dt.

So that each reference to `.portfolio` in the algoscript,
cache the value of the portfolio, and mark the need for a new
value at the end of each dt in the tradesimulation loop.
This commit is contained in:
Eddie Hebert
2013-11-19 14:39:19 -05:00
parent 6d46eb71ea
commit ccb7f493f7
2 changed files with 9 additions and 1 deletions
+7 -1
View File
@@ -130,6 +130,9 @@ class TradingAlgorithm(object):
if not self.blotter:
self.blotter = Blotter()
self.portfolio_needs_update = True
self._portfolio = None
# an algorithm subclass needs to set initialized to True when
# it is fully initialized.
self.initialized = False
@@ -397,7 +400,10 @@ class TradingAlgorithm(object):
def updated_portfolio(self):
# internally this will cause a refresh of the
# period performance calculations.
return self.perf_tracker.get_portfolio()
if self.portfolio_needs_update:
self._portfolio = self.perf_tracker.get_portfolio()
self.portfolio_needs_update = False
return self._portfolio
def set_logger(self, logger):
self.logger = logger
+2
View File
@@ -195,6 +195,8 @@ class AlgorithmSimulator(object):
)
self.algo.perf_tracker.handle_intraday_close()
self.portfolio_needs_update = True
risk_message = self.algo.perf_tracker.handle_simulation_end()
yield risk_message