Backtest protocol, ala Bredeche.

This commit is contained in:
Stephen Diehl
2012-03-08 17:18:29 -05:00
parent defa3186ca
commit 23a4f0680b
2 changed files with 34 additions and 2 deletions
+13 -2
View File
@@ -14,7 +14,8 @@ import humanhash
from datetime import datetime
import zipline.util as qutil
from zipline.protocol import CONTROL_PROTOCOL, COMPONENT_STATE
from zipline.protocol import CONTROL_PROTOCOL, COMPONENT_STATE, \
COMPONENT_FAILURE, BACKTEST_STATE
class Component(object):
"""
@@ -66,6 +67,7 @@ class Component(object):
self.controller = None
self.heartbeat_timeout = 2000
self.state_flag = COMPONENT_STATE.OK
self.error_state = COMPONENT_FAILURE.NOFAILURE
self.on_done = None
self._exception = None
@@ -254,8 +256,17 @@ class Component(object):
# Internal Maintenance
# ----------------------
def signal_exception(self, exc=None):
def signal_exception(self, exc=None, scope=None):
if scope == 'algo':
self.error_state = COMPONENT_FAILURE.ALGOEXCEPT
else:
self.error_state = COMPONENT_FAILURE.HOSTEXCEPT
self.state_flag = COMPONENT_STATE.EXCEPTION
# mark the time of failure so we can track the failure
# progogation through the system.
self.stop_tic = time.time()
self._exception = exc
+21
View File
@@ -274,6 +274,27 @@ COMPONENT_STATE = Enum(
'EXCEPTION' , # 2
)
# NOFAILURE - Component is either not running or has not failed
# ALGOEXCEPT - Exception thrown in the given algorithm
# HOSTEXCEPT - Exception thrown on our end.
# INTERRUPT - Manually interuptted by user
COMPONENT_FAILURE = Enum(
'NOFAILURE' ,
'ALGOEXCEPT' ,
'HOSTEXCEPT' ,
'INTERRUPT' ,
)
BACKTEST_STATE = Enum(
'IDLE' ,
'QUEUED' ,
'INPROGRESS' ,
'CANCELLED' , # cancelled ( before natural completion )
'EXCEPTION' , # failure ( due to unnatural causes )
'DONE' , # done ( naturally completed )
)
# ==================
# Datasource Protocol
# ==================