added a class to throw exceptions from the algorithm

This commit is contained in:
fawce
2012-07-21 09:52:06 -04:00
parent 5dd35a4709
commit f364cde3d2
3 changed files with 40 additions and 5 deletions
-1
View File
@@ -4,7 +4,6 @@ from unittest2 import TestCase, skip
from zipline.core.monitor import Controller
class TestMonitor(TestCase):
def setUp(self):
self.log_handler = LoggingHandler()
-2
View File
@@ -180,8 +180,6 @@ class TradeSimulationClient(Component):
- Set the current portfolio for the algorithm as per protocol.
- Construct data based on backlog of events, send to algorithm.
"""
# current_portfolio = self.perf.get_portfolio()
# self.algorithm.set_portfolio(current_portfolio)
data = self.get_data()
if len(data) > 0:
+40 -2
View File
@@ -138,17 +138,55 @@ class NoopAlgorithm(object):
def get_sid_filter(self):
return None
class ExceptionAlgorithm(object):
"""
Dolce fa niente.
"""
def __init__(self, throw_from):
self.throw_from == throw_from
def initialize(self):
if self.throw_from == "initialize":
raise Exception("Algo exception in initialize")
else:
pass
def set_order(self, order_callable):
if self.throw_from == "set_order":
raise Exception("Algo exception in set_order")
else:
pass
def set_portfolio(self, portfolio):
if self.throw_from == "set_portfolio":
raise Exception("Algo exception in set_portfolio")
else:
pass
def handle_data(self, data):
if self.throw_from == "handle_data":
raise Exception("Algo exception in handle_data")
else:
pass
def get_sid_filter(self):
if self.throw_from == "get_sid_filter":
raise Exception("Algo exception in get_sid_filter")
else:
return None
class TestPrintAlgorithm():
def __init__(self):
pass
def initialize(self):
print "Initializing..."
def set_order(self, order_callable):
pass
def set_portfolio(self, portfolio):
pass