mirror of
https://github.com/wassname/catalyst.git
synced 2026-07-02 12:29:43 +08:00
Merge pull request #92 from quantopian/noop_env_fix_1470
added a decorator for applying an environment to a function context.
This commit is contained in:
@@ -18,6 +18,7 @@ import pytz
|
||||
import logbook
|
||||
import datetime
|
||||
|
||||
from functools import wraps
|
||||
from collections import defaultdict, OrderedDict
|
||||
from delorean import Delorean
|
||||
from pandas import DatetimeIndex
|
||||
@@ -356,3 +357,18 @@ 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):
|
||||
@wraps(func)
|
||||
def wrapper(*args, **kwargs):
|
||||
with self.env:
|
||||
return func(*args, **kwargs)
|
||||
return wrapper
|
||||
|
||||
Reference in New Issue
Block a user