Locks down the ability to easily override the algo's portfolio.

Starting down the path of making the portfolio completely read-only
with respect to the handle_data in algo.

The portfolio should only be changed during the course of running
the algorithm by the simulator.

This doesn't do a 100% protection, i.e. an algo could use _portfolio,
or the set_attr property, but hoping this helps guides algo writing
to treat the portfolio as read-only.
This commit is contained in:
Eddie Hebert
2012-11-05 13:40:23 -05:00
parent 96ba4c7d6c
commit 086c12ddf8
4 changed files with 45 additions and 2 deletions
+6 -2
View File
@@ -66,7 +66,7 @@ class TradingAlgorithm(object):
self.done = False
self.order = None
self.frame_count = 0
self.portfolio = None
self._portfolio = None
self.datetime = None
self.registered_transforms = {}
@@ -217,8 +217,12 @@ class TradingAlgorithm(object):
'args': args,
'kwargs': kwargs}
@property
def portfolio(self):
return self._portfolio
def set_portfolio(self, portfolio):
self.portfolio = portfolio
self._portfolio = portfolio
def set_order(self, order_callable):
self.order = order_callable