indexing module¶
Classes and functions for indexing.
build_param_indexer function¶
A factory to create a class with parameter indexing.
Parameter indexer enables accessing a group of rows and columns by a parameter array (similar to loc). This way, one can query index/columns by another Series called a parameter mapper, which is just a pd.Series that maps columns (its index) to params (its values).
Parameter indexing is important, since querying by column/index labels alone is not always the best option. For example, pandas doesn't let you query by list at a specific index/column level.
Args
param_names:listofstr- Names of the parameters.
class_name:str- Name of the generated class.
module_name:str- Name of the module to which the class should be bound.
Usage
>>> from vectorbtpro import *
>>> from vectorbtpro.base.indexing import build_param_indexer, indexing_on_mapper
>>> MyParamIndexer = build_param_indexer(['my_param'])
>>> class C(MyParamIndexer):
... def __init__(self, df, param_mapper):
... self.df = df
... self._my_param_mapper = param_mapper
... super().__init__([param_mapper])
...
... def indexing_func(self, pd_indexing_func):
... return type(self)(
... pd_indexing_func(self.df),
... indexing_on_mapper(self._my_param_mapper, self.df, pd_indexing_func)
... )
>>> df = pd.DataFrame({'a': [1, 2], 'b': [3, 4]})
>>> param_mapper = pd.Series(['First', 'Second'], index=['a', 'b'])
>>> c = C(df, param_mapper)
>>> c.my_param_loc['First'].df
0 1
1 2
Name: a, dtype: int64
>>> c.my_param_loc['Second'].df
0 3
1 4
Name: b, dtype: int64
>>> c.my_param_loc[['First', 'First', 'Second', 'Second']].df
a b
0 1 1 3 3
1 2 2 4 4
get_idxs function¶
Translate indexer to row and column indices.
If idxr is not an indexer class, wraps it with Idxr.
Keyword arguments are passed when constructing a new Idxr.
get_index_points function¶
get_index_points(
index,
every=None,
normalize_every=False,
at_time=None,
start=None,
end=None,
exact_start=False,
on=None,
add_delta=None,
kind=None,
indexer_method='bfill',
indexer_tolerance=None,
skip_not_found=True
)
Translate indices or labels into index points.
See PointIdxr for arguments.
Usage
- Provide nothing to generate at the beginning:
>>> from vectorbtpro import *
>>> index = pd.date_range("2020-01", "2020-02", freq="1d")
>>> vbt.get_index_points(index)
array([0])
- Provide
everyas an integer frequency to generate index points using NumPy:
>>> # Generate a point every five rows
>>> vbt.get_index_points(index, every=5)
array([ 0, 5, 10, 15, 20, 25, 30])
>>> # Generate a point every five rows starting at 6th row
>>> vbt.get_index_points(index, every=5, start=5)
array([ 5, 10, 15, 20, 25, 30])
>>> # Generate a point every five rows from 6th to 16th row
>>> vbt.get_index_points(index, every=5, start=5, end=15)
array([ 5, 10])
- Provide
everyas a time delta frequency to generate index points using Pandas:
>>> # Generate a point every week
>>> vbt.get_index_points(index, every="W")
array([ 4, 11, 18, 25])
>>> # Generate a point every second day of the week
>>> vbt.get_index_points(index, every="W", add_delta="2d")
array([ 6, 13, 20, 27])
>>> # Generate a point every week, starting at 11th row
>>> vbt.get_index_points(index, every="W", start=10)
array([11, 18, 25])
>>> # Generate a point every week, starting exactly at 11th row
>>> vbt.get_index_points(index, every="W", start=10, exact_start=True)
array([10, 11, 18, 25])
>>> # Generate a point every week, starting at 2020-01-10
>>> vbt.get_index_points(index, every="W", start="2020-01-10")
array([11, 18, 25])
- Instead of using
every, provide indices explicitly:
>>> # Generate one point
>>> vbt.get_index_points(index, on="2020-01-07")
array([6])
>>> # Generate multiple points
>>> vbt.get_index_points(index, on=["2020-01-07", "2020-01-14"])
array([ 6, 13])
get_index_ranges function¶
get_index_ranges(
index,
index_freq=None,
every=None,
normalize_every=False,
split_every=True,
start_time=None,
end_time=None,
lookback_period=None,
start=None,
end=None,
exact_start=False,
fixed_start=False,
closed_start=True,
closed_end=False,
add_start_delta=None,
add_end_delta=None,
kind=None,
skip_not_found=True,
jitted=None
)
Translate indices, labels, or bounds into index ranges.
See RangeIdxr for arguments.
Usage
- Provide nothing to generate one largest index range:
>>> from vectorbtpro import *
>>> index = pd.date_range("2020-01", "2020-02", freq="1d")
>>> np.column_stack(vbt.get_index_ranges(index))
array([[ 0, 32]])
- Provide
everyas an integer frequency to generate index ranges using NumPy:
>>> # Generate a range every five rows
>>> np.column_stack(vbt.get_index_ranges(index, every=5))
array([[ 0, 5],
[ 5, 10],
[10, 15],
[15, 20],
[20, 25],
[25, 30]])
>>> # Generate a range every five rows, starting at 6th row
>>> np.column_stack(vbt.get_index_ranges(
... index,
... every=5,
... start=5
... ))
array([[ 5, 10],
[10, 15],
[15, 20],
[20, 25],
[25, 30]])
>>> # Generate a range every five rows from 6th to 16th row
>>> np.column_stack(vbt.get_index_ranges(
... index,
... every=5,
... start=5,
... end=15
... ))
array([[ 5, 10],
[10, 15]])
- Provide
everyas a time delta frequency to generate index ranges using Pandas:
>>> # Generate a range every week
>>> np.column_stack(vbt.get_index_ranges(index, every="W"))
array([[ 4, 11],
[11, 18],
[18, 25]])
>>> # Generate a range every second day of the week
>>> np.column_stack(vbt.get_index_ranges(
... index,
... every="W",
... add_start_delta="2d"
... ))
array([[ 6, 11],
[13, 18],
[20, 25]])
>>> # Generate a range every week, starting at 11th row
>>> np.column_stack(vbt.get_index_ranges(
... index,
... every="W",
... start=10
... ))
array([[11, 18],
[18, 25]])
>>> # Generate a range every week, starting exactly at 11th row
>>> np.column_stack(vbt.get_index_ranges(
... index,
... every="W",
... start=10,
... exact_start=True
... ))
array([[10, 11],
[11, 18],
[18, 25]])
>>> # Generate a range every week, starting at 2020-01-10
>>> np.column_stack(vbt.get_index_ranges(
... index,
... every="W",
... start="2020-01-10"
... ))
array([[11, 18],
[18, 25]])
>>> # Generate a range every week, each starting at 2020-01-10
>>> np.column_stack(vbt.get_index_ranges(
... index,
... every="W",
... start="2020-01-10",
... fixed_start=True
... ))
array([[11, 18],
[11, 25]])
>>> # Generate an expanding range that increments by week
>>> np.column_stack(vbt.get_index_ranges(
... index,
... every="W",
... start=0,
... exact_start=True,
... fixed_start=True
... ))
array([[ 0, 4],
[ 0, 11],
[ 0, 18],
[ 0, 25]])
- Use a look-back period (instead of an end index):
>>> # Generate a range every week, looking 5 days back
>>> np.column_stack(vbt.get_index_ranges(
... index,
... every="W",
... lookback_period=5
... ))
array([[ 6, 11],
[13, 18],
[20, 25]])
>>> # Generate a range every week, looking 2 weeks back
>>> np.column_stack(vbt.get_index_ranges(
... index,
... every="W",
... lookback_period="2W"
... ))
array([[ 0, 11],
[ 4, 18],
[11, 25]])
- Instead of using
every, provide start and end indices explicitly:
>>> # Generate one range
>>> np.column_stack(vbt.get_index_ranges(
... index,
... start="2020-01-01",
... end="2020-01-07"
... ))
array([[0, 6]])
>>> # Generate ranges between multiple dates
>>> np.column_stack(vbt.get_index_ranges(
... index,
... start=["2020-01-01", "2020-01-07"],
... end=["2020-01-07", "2020-01-14"]
... ))
array([[ 0, 6],
[ 6, 13]])
>>> # Generate ranges with a fixed start
>>> np.column_stack(vbt.get_index_ranges(
... index,
... start="2020-01-01",
... end=["2020-01-07", "2020-01-14"]
... ))
array([[ 0, 6],
[ 0, 13]])
- Use
closed_startandclosed_endto exclude any of the bounds:
>>> # Generate ranges between multiple dates
>>> # by excluding the start date and including the end date
>>> np.column_stack(vbt.get_index_ranges(
... index,
... start=["2020-01-01", "2020-01-07"],
... end=["2020-01-07", "2020-01-14"],
... closed_start=False,
... closed_end=True
... ))
array([[ 1, 7],
[ 7, 14]])
indexing_on_mapper function¶
Broadcast mapper Series to ref_obj and perform pandas indexing using pd_indexing_func.
normalize_idxs function¶
Normalize indexes into a 1-dim integer array.
AutoIdxr class¶
Class for resolving indices, datetime-like objects, frequency-like objects, and labels for one axis.
Superclasses
Inherited members
- Base.chat
- Base.find_api
- Base.find_assets
- Base.find_docs
- Base.find_examples
- Base.find_messages
- DefineMixin.asdict
- DefineMixin.assert_field_not_missing
- DefineMixin.fields
- DefineMixin.fields_dict
- DefineMixin.get_field
- DefineMixin.hash
- DefineMixin.hash_key
- DefineMixin.is_field_missing
- DefineMixin.is_field_optional
- DefineMixin.is_field_required
- DefineMixin.merge_over
- DefineMixin.merge_with
- DefineMixin.replace
- DefineMixin.resolve
- DefineMixin.resolve_field
- Hashable.get_hash
- IdxrBase.check_idxs
- IdxrBase.slice_indexer
- UniIdxr.get
above_to_len field¶
Whether to place len(index) instead of -1 if AutoIdxr.value is above the last index.
below_to_zero field¶
Whether to place 0 instead of -1 if AutoIdxr.value is below the first index.
closed_end field¶
Whether slice end should be inclusive.
closed_start field¶
Whether slice start should be inclusive.
idxr_kwargs field¶
Keyword arguments passed to the selected indexer.
indexer_method field¶
Method for pd.Index.get_indexer.
kind field¶
Kind of value.
Allowed are
- "position(s)" for PosIdxr
- "mask" for MaskIdxr
- "label(s)" for LabelIdxr
- "datetime" for DatetimeIdxr
- "dtc": for DTCIdxr
- "frequency" for PointIdxr
If None, will (try to) determine automatically based on the type of indices.
level field¶
One or more levels.
If level is not None and kind is None, kind becomes "labels".
value field¶
One or more integer indices, datetime-like objects, frequency-like objects, or labels.
Can also be an instance of PosSel holding position(s) and LabelSel holding label(s).
ColIdxr class¶
Class for resolving column indices.
Superclasses
Inherited members
- Base.chat
- Base.find_api
- Base.find_assets
- Base.find_docs
- Base.find_examples
- Base.find_messages
- DefineMixin.asdict
- DefineMixin.assert_field_not_missing
- DefineMixin.fields
- DefineMixin.fields_dict
- DefineMixin.get_field
- DefineMixin.hash
- DefineMixin.hash_key
- DefineMixin.is_field_missing
- DefineMixin.is_field_optional
- DefineMixin.is_field_required
- DefineMixin.merge_over
- DefineMixin.merge_with
- DefineMixin.replace
- DefineMixin.resolve
- DefineMixin.resolve_field
- Hashable.get_hash
- IdxrBase.check_idxs
- IdxrBase.get
- IdxrBase.slice_indexer
idxr field¶
Indexer.
Can be an instance of UniIdxr, a custom template, or a value to be wrapped with AutoIdxr.
idxr_kwargs field¶
Keyword arguments passed to AutoIdxr.
DTCIdxr class¶
Class for resolving indices provided as datetime-like components.
Superclasses
Inherited members
- Base.chat
- Base.find_api
- Base.find_assets
- Base.find_docs
- Base.find_examples
- Base.find_messages
- DefineMixin.asdict
- DefineMixin.assert_field_not_missing
- DefineMixin.fields
- DefineMixin.fields_dict
- DefineMixin.get_field
- DefineMixin.hash
- DefineMixin.hash_key
- DefineMixin.is_field_missing
- DefineMixin.is_field_optional
- DefineMixin.is_field_required
- DefineMixin.merge_over
- DefineMixin.merge_with
- DefineMixin.replace
- DefineMixin.resolve
- DefineMixin.resolve_field
- Hashable.get_hash
- IdxrBase.check_idxs
- IdxrBase.slice_indexer
- UniIdxr.get
closed_end field¶
Whether slice end should be inclusive.
closed_start field¶
Whether slice start should be inclusive.
get_dtc_namedtuple static method¶
Convert a value to a DTCNT instance.
jitted field¶
Jitting option passed to index_matches_dtc_nb and index_within_dtc_range_nb.
parse_kwargs field¶
Keyword arguments passed to DTC.parse.
value field¶
One or more datetime-like components.
DatetimeIdxr class¶
Class for resolving indices provided as datetime-like objects.
Superclasses
Inherited members
- Base.chat
- Base.find_api
- Base.find_assets
- Base.find_docs
- Base.find_examples
- Base.find_messages
- DefineMixin.asdict
- DefineMixin.assert_field_not_missing
- DefineMixin.fields
- DefineMixin.fields_dict
- DefineMixin.get_field
- DefineMixin.hash
- DefineMixin.hash_key
- DefineMixin.is_field_missing
- DefineMixin.is_field_optional
- DefineMixin.is_field_required
- DefineMixin.merge_over
- DefineMixin.merge_with
- DefineMixin.replace
- DefineMixin.resolve
- DefineMixin.resolve_field
- Hashable.get_hash
- IdxrBase.check_idxs
- IdxrBase.slice_indexer
- UniIdxr.get
above_to_len field¶
Whether to place len(index) instead of -1 if DatetimeIdxr.value is above the last index.
below_to_zero field¶
Whether to place 0 instead of -1 if DatetimeIdxr.value is below the first index.
closed_end field¶
Whether slice end should be inclusive.
closed_start field¶
Whether slice start should be inclusive.
indexer_method field¶
Method for pd.Index.get_indexer.
Allows two additional values: "before" and "after".
value field¶
One or more datetime-like objects.
ExtPandasIndexer class¶
Extension of PandasIndexer that also implements indexing using xLoc.
Superclasses
Inherited members
- Base.chat
- Base.find_api
- Base.find_assets
- Base.find_docs
- Base.find_examples
- Base.find_messages
- IndexingBase.indexing_func
- IndexingBase.indexing_setter_func
- PandasIndexer.iloc
- PandasIndexer.indexing_kwargs
- PandasIndexer.loc
- PandasIndexer.xs
Subclasses
xloc class property¶
Subclass of iLoc that transforms an Idxr-based operation with get_idxs to an iLoc operation.
IdxDict class¶
Class for building an index setter from a dict.
Superclasses
Inherited members
- Base.chat
- Base.find_api
- Base.find_assets
- Base.find_docs
- Base.find_examples
- Base.find_messages
- DefineMixin.asdict
- DefineMixin.assert_field_not_missing
- DefineMixin.fields
- DefineMixin.fields_dict
- DefineMixin.get_field
- DefineMixin.hash
- DefineMixin.hash_key
- DefineMixin.is_field_missing
- DefineMixin.is_field_optional
- DefineMixin.is_field_required
- DefineMixin.merge_over
- DefineMixin.merge_with
- DefineMixin.replace
- DefineMixin.resolve
- DefineMixin.resolve_field
- Hashable.get_hash
- IdxSetterFactory.get
index_dct field¶
Dict that contains indexer objects as keys and values to be set as values.
IdxFrame class¶
Class for building an index setter from a DataFrame.
Superclasses
Inherited members
- Base.chat
- Base.find_api
- Base.find_assets
- Base.find_docs
- Base.find_examples
- Base.find_messages
- DefineMixin.asdict
- DefineMixin.assert_field_not_missing
- DefineMixin.fields
- DefineMixin.fields_dict
- DefineMixin.get_field
- DefineMixin.hash
- DefineMixin.hash_key
- DefineMixin.is_field_missing
- DefineMixin.is_field_optional
- DefineMixin.is_field_required
- DefineMixin.merge_over
- DefineMixin.merge_with
- DefineMixin.replace
- DefineMixin.resolve
- DefineMixin.resolve_field
- Hashable.get_hash
- IdxSetterFactory.get
colidx_kwargs field¶
Keyword arguments passed to colidx if the indexer isn't an instance of ColIdxr.
df field¶
DataFrame or any array-like object to create the DataFrame from.
rowidx_kwargs field¶
Keyword arguments passed to rowidx if the indexer isn't an instance of RowIdxr.
split field¶
Whether to split the setting operation.
If False, will set all values using a single operation. Otherwise, the following options are supported:
- 'columns': one operation per column
- 'rows': one operation per row
- True or 'elements': one operation per element
IdxRecords class¶
Class for building index setters from records - one per field.
Superclasses
Inherited members
- Base.chat
- Base.find_api
- Base.find_assets
- Base.find_docs
- Base.find_examples
- Base.find_messages
- DefineMixin.asdict
- DefineMixin.assert_field_not_missing
- DefineMixin.fields
- DefineMixin.fields_dict
- DefineMixin.get_field
- DefineMixin.hash
- DefineMixin.hash_key
- DefineMixin.is_field_missing
- DefineMixin.is_field_optional
- DefineMixin.is_field_required
- DefineMixin.merge_over
- DefineMixin.merge_with
- DefineMixin.replace
- DefineMixin.resolve
- DefineMixin.resolve_field
- Hashable.get_hash
- IdxSetterFactory.get
col_field field¶
Column field.
If None or True, will search for "col", "column", and "symbol" (case-insensitive).
If a record doesn't have a column field, all columns will be set. If there's no row and column field, the field value will become the default of the entire array.
colidx_kwargs field¶
Keyword arguments passed to colidx if the indexer isn't an instance of ColIdxr.
records field¶
Series, DataFrame, or any sequence of mapping-like objects.
If a Series or DataFrame and the index is not a default range, the index will become a row field. If a custom row field is provided, the index will be ignored.
row_field field¶
Row field.
If None or True, will search for "row", "index", "open time", and "date" (case-insensitive). If IdxRecords.records is a Series or DataFrame, will also include the index name if the index is not a default range.
If a record doesn't have a row field, all rows will be set. If there's no row and column field, the field value will become the default of the entire array.
rowidx_kwargs field¶
Keyword arguments passed to rowidx if the indexer isn't an instance of RowIdxr.
IdxSeries class¶
Class for building an index setter from a Series.
Superclasses
Inherited members
- Base.chat
- Base.find_api
- Base.find_assets
- Base.find_docs
- Base.find_examples
- Base.find_messages
- DefineMixin.asdict
- DefineMixin.assert_field_not_missing
- DefineMixin.fields
- DefineMixin.fields_dict
- DefineMixin.get_field
- DefineMixin.hash
- DefineMixin.hash_key
- DefineMixin.is_field_missing
- DefineMixin.is_field_optional
- DefineMixin.is_field_required
- DefineMixin.merge_over
- DefineMixin.merge_with
- DefineMixin.replace
- DefineMixin.resolve
- DefineMixin.resolve_field
- Hashable.get_hash
- IdxSetterFactory.get
idx_kwargs field¶
Keyword arguments passed to idx if the indexer isn't an instance of Idxr.
split field¶
Whether to split the setting operation.
If False, will set all values using a single operation. Otherwise, will do one operation per element.
sr field¶
Series or any array-like object to create the Series from.
IdxSetter class¶
Class for setting values based on indexing.
Superclasses
Inherited members
- Base.chat
- Base.find_api
- Base.find_assets
- Base.find_docs
- Base.find_examples
- Base.find_messages
- DefineMixin.asdict
- DefineMixin.assert_field_not_missing
- DefineMixin.fields
- DefineMixin.fields_dict
- DefineMixin.get_field
- DefineMixin.hash
- DefineMixin.hash_key
- DefineMixin.is_field_missing
- DefineMixin.is_field_optional
- DefineMixin.is_field_required
- DefineMixin.merge_over
- DefineMixin.merge_with
- DefineMixin.replace
- DefineMixin.resolve
- DefineMixin.resolve_field
- Hashable.get_hash
fill_and_set method¶
Fill a new array and set its values based on IdxSetter.get_set_meta.
If keep_flex is True, will return the most memory-efficient array representation capable of flexible indexing.
If fill_value is None, will search for the _def key in IdxSetter.idx_items. If there's none, will be set to NaN.
get_set_meta method¶
Get meta of setting operations in IdxSetter.idx_items.
idx_items field¶
Items where the first element is an indexer and the second element is a value to be set.
set method¶
Set values of a NumPy array based on IdxSetter.get_set_meta.
set_col_idxs class method¶
Set column indices in an array.
set_pd method¶
Set values of a Pandas array based on IdxSetter.get_set_meta.
set_row_and_col_idxs class method¶
Set row and column indices in an array.
set_row_idxs class method¶
Set row indices in an array.
IdxSetterFactory class¶
Class for building index setters.
Superclasses
Inherited members
Subclasses
get method¶
Get an instance of IdxSetter or a dict of such instances - one per array name.
Idxr class¶
Class for resolving indices.
Superclasses
Inherited members
- Base.chat
- Base.find_api
- Base.find_assets
- Base.find_docs
- Base.find_examples
- Base.find_messages
- DefineMixin.asdict
- DefineMixin.assert_field_not_missing
- DefineMixin.fields
- DefineMixin.fields_dict
- DefineMixin.get_field
- DefineMixin.hash
- DefineMixin.hash_key
- DefineMixin.is_field_missing
- DefineMixin.is_field_optional
- DefineMixin.is_field_required
- DefineMixin.merge_over
- DefineMixin.merge_with
- DefineMixin.replace
- DefineMixin.resolve
- DefineMixin.resolve_field
- Hashable.get_hash
- IdxrBase.check_idxs
- IdxrBase.get
- IdxrBase.slice_indexer
idxr_kwargs field¶
Keyword arguments passed to RowIdxr and ColIdxr.
idxrs field¶
A tuple of one or more indexers.
If one indexer is provided, can be an instance of RowIdxr or ColIdxr, a custom template, or a value to wrapped with RowIdxr.
If two indexers are provided, can be an instance of RowIdxr and ColIdxr respectively, or a value to wrapped with RowIdxr and ColIdxr respectively.
IdxrBase class¶
Abstract class for resolving indices.
Superclasses
Inherited members
Subclasses
check_idxs method¶
Check indices after resolving them.
get method¶
Get indices.
slice_indexer class method¶
Compute the slice indexer for input labels and step.
IndexingBase class¶
Class that supports indexing through IndexingBase.indexing_func.
Superclasses
Inherited members
Subclasses
- PandasIndexer
vectorbtpro.indicators.custom.adx.ParamIndexervectorbtpro.indicators.custom.atr.ParamIndexervectorbtpro.indicators.custom.bbands.ParamIndexervectorbtpro.indicators.custom.hurst.ParamIndexervectorbtpro.indicators.custom.ma.ParamIndexervectorbtpro.indicators.custom.macd.ParamIndexervectorbtpro.indicators.custom.msd.ParamIndexervectorbtpro.indicators.custom.obv.ParamIndexervectorbtpro.indicators.custom.ols.ParamIndexervectorbtpro.indicators.custom.patsim.ParamIndexervectorbtpro.indicators.custom.pivotinfo.ParamIndexervectorbtpro.indicators.custom.rsi.ParamIndexervectorbtpro.indicators.custom.sigdet.ParamIndexervectorbtpro.indicators.custom.stoch.ParamIndexervectorbtpro.indicators.custom.supertrend.ParamIndexervectorbtpro.indicators.custom.vwap.ParamIndexervectorbtpro.labels.generators.bolb.ParamIndexervectorbtpro.labels.generators.fixlb.ParamIndexervectorbtpro.labels.generators.fmax.ParamIndexervectorbtpro.labels.generators.fmean.ParamIndexervectorbtpro.labels.generators.fmin.ParamIndexervectorbtpro.labels.generators.fstd.ParamIndexervectorbtpro.labels.generators.meanlb.ParamIndexervectorbtpro.labels.generators.pivotlb.ParamIndexervectorbtpro.labels.generators.trendlb.ParamIndexervectorbtpro.signals.generators.ohlcstx.ParamIndexervectorbtpro.signals.generators.ohlcstx.ParamIndexervectorbtpro.signals.generators.rand.ParamIndexervectorbtpro.signals.generators.randnx.ParamIndexervectorbtpro.signals.generators.randx.ParamIndexervectorbtpro.signals.generators.rprob.ParamIndexervectorbtpro.signals.generators.rprobnx.ParamIndexervectorbtpro.signals.generators.rprobx.ParamIndexervectorbtpro.signals.generators.rprobx.ParamIndexervectorbtpro.signals.generators.stx.ParamIndexervectorbtpro.signals.generators.stx.ParamIndexer
indexing_func method¶
Apply pd_indexing_func on all pandas objects in question and return a new instance of the class.
Should be overridden.
indexing_setter_func method¶
Apply pd_indexing_setter_func on all pandas objects in question.
Should be overridden.
IndexingError class¶
Exception raised when an indexing error has occurred.
Superclasses
builtins.BaseExceptionbuiltins.Exception
LabelIdxr class¶
Class for resolving indices provided as labels.
Superclasses
Inherited members
- Base.chat
- Base.find_api
- Base.find_assets
- Base.find_docs
- Base.find_examples
- Base.find_messages
- DefineMixin.asdict
- DefineMixin.assert_field_not_missing
- DefineMixin.fields
- DefineMixin.fields_dict
- DefineMixin.get_field
- DefineMixin.hash
- DefineMixin.hash_key
- DefineMixin.is_field_missing
- DefineMixin.is_field_optional
- DefineMixin.is_field_required
- DefineMixin.merge_over
- DefineMixin.merge_with
- DefineMixin.replace
- DefineMixin.resolve
- DefineMixin.resolve_field
- Hashable.get_hash
- IdxrBase.check_idxs
- IdxrBase.slice_indexer
- UniIdxr.get
closed_end field¶
Whether slice end should be inclusive.
closed_start field¶
Whether slice start should be inclusive.
level field¶
One or more levels.
value field¶
One or more labels.
Loc class¶
Forwards pd.Series.loc/pd.DataFrame.loc operation to each Series/DataFrame and returns a new class instance.
Superclasses
Inherited members
- Base.chat
- Base.find_api
- Base.find_assets
- Base.find_docs
- Base.find_examples
- Base.find_messages
- pdLoc.indexing_func
- pdLoc.indexing_kwargs
- pdLoc.indexing_setter_func
- pdLoc.pd_indexing_func
- pdLoc.pd_indexing_setter_func
LocBase class¶
Class that implements location-based indexing.
Superclasses
Inherited members
Subclasses
indexing_func class property¶
Indexing function.
indexing_kwargs class property¶
Keyword arguments passed to LocBase.indexing_func.
indexing_setter_func class property¶
Indexing setter function.
MaskIdxr class¶
Class for resolving indices provided as a mask.
Superclasses
Inherited members
- Base.chat
- Base.find_api
- Base.find_assets
- Base.find_docs
- Base.find_examples
- Base.find_messages
- DefineMixin.asdict
- DefineMixin.assert_field_not_missing
- DefineMixin.fields
- DefineMixin.fields_dict
- DefineMixin.get_field
- DefineMixin.hash
- DefineMixin.hash_key
- DefineMixin.is_field_missing
- DefineMixin.is_field_optional
- DefineMixin.is_field_required
- DefineMixin.merge_over
- DefineMixin.merge_with
- DefineMixin.replace
- DefineMixin.resolve
- DefineMixin.resolve_field
- Hashable.get_hash
- IdxrBase.check_idxs
- IdxrBase.slice_indexer
- UniIdxr.get
value field¶
Mask.
PandasIndexer class¶
Implements indexing using iloc, loc, xs and __getitem__.
Usage
>>> from vectorbtpro import *
>>> from vectorbtpro.base.indexing import PandasIndexer
>>> class C(PandasIndexer):
... def __init__(self, df1, df2):
... self.df1 = df1
... self.df2 = df2
... super().__init__()
...
... def indexing_func(self, pd_indexing_func):
... return type(self)(
... pd_indexing_func(self.df1),
... pd_indexing_func(self.df2)
... )
>>> df1 = pd.DataFrame({'a': [1, 2], 'b': [3, 4]})
>>> df2 = pd.DataFrame({'a': [5, 6], 'b': [7, 8]})
>>> c = C(df1, df2)
>>> c.iloc[:, 0]
<__main__.C object at 0x1a1cacbbe0>
>>> c.iloc[:, 0].df1
0 1
1 2
Name: a, dtype: int64
>>> c.iloc[:, 0].df2
0 5
1 6
Name: a, dtype: int64
Superclasses
Inherited members
- Base.chat
- Base.find_api
- Base.find_assets
- Base.find_docs
- Base.find_examples
- Base.find_messages
- IndexingBase.indexing_func
- IndexingBase.indexing_setter_func
Subclasses
iloc class property¶
Forwards pd.Series.iloc/pd.DataFrame.iloc operation to each Series/DataFrame and returns a new class instance.
indexing_kwargs class property¶
Indexing keyword arguments.
loc class property¶
Forwards pd.Series.loc/pd.DataFrame.loc operation to each Series/DataFrame and returns a new class instance.
xs method¶
Forwards pd.Series.xs/pd.DataFrame.xs operation to each Series/DataFrame and returns a new class instance.
ParamLoc class¶
Access a group of columns by parameter using pd.Series.loc.
Uses mapper to establish link between columns and parameter values.
Superclasses
Inherited members
- Base.chat
- Base.find_api
- Base.find_assets
- Base.find_docs
- Base.find_examples
- Base.find_messages
- LocBase.indexing_func
- LocBase.indexing_kwargs
- LocBase.indexing_setter_func
encode_key class method¶
Encode key.
get_idxs method¶
Get array of indices affected by this key.
level_name class property¶
Level name.
mapper class property¶
Mapper.
PointIdxr class¶
Class for resolving index points.
Superclasses
Inherited members
- Base.chat
- Base.find_api
- Base.find_assets
- Base.find_docs
- Base.find_examples
- Base.find_messages
- DefineMixin.asdict
- DefineMixin.assert_field_not_missing
- DefineMixin.fields
- DefineMixin.fields_dict
- DefineMixin.get_field
- DefineMixin.hash
- DefineMixin.hash_key
- DefineMixin.is_field_missing
- DefineMixin.is_field_optional
- DefineMixin.is_field_required
- DefineMixin.merge_over
- DefineMixin.merge_with
- DefineMixin.replace
- DefineMixin.resolve
- DefineMixin.resolve_field
- Hashable.get_hash
- IdxrBase.check_idxs
- IdxrBase.slice_indexer
- UniIdxr.get
add_delta field¶
Offset to be added to each in on.
Gets converted to a proper offset/timedelta using to_freq.
at_time field¶
Time of the day either as a (human-readable) string or datetime.time.
Every datetime in on gets floored to the daily frequency, while at_time gets converted into a timedelta using time_to_timedelta and added to add_delta. Index must be datetime-like.
end field¶
End index/date.
If (human-readable) string, gets converted into a datetime.
If every is None, gets used to filter the final index array.
every field¶
Frequency either as an integer or timedelta.
Gets translated into on array by creating a range. If integer, an index sequence from start to end (exclusive) is created and 'indices' as kind is used. If timedelta-like, a date sequence from start to end (inclusive) is created and 'labels' as kind is used.
If at_time is not None and every and on are None, every defaults to one day.
exact_start field¶
Whether the first index should be exactly start.
Depending on every, the first index picked by pd.date_range may happen after start. In such a case, start gets injected before the first index generated by pd.date_range.
indexer_method field¶
Method for pd.Index.get_indexer.
Allows two additional values: "before" and "after".
indexer_tolerance field¶
Tolerance for pd.Index.get_indexer.
If at_time is set and indexer_method is neither exact nor nearest, indexer_tolerance becomes such that the next element must be within the current day.
kind field¶
Kind of data in on: indices or labels.
If None, gets assigned to indices if on contains integer data, otherwise to labels.
If kind is 'labels', on gets converted into indices using pd.Index.get_indexer. Prior to this, gets its timezone aligned to the timezone of the index. If kind is 'indices', on gets wrapped with NumPy.
normalize_every field¶
Normalize start/end dates to midnight before generating date range.
on field¶
Index/label or a sequence of such.
Gets converted into datetime format whenever possible.
skip_not_found field¶
Whether to drop indices that are -1 (not found).
start field¶
Start index/date.
If (human-readable) string, gets converted into a datetime.
If every is None, gets used to filter the final index array.
PosIdxr class¶
Class for resolving indices provided as integer positions.
Superclasses
Inherited members
- Base.chat
- Base.find_api
- Base.find_assets
- Base.find_docs
- Base.find_examples
- Base.find_messages
- DefineMixin.asdict
- DefineMixin.assert_field_not_missing
- DefineMixin.fields
- DefineMixin.fields_dict
- DefineMixin.get_field
- DefineMixin.hash
- DefineMixin.hash_key
- DefineMixin.is_field_missing
- DefineMixin.is_field_optional
- DefineMixin.is_field_required
- DefineMixin.merge_over
- DefineMixin.merge_with
- DefineMixin.replace
- DefineMixin.resolve
- DefineMixin.resolve_field
- Hashable.get_hash
- IdxrBase.check_idxs
- IdxrBase.slice_indexer
- UniIdxr.get
value field¶
One or more integer positions.
RangeIdxr class¶
Class for resolving index ranges.
Superclasses
Inherited members
- Base.chat
- Base.find_api
- Base.find_assets
- Base.find_docs
- Base.find_examples
- Base.find_messages
- DefineMixin.asdict
- DefineMixin.assert_field_not_missing
- DefineMixin.fields
- DefineMixin.fields_dict
- DefineMixin.get_field
- DefineMixin.hash
- DefineMixin.hash_key
- DefineMixin.is_field_missing
- DefineMixin.is_field_optional
- DefineMixin.is_field_required
- DefineMixin.merge_over
- DefineMixin.merge_with
- DefineMixin.replace
- DefineMixin.resolve
- DefineMixin.resolve_field
- Hashable.get_hash
- IdxrBase.check_idxs
- IdxrBase.slice_indexer
- UniIdxr.get
add_end_delta field¶
Offset to be added to each in end.
If string, gets converted to a proper offset/timedelta using to_freq.
add_start_delta field¶
Offset to be added to each in start.
If string, gets converted to a proper offset/timedelta using to_freq.
closed_end field¶
Whether end should be inclusive.
closed_start field¶
Whether start should be inclusive.
end field¶
End index/label or a sequence of such.
Gets converted into datetime format whenever possible.
Gets broadcasted together with start.
end_time field¶
End time of the day either as a (human-readable) string or datetime.time.
Every datetime in end gets floored to the daily frequency, while end_time gets converted into a timedelta using time_to_timedelta and added to add_end_delta. Index must be datetime-like.
every field¶
Frequency either as an integer or timedelta.
Gets translated into start and end arrays by creating a range. If integer, an index sequence from start to end (exclusive) is created and 'indices' as kind is used. If timedelta-like, a date sequence from start to end (inclusive) is created and 'bounds' as kind is used.
If start_time and end_time are not None and every, start, and end are None, every defaults to one day.
exact_start field¶
Whether the first index in the start array should be exactly start.
Depending on every, the first index picked by pd.date_range may happen after start. In such a case, start gets injected before the first index generated by pd.date_range.
Cannot be used together with lookback_period.
fixed_start field¶
Whether all indices in the start array should be exactly start.
Works only together with every.
Cannot be used together with lookback_period.
jitted field¶
Jitting option passed to Resampler.map_bounds_to_source_ranges.
kind field¶
Kind of data in on: indices, labels or bounds.
If None, gets assigned to indices if start and end contain integer data, to bounds if start, end, and index are datetime-like, otherwise to labels.
If kind is 'labels', start and end get converted into indices using pd.Index.get_indexer. Prior to this, get their timezone aligned to the timezone of the index. If kind is 'indices', start and end get wrapped with NumPy. If kind` is 'bounds', Resampler.map_bounds_to_source_ranges is used.
lookback_period field¶
Lookback period either as an integer or offset.
If lookback_period is set, start becomes end-lookback_period. If every is not None, the sequence is generated from start+lookback_period to end and then assigned to end.
If string, gets converted to a proper offset/timedelta using to_freq. If integer, gets multiplied by the frequency of the index if the index is not integer.
normalize_every field¶
Normalize start/end dates to midnight before generating date range.
skip_not_found field¶
Whether to drop indices that are -1 (not found).
split_every field¶
Whether to split the sequence generated using every into start and end arrays.
After creation, and if split_every is True, an index range is created from each pair of elements in the generated sequence. Otherwise, the entire sequence is assigned to start and end, and only time and delta instructions can be used to further differentiate between them.
Forced to False if every, start_time, and end_time are not None and fixed_start is False.
start field¶
Start index/label or a sequence of such.
Gets converted into datetime format whenever possible.
Gets broadcasted together with end.
start_time field¶
Start time of the day either as a (human-readable) string or datetime.time.
Every datetime in start gets floored to the daily frequency, while start_time gets converted into a timedelta using time_to_timedelta and added to add_start_delta. Index must be datetime-like.
RowIdxr class¶
Class for resolving row indices.
Superclasses
Inherited members
- Base.chat
- Base.find_api
- Base.find_assets
- Base.find_docs
- Base.find_examples
- Base.find_messages
- DefineMixin.asdict
- DefineMixin.assert_field_not_missing
- DefineMixin.fields
- DefineMixin.fields_dict
- DefineMixin.get_field
- DefineMixin.hash
- DefineMixin.hash_key
- DefineMixin.is_field_missing
- DefineMixin.is_field_optional
- DefineMixin.is_field_required
- DefineMixin.merge_over
- DefineMixin.merge_with
- DefineMixin.replace
- DefineMixin.resolve
- DefineMixin.resolve_field
- Hashable.get_hash
- IdxrBase.check_idxs
- IdxrBase.get
- IdxrBase.slice_indexer
idxr field¶
Indexer.
Can be an instance of UniIdxr, a custom template, or a value to be wrapped with AutoIdxr.
idxr_kwargs field¶
Keyword arguments passed to AutoIdxr.
UniIdxr class¶
Abstract class for resolving indices based on a single index.
Superclasses
Inherited members
- Base.chat
- Base.find_api
- Base.find_assets
- Base.find_docs
- Base.find_examples
- Base.find_messages
- IdxrBase.check_idxs
- IdxrBase.get
- IdxrBase.slice_indexer
Subclasses
UniIdxrOp class¶
Class for applying an operation to one or more indexers.
Produces a single set of indices.
Superclasses
Inherited members
- Base.chat
- Base.find_api
- Base.find_assets
- Base.find_docs
- Base.find_examples
- Base.find_messages
- DefineMixin.asdict
- DefineMixin.assert_field_not_missing
- DefineMixin.fields
- DefineMixin.fields_dict
- DefineMixin.get_field
- DefineMixin.hash
- DefineMixin.hash_key
- DefineMixin.is_field_missing
- DefineMixin.is_field_optional
- DefineMixin.is_field_required
- DefineMixin.merge_over
- DefineMixin.merge_with
- DefineMixin.replace
- DefineMixin.resolve
- DefineMixin.resolve_field
- Hashable.get_hash
- IdxrBase.check_idxs
- IdxrBase.slice_indexer
- UniIdxr.get
idxrs field¶
A tuple of one or more indexers.
op_func field¶
Operation function that takes the indices of each indexer (as *args), index (keyword argument), and freq (keyword argument), and returns new indices.
hslice class¶
Hashable slice.
Superclasses
Inherited members
- Base.chat
- Base.find_api
- Base.find_assets
- Base.find_docs
- Base.find_examples
- Base.find_messages
- DefineMixin.asdict
- DefineMixin.assert_field_not_missing
- DefineMixin.fields
- DefineMixin.fields_dict
- DefineMixin.get_field
- DefineMixin.hash
- DefineMixin.hash_key
- DefineMixin.is_field_missing
- DefineMixin.is_field_optional
- DefineMixin.is_field_required
- DefineMixin.merge_over
- DefineMixin.merge_with
- DefineMixin.replace
- DefineMixin.resolve
- DefineMixin.resolve_field
- Hashable.get_hash
from_slice class method¶
Construct from a slice.
start field¶
Start.
step field¶
Step.
stop field¶
Stop.
to_slice method¶
Convert to a slice.
iLoc class¶
Forwards pd.Series.iloc/pd.DataFrame.iloc operation to each Series/DataFrame and returns a new class instance.
Superclasses
Inherited members
- Base.chat
- Base.find_api
- Base.find_assets
- Base.find_docs
- Base.find_examples
- Base.find_messages
- pdLoc.indexing_func
- pdLoc.indexing_kwargs
- pdLoc.indexing_setter_func
- pdLoc.pd_indexing_func
- pdLoc.pd_indexing_setter_func
Subclasses
index_dict class¶
Dict that contains indexer objects as keys and values to be set as values.
Each indexer object must be hashable. To make a slice hashable, use hslice. To make an array hashable, convert it into a tuple.
To set a default value, use the _def key (case-sensitive!).
Superclasses
- Base
- Comparable
- Pickleable
- Prettified
builtins.dict- pdict
Inherited members
- Base.chat
- Base.find_api
- Base.find_assets
- Base.find_docs
- Base.find_examples
- Base.find_messages
- Pickleable.decode_config
- Pickleable.decode_config_node
- Pickleable.dumps
- Pickleable.encode_config
- Pickleable.encode_config_node
- Pickleable.file_exists
- Pickleable.getsize
- Pickleable.load
- Pickleable.loads
- Pickleable.modify_state
- Pickleable.resolve_file_path
- Pickleable.save
- Prettified.pprint
- pdict.equals
- pdict.load_update
- pdict.prettify
- pdict.rec_state
pdLoc class¶
Forwards a Pandas-like indexing operation to each Series/DataFrame and returns a new class instance.
Superclasses
Inherited members
- Base.chat
- Base.find_api
- Base.find_assets
- Base.find_docs
- Base.find_examples
- Base.find_messages
- LocBase.indexing_func
- LocBase.indexing_kwargs
- LocBase.indexing_setter_func
Subclasses
pd_indexing_func class method¶
Pandas-like indexing operation.
pd_indexing_setter_func class method¶
Pandas-like indexing setter operation.
xLoc class¶
Subclass of iLoc that transforms an Idxr-based operation with get_idxs to an iLoc operation.
Superclasses
Inherited members