mirror of
https://github.com/wassname/catalyst.git
synced 2026-09-12 12:12:04 +08:00
MAINT: Use Python 3 compatible metaclass.
Use six's with_metaclass to have objects that use metaclasses, in both Python 2 and 3. Otherwise, in Python 3 the objects were being treated as if they did not have a metaclass, when the Python 2 syntax is used, leading to errors because of missing attributes, etc.
This commit is contained in:
@@ -20,6 +20,9 @@ import math
|
|||||||
|
|
||||||
from copy import copy
|
from copy import copy
|
||||||
from functools import partial
|
from functools import partial
|
||||||
|
|
||||||
|
from six import with_metaclass
|
||||||
|
|
||||||
from zipline.protocol import DATASOURCE_TYPE
|
from zipline.protocol import DATASOURCE_TYPE
|
||||||
import zipline.utils.math_utils as zp_math
|
import zipline.utils.math_utils as zp_math
|
||||||
|
|
||||||
@@ -152,9 +155,7 @@ def create_transaction(event, order, price, amount):
|
|||||||
return transaction
|
return transaction
|
||||||
|
|
||||||
|
|
||||||
class SlippageModel(object):
|
class SlippageModel(with_metaclass(abc.ABCMeta)):
|
||||||
|
|
||||||
__metaclass__ = abc.ABCMeta
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def volume_for_bar(self):
|
def volume_for_bar(self):
|
||||||
|
|||||||
@@ -3,13 +3,13 @@ from abc import (
|
|||||||
abstractproperty
|
abstractproperty
|
||||||
)
|
)
|
||||||
|
|
||||||
|
from six import with_metaclass
|
||||||
|
|
||||||
from zipline.protocol import DATASOURCE_TYPE
|
from zipline.protocol import DATASOURCE_TYPE
|
||||||
from zipline.protocol import Event
|
from zipline.protocol import Event
|
||||||
|
|
||||||
|
|
||||||
class DataSource(object):
|
class DataSource(with_metaclass(ABCMeta)):
|
||||||
|
|
||||||
__metaclass__ = ABCMeta
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def event_type(self):
|
def event_type(self):
|
||||||
|
|||||||
@@ -15,20 +15,19 @@
|
|||||||
|
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
|
|
||||||
from six import string_types
|
from six import string_types, with_metaclass
|
||||||
|
|
||||||
from zipline.transforms.utils import EventWindow, TransformMeta
|
from zipline.transforms.utils import EventWindow, TransformMeta
|
||||||
from zipline.errors import WrongDataForTransform
|
from zipline.errors import WrongDataForTransform
|
||||||
|
|
||||||
|
|
||||||
class MovingAverage(object):
|
class MovingAverage(with_metaclass(TransformMeta)):
|
||||||
"""
|
"""
|
||||||
Class that maintains a dictionary from sids to
|
Class that maintains a dictionary from sids to
|
||||||
MovingAverageEventWindows. For each sid, we maintain moving
|
MovingAverageEventWindows. For each sid, we maintain moving
|
||||||
averages over any number of distinct fields (For example, we can
|
averages over any number of distinct fields (For example, we can
|
||||||
maintain a sid's average volume as well as its average price.)
|
maintain a sid's average volume as well as its average price.)
|
||||||
"""
|
"""
|
||||||
__metaclass__ = TransformMeta
|
|
||||||
|
|
||||||
def __init__(self, fields='price',
|
def __init__(self, fields='price',
|
||||||
market_aware=True, window_length=None, delta=None):
|
market_aware=True, window_length=None, delta=None):
|
||||||
|
|||||||
@@ -17,13 +17,14 @@ from zipline.errors import WrongDataForTransform
|
|||||||
from zipline.transforms.utils import TransformMeta
|
from zipline.transforms.utils import TransformMeta
|
||||||
from collections import defaultdict, deque
|
from collections import defaultdict, deque
|
||||||
|
|
||||||
|
from six import with_metaclass
|
||||||
|
|
||||||
class Returns(object):
|
|
||||||
|
class Returns(with_metaclass(TransformMeta)):
|
||||||
"""
|
"""
|
||||||
Class that maintains a dictionary from sids to the sid's
|
Class that maintains a dictionary from sids to the sid's
|
||||||
closing price N trading days ago.
|
closing price N trading days ago.
|
||||||
"""
|
"""
|
||||||
__metaclass__ = TransformMeta
|
|
||||||
|
|
||||||
def __init__(self, window_length):
|
def __init__(self, window_length):
|
||||||
self.window_length = window_length
|
self.window_length = window_length
|
||||||
|
|||||||
@@ -16,19 +16,20 @@
|
|||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from math import sqrt
|
from math import sqrt
|
||||||
|
|
||||||
|
from six import with_metaclass
|
||||||
|
|
||||||
from zipline.errors import WrongDataForTransform
|
from zipline.errors import WrongDataForTransform
|
||||||
from zipline.transforms.utils import EventWindow, TransformMeta
|
from zipline.transforms.utils import EventWindow, TransformMeta
|
||||||
import zipline.utils.math_utils as zp_math
|
import zipline.utils.math_utils as zp_math
|
||||||
|
|
||||||
|
|
||||||
class MovingStandardDev(object):
|
class MovingStandardDev(with_metaclass(TransformMeta)):
|
||||||
"""
|
"""
|
||||||
Class that maintains a dictionary from sids to
|
Class that maintains a dictionary from sids to
|
||||||
MovingStandardDevWindows. For each sid, we maintain a the
|
MovingStandardDevWindows. For each sid, we maintain a the
|
||||||
standard deviation of all events falling within the specified
|
standard deviation of all events falling within the specified
|
||||||
window.
|
window.
|
||||||
"""
|
"""
|
||||||
__metaclass__ = TransformMeta
|
|
||||||
|
|
||||||
def __init__(self, market_aware=True, window_length=None, delta=None):
|
def __init__(self, market_aware=True, window_length=None, delta=None):
|
||||||
|
|
||||||
|
|||||||
@@ -26,6 +26,8 @@ from datetime import datetime
|
|||||||
from collections import deque
|
from collections import deque
|
||||||
from abc import ABCMeta, abstractmethod
|
from abc import ABCMeta, abstractmethod
|
||||||
|
|
||||||
|
from six import with_metaclass
|
||||||
|
|
||||||
from zipline.protocol import DATASOURCE_TYPE
|
from zipline.protocol import DATASOURCE_TYPE
|
||||||
from zipline.gens.utils import assert_sort_unframe_protocol, hash_args
|
from zipline.gens.utils import assert_sort_unframe_protocol, hash_args
|
||||||
from zipline.finance import trading
|
from zipline.finance import trading
|
||||||
@@ -147,7 +149,7 @@ class StatefulTransform(object):
|
|||||||
yield out_message
|
yield out_message
|
||||||
|
|
||||||
|
|
||||||
class EventWindow(object):
|
class EventWindow(with_metaclass(ABCMeta)):
|
||||||
"""
|
"""
|
||||||
Abstract base class for transform classes that calculate iterative
|
Abstract base class for transform classes that calculate iterative
|
||||||
metrics on events within a given timedelta. Maintains a list of
|
metrics on events within a given timedelta. Maintains a list of
|
||||||
@@ -166,7 +168,6 @@ class EventWindow(object):
|
|||||||
price.
|
price.
|
||||||
"""
|
"""
|
||||||
# Mark this as an abstract base class.
|
# Mark this as an abstract base class.
|
||||||
__metaclass__ = ABCMeta
|
|
||||||
|
|
||||||
def __init__(self, market_aware=True, window_length=None, delta=None):
|
def __init__(self, market_aware=True, window_length=None, delta=None):
|
||||||
|
|
||||||
|
|||||||
@@ -15,15 +15,16 @@
|
|||||||
|
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
|
|
||||||
|
from six import with_metaclass
|
||||||
|
|
||||||
from zipline.errors import WrongDataForTransform
|
from zipline.errors import WrongDataForTransform
|
||||||
from zipline.transforms.utils import EventWindow, TransformMeta
|
from zipline.transforms.utils import EventWindow, TransformMeta
|
||||||
|
|
||||||
|
|
||||||
class MovingVWAP(object):
|
class MovingVWAP(with_metaclass(TransformMeta)):
|
||||||
"""
|
"""
|
||||||
Class that maintains a dictionary from sids to VWAPEventWindows.
|
Class that maintains a dictionary from sids to VWAPEventWindows.
|
||||||
"""
|
"""
|
||||||
__metaclass__ = TransformMeta
|
|
||||||
|
|
||||||
def __init__(self, market_aware=True, delta=None, window_length=None):
|
def __init__(self, market_aware=True, delta=None, window_length=None):
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user