Example #1
0
    def __init__(self, wrapper, records_arr, close, idx_field='idx', **kwargs):
        Records.__init__(
            self,
            wrapper,
            records_arr,
            idx_field=idx_field,
            close=close,
            **kwargs
        )
        self._close = broadcast_to(close, wrapper.dummy(group_by=False))

        if not all(field in records_arr.dtype.names for field in order_dt.names):
            raise TypeError("Records array must match order_dt")
Example #2
0
    def __init__(self, records_arr, ts, freq=None, idx_field='end_idx', group_by=None):
        Records.__init__(
            self,
            records_arr,
            ArrayWrapper.from_obj(ts, freq=freq),
            idx_field=idx_field,
            group_by=group_by
        )
        PandasIndexer.__init__(self, _indexing_func)

        if not all(field in records_arr.dtype.names for field in drawdown_dt.names):
            raise ValueError("Records array must have all fields defined in drawdown_dt")

        self.ts = ts
Example #3
0
    def __init__(self, wrapper, records_arr, ts, idx_field='end_idx'):
        Records.__init__(self, wrapper, records_arr, idx_field=idx_field)
        Configured.__init__(self,
                            wrapper=wrapper,
                            records_arr=records_arr,
                            ts=ts,
                            idx_field=idx_field)
        self._ts = ts

        if not all(field in records_arr.dtype.names
                   for field in drawdown_dt.names):
            raise ValueError(
                "Records array must have all fields defined in drawdown_dt")

        PandasIndexer.__init__(self, _indexing_func)
Example #4
0
    def __init__(self, wrapper, records_arr, close, idx_field='exit_idx'):
        Records.__init__(self, wrapper, records_arr, idx_field=idx_field)
        Configured.__init__(self,
                            wrapper=wrapper,
                            records_arr=records_arr,
                            close=close,
                            idx_field=idx_field)
        self.close = close

        if not all(field in records_arr.dtype.names
                   for field in event_dt.names):
            raise ValueError(
                "Records array must have all fields defined in event_dt")

        PandasIndexer.__init__(self, _indexing_func)
Example #5
0
 def _indexing_func(self, pd_indexing_func):
     """Perform indexing on `Drawdowns`."""
     new_wrapper, new_records_arr, _, col_idxs = \
         Records._indexing_func_meta(self, pd_indexing_func)
     new_ts = new_wrapper.wrap(self.ts.values[:, col_idxs], group_by=False)
     return self.copy(wrapper=new_wrapper,
                      records_arr=new_records_arr,
                      ts=new_ts)
Example #6
0
    def __init__(self,
                 wrapper,
                 records_arr,
                 ts,
                 idx_field='end_idx',
                 **kwargs):
        Records.__init__(self,
                         wrapper,
                         records_arr,
                         idx_field=idx_field,
                         ts=ts,
                         **kwargs)
        self._ts = ts

        if not all(field in records_arr.dtype.names
                   for field in drawdown_dt.names):
            raise TypeError("Records array must match drawdown_dt")
Example #7
0
    def __init__(self,
                 wrapper: ArrayWrapper,
                 records_arr: tp.RecordArray,
                 ts: tp.ArrayLike,
                 idx_field: str = 'end_idx',
                 **kwargs) -> None:
        Records.__init__(self,
                         wrapper,
                         records_arr,
                         idx_field=idx_field,
                         ts=ts,
                         **kwargs)
        self._ts = broadcast_to(ts, wrapper.dummy(group_by=False))

        if not all(field in records_arr.dtype.names
                   for field in drawdown_dt.names):
            raise TypeError("Records array must match drawdown_dt")
Example #8
0
    def __init__(self,
                 records_arr,
                 main_price,
                 freq=None,
                 idx_field='exit_idx'):
        Records.__init__(self,
                         records_arr,
                         ArrayWrapper.from_obj(main_price, freq=freq),
                         idx_field=idx_field)
        PandasIndexer.__init__(self, _indexing_func)

        if not all(field in records_arr.dtype.names
                   for field in event_dt.names):
            raise ValueError(
                "Records array must have all fields defined in event_dt")

        self.main_price = main_price
Example #9
0
 def _indexing_func_meta(self, pd_indexing_func):
     """Perform indexing on `Orders` and return metadata."""
     new_wrapper, new_records_arr, group_idxs, col_idxs = \
         Records._indexing_func_meta(self, pd_indexing_func)
     new_close = new_wrapper.wrap(to_2d(self.close, raw=True)[:, col_idxs],
                                  group_by=False)
     return self.copy(wrapper=new_wrapper,
                      records_arr=new_records_arr,
                      close=new_close), group_idxs, col_idxs
Example #10
0
 def indexing_func(self: DrawdownsT,
                   pd_indexing_func: tp.PandasIndexingFunc,
                   **kwargs) -> DrawdownsT:
     """Perform indexing on `Drawdowns`."""
     new_wrapper, new_records_arr, _, col_idxs = \
         Records.indexing_func_meta(self, pd_indexing_func, **kwargs)
     new_ts = new_wrapper.wrap(self.ts.values[:, col_idxs], group_by=False)
     return self.copy(wrapper=new_wrapper,
                      records_arr=new_records_arr,
                      ts=new_ts)
Example #11
0
    def __init__(self, wrapper, records_arr, close, idx_field='exit_idx',
                 trade_type=TradeType.Trade, **kwargs):
        Records.__init__(
            self,
            wrapper,
            records_arr,
            idx_field=idx_field,
            close=close,
            trade_type=trade_type,
            **kwargs
        )
        self._close = broadcast_to(close, wrapper.dummy(group_by=False))
        self._trade_type = trade_type

        if trade_type == TradeType.Trade:
            if not all(field in records_arr.dtype.names for field in trade_dt.names):
                raise TypeError("Records array must match trade_dt")
        else:
            if not all(field in records_arr.dtype.names for field in position_dt.names):
                raise TypeError("Records array must match position_dt")
Example #12
0
 def indexing_func_meta(
         self: OrdersT, pd_indexing_func: tp.PandasIndexingFunc,
         **kwargs) -> tp.Tuple[OrdersT, tp.MaybeArray, tp.Array1d]:
     """Perform indexing on `Orders` and return metadata."""
     new_wrapper, new_records_arr, group_idxs, col_idxs = \
         Records.indexing_func_meta(self, pd_indexing_func, **kwargs)
     new_close = new_wrapper.wrap(to_2d(self.close, raw=True)[:, col_idxs],
                                  group_by=False)
     return self.copy(wrapper=new_wrapper,
                      records_arr=new_records_arr,
                      close=new_close), group_idxs, col_idxs
Example #13
0
 def indexing_func(self: RangesT, pd_indexing_func: tp.PandasIndexingFunc,
                   **kwargs) -> RangesT:
     """Perform indexing on `Ranges`."""
     new_wrapper, new_records_arr, _, col_idxs = \
         Records.indexing_func_meta(self, pd_indexing_func, **kwargs)
     if self.ts is not None:
         new_ts = new_wrapper.wrap(self.ts.values[:, col_idxs],
                                   group_by=False)
     else:
         new_ts = None
     return self.replace(wrapper=new_wrapper,
                         records_arr=new_records_arr,
                         ts=new_ts)
Example #14
0
 def indexing_func(self: OrdersT, pd_indexing_func: tp.PandasIndexingFunc, **kwargs) -> OrdersT:
     """Perform indexing on `Orders`."""
     new_wrapper, new_records_arr, group_idxs, col_idxs = \
         Records.indexing_func_meta(self, pd_indexing_func, **kwargs)
     if self.close is not None:
         new_close = new_wrapper.wrap(to_2d_array(self.close)[:, col_idxs], group_by=False)
     else:
         new_close = None
     return self.replace(
         wrapper=new_wrapper,
         records_arr=new_records_arr,
         close=new_close
     )