mirror of
https://github.com/wassname/catalyst.git
synced 2026-07-04 03:17:18 +08:00
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:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user