mirror of
https://github.com/wassname/catalyst.git
synced 2026-07-25 13:10:33 +08:00
ENH: Emit a rollup of day's performance in minutely emission mode.
During minute emissions, it is still helpful to have a final daily performance result, analogous to what would be the final packet in a daily emitted backtest, so that all transactions, etc. are contained in one place.
This commit is contained in:
@@ -232,24 +232,26 @@ class PerformanceTracker(object):
|
||||
def get_portfolio(self):
|
||||
return self.cumulative_performance.as_portfolio()
|
||||
|
||||
def to_dict(self):
|
||||
def to_dict(self, emission_type=None):
|
||||
"""
|
||||
Creates a dictionary representing the state of this tracker.
|
||||
Returns a dict object of the form described in header comments.
|
||||
"""
|
||||
if not emission_type:
|
||||
emission_type = self.emission_rate
|
||||
_dict = {
|
||||
'period_start': self.period_start,
|
||||
'period_end': self.period_end,
|
||||
'capital_base': self.capital_base,
|
||||
'cumulative_perf': self.cumulative_performance.to_dict(),
|
||||
}
|
||||
if self.emission_rate == 'daily':
|
||||
if emission_type == 'daily':
|
||||
_dict.update({'cumulative_risk_metrics':
|
||||
self.cumulative_risk_metrics.to_dict(),
|
||||
'daily_perf':
|
||||
self.todays_performance.to_dict(),
|
||||
'progress': self.progress})
|
||||
if self.emission_rate == 'minute':
|
||||
if emission_type == 'minute':
|
||||
# Currently reusing 'todays_performance' for intraday trading
|
||||
# result, should be analogous, but has the potential for needing
|
||||
# its own configuration down the line.
|
||||
|
||||
@@ -290,6 +290,17 @@ class AlgorithmSimulator(object):
|
||||
self.algo.recorded_vars
|
||||
yield message
|
||||
|
||||
# When emitting minutely, it is still useful to have a final
|
||||
# packet with the entire days performance rolled up.
|
||||
if self.perf_tracker.emission_rate == 'minute':
|
||||
daily_rollup = self.perf_tracker.to_dict(
|
||||
emission_type='daily'
|
||||
)
|
||||
daily_rollup['daily_perf']['recorded_vars'] = \
|
||||
self.algo.recorded_vars
|
||||
log.info("emitting daily rollup: %s" % daily_rollup)
|
||||
yield daily_rollup
|
||||
|
||||
yield risk_message
|
||||
|
||||
def update_universe(self, event):
|
||||
|
||||
Reference in New Issue
Block a user