def __init__(self, data, **kwargs):
        """
        Data must be a DataFrame formatted like this:

        #################################################################################################
        #                     # GS                                # TW                                  #
        #                     # N10             # H10             # G14              # H14              #
        #                     # Price  # Volume # Price  # Volume # Price  # Metric3 # Price  # Metric3 #
        # 2013-12-20 00:09:15 # 101.00 # 1000   # 60.34  # 2500   # 400.00 # -0.0034 # Price # -5.0     #
        # 2013-12-20 00:09:17 # 201.00 # 2000   # 20.34  # 2500   # 200.00 # -2.0034 # Price # -2.0     #
        # etc...                                                                                        #
        #################################################################################################

        """
        assert isinstance(data.index, pd.tseries.index.DatetimeIndex)

        self.data = data
        # Unpack config dictionary with default values.
        self.sids = kwargs.get(
            'sids', list(set(['.'.join(tup[:2]) for tup in data.columns])))
        self.start = kwargs.get('start', data.index[0])
        self.end = kwargs.get('end', data.index[-1])

        # Hash_value for downstream sorting.
        self.arg_string = hash_args(data, **kwargs)

        self._raw_data = None
Esempio n. 2
0
    def __init__(self, tnfm_class, *args, **kwargs):
        assert isinstance(tnfm_class, (types.ObjectType, types.ClassType)), \
            "Stateful transform requires a class."
        assert hasattr(tnfm_class, 'update'), \
            "Stateful transform requires the class to have an update method"

        # Create an instance of our transform class.
        if isinstance(tnfm_class, TransformMeta):
            # Classes derived TransformMeta have their __call__
            # attribute overridden.  Since this is what is usually
            # used to create an instance, we have to delegate the
            # responsibility of creating an instance to
            # TransformMeta's parent class, which is 'type'. This is
            # what is implicitly done behind the scenes by the python
            # interpreter for most classes anyway, but here we have to
            # be explicit because we've overridden the method that
            # usually resolves to our super call.
            self.state = super(TransformMeta, tnfm_class).__call__(
                *args, **kwargs)
        # Normal object instantiation.
        else:
            self.state = tnfm_class(*args, **kwargs)
        # save the window_length of the state for external access.
        self.window_length = self.state.window_length
        # Create the string associated with this generator's output.
        self.namestring = tnfm_class.__name__ + hash_args(*args, **kwargs)
    def __init__(self, data, **kwargs):
        """
        Data must be a DataFrame formatted like this:

        #################################################################################################
        #                     # GS                                # TW                                  #
        #                     # N10             # H10             # G14              # H14              #
        #                     # Price  # Volume # Price  # Volume # Price  # Metric3 # Price  # Metric3 #
        # 2013-12-20 00:09:15 # 101.00 # 1000   # 60.34  # 2500   # 400.00 # -0.0034 # Price # -5.0     #
        # 2013-12-20 00:09:17 # 201.00 # 2000   # 20.34  # 2500   # 200.00 # -2.0034 # Price # -2.0     #
        # etc...                                                                                        #
        #################################################################################################

        """
        assert isinstance(data.index, pd.tseries.index.DatetimeIndex)

        self.data = data
        # Unpack config dictionary with default values.
        self.sids = kwargs.get('sids', list(set(['.'.join(tup[:2]) for tup in data.columns])))
        self.start = kwargs.get('start', data.index[0])
        self.end = kwargs.get('end', data.index[-1])

        # Hash_value for downstream sorting.
        self.arg_string = hash_args(data, **kwargs)

        self._raw_data = None
Esempio n. 4
0
    def __init__(self, data, **kwargs):
        assert isinstance(data.major_axis, pd.tseries.index.DatetimeIndex)

        self.data = data
        # Unpack config dictionary with default values.
        self.sids = kwargs.get('sids', data.items)
        self.start = kwargs.get('start', data.major_axis[0])
        self.end = kwargs.get('end', data.major_axis[-1])

        # Hash_value for downstream sorting.
        self.arg_string = hash_args(data, **kwargs)

        self._raw_data = None
Esempio n. 5
0
    def __init__(self, data, **kwargs):
        assert isinstance(data.index, pd.tseries.index.DatetimeIndex)

        self.data = data
        # Unpack config dictionary with default values.
        self.sids = kwargs.get('sids', data.columns)
        self.start = kwargs.get('start', data.index[0])
        self.end = kwargs.get('end', data.index[-1])

        # Hash_value for downstream sorting.
        self.arg_string = hash_args(data, **kwargs)

        self._raw_data = None
Esempio n. 6
0
    def __init__(self, *args, **kwargs):
        # We shouldn't get any positional arguments.
        assert len(args) == 0

        # Default to None for event_list and filter.
        self.event_list = kwargs.get('event_list')
        self.filter = kwargs.get('filter')

        if self.event_list is not None:
            # If event_list is provided, extract parameters from there
            # This isn't really clean and ultimately I think this
            # class should serve a single purpose (either take an
            # event_list or autocreate events).
            self.count = kwargs.get('count', len(self.event_list))
            self.sids = kwargs.get(
                'sids',
                np.unique([event.sid for event in self.event_list]).tolist())
            self.start = kwargs.get('start', self.event_list[0].dt)
            self.end = kwargs.get('start', self.event_list[-1].dt)
            self.delta = kwargs.get(
                'delta',
                self.event_list[1].dt - self.event_list[0].dt)
            self.concurrent = kwargs.get('concurrent', False)

        else:
            # Unpack config dictionary with default values.
            self.count = kwargs.get('count', 500)
            self.sids = kwargs.get('sids', [1, 2])
            self.start = kwargs.get(
                'start',
                datetime(2008, 6, 6, 15, tzinfo=pytz.utc))
            self.delta = kwargs.get(
                'delta',
                timedelta(minutes=1))
            self.concurrent = kwargs.get('concurrent', False)

        # Hash_value for downstream sorting.
        self.arg_string = hash_args(*args, **kwargs)

        self.generator = self.create_fresh_generator()
Esempio n. 7
0
 def get_hash(self):
     """
     There should only ever be one TSC in the system, so
     we don't bother passing args into the hash.
     """
     return self.__class__.__name__ + hash_args()