mirror of
https://github.com/wassname/catalyst.git
synced 2026-07-02 09:02:15 +08:00
fixes for max drawdown
This commit is contained in:
@@ -197,7 +197,7 @@ class PerformanceTracker(object):
|
||||
# save the transactions for the daily periods
|
||||
keep_transactions = True
|
||||
)
|
||||
|
||||
|
||||
for sid in sid_list:
|
||||
self.cumulative_performance.positions[sid] = Position(sid)
|
||||
self.todays_performance.positions[sid] = Position(sid)
|
||||
@@ -207,6 +207,13 @@ class PerformanceTracker(object):
|
||||
event.perf_message = self.handle_simulation_end()
|
||||
del event['TRANSACTION']
|
||||
return event
|
||||
elif self.exceeded_max_loss:
|
||||
# in case of max_loss, signal to downstream
|
||||
# generators that we are done.
|
||||
event.dt = "DONE"
|
||||
event.perf_message = self.handle_simulation_end()
|
||||
del event['TRANSACTION']
|
||||
return event
|
||||
else:
|
||||
event.perf_message = self.process_event(event)
|
||||
event.portfolio = self.get_portfolio()
|
||||
@@ -251,7 +258,7 @@ class PerformanceTracker(object):
|
||||
|
||||
|
||||
def process_event(self, event):
|
||||
|
||||
|
||||
message = None
|
||||
|
||||
if self.exceeded_max_loss:
|
||||
@@ -275,12 +282,12 @@ class PerformanceTracker(object):
|
||||
#calculate performance as of last trade
|
||||
self.cumulative_performance.calculate_performance()
|
||||
self.todays_performance.calculate_performance()
|
||||
|
||||
|
||||
|
||||
return message
|
||||
|
||||
def handle_market_close(self):
|
||||
|
||||
|
||||
# add the return results from today to the list of DailyReturn objects.
|
||||
todays_date = self.market_close.replace(hour=0, minute=0, second=0)
|
||||
todays_return_obj = risk.DailyReturn(
|
||||
@@ -338,7 +345,7 @@ class PerformanceTracker(object):
|
||||
self.market_close,
|
||||
keep_transactions = True
|
||||
)
|
||||
|
||||
|
||||
return daily_update
|
||||
|
||||
def handle_simulation_end(self):
|
||||
|
||||
@@ -87,7 +87,7 @@ class TradeSimulationClient(object):
|
||||
self.sids
|
||||
)
|
||||
with_portfolio = perf_tracker.transform(with_filled_orders)
|
||||
|
||||
|
||||
# Pass the messages from perf along with the trading client's
|
||||
# state into the algorithm for simulation. We provide the
|
||||
# trading client so that the algorithm can place new orders
|
||||
@@ -97,7 +97,7 @@ class TradeSimulationClient(object):
|
||||
ordering_client.state,
|
||||
self.algo,
|
||||
)
|
||||
|
||||
|
||||
# The algorithm will yield a daily_results message (as
|
||||
# calculated by the performance tracker) at the end of each
|
||||
# day. It will also yield a risk report at the end of the
|
||||
|
||||
Reference in New Issue
Block a user