added a decorator for applying an environment to a function context.

This commit is contained in:
fawce
2013-02-19 12:52:17 -05:00
parent 97cbea2514
commit 9cc043f130
+14
View File
@@ -356,3 +356,17 @@ class DailyReturn(object):
def __repr__(self):
return str(self.date) + " - " + str(self.returns)
class use_environment(object):
"""A decorator to wrap a method in a particular
trading environment."""
def __init__(self, environment):
self.env = environment
def __call__(self, func):
def wrapper(*args, **kwargs):
with self.env:
return func(*args, **kwargs)
return wrapper