accessors module¶
Custom Pandas accessors for generic data.
Methods can be accessed as follows:
- GenericSRAccessor ->
pd.Series.vbt.* - GenericDFAccessor ->
pd.DataFrame.vbt.*
>>> from vectorbtpro import *
>>> # vectorbtpro.generic.accessors.GenericAccessor.rolling_mean
>>> pd.Series([1, 2, 3, 4]).vbt.rolling_mean(2)
0 NaN
1 1.5
2 2.5
3 3.5
dtype: float64
The accessors inherit vectorbtpro.base.accessors and are inherited by more specialized accessors, such as vectorbtpro.signals.accessors and vectorbtpro.returns.accessors.
Note
Grouping is only supported by the methods that accept the group_by argument.
Accessors do not utilize caching.
Run for the examples below
>>> df = pd.DataFrame({
... 'a': [1, 2, 3, 4, 5],
... 'b': [5, 4, 3, 2, 1],
... 'c': [1, 2, 3, 2, 1]
... }, index=pd.Index(pd.date_range("2020", periods=5)))
>>> df
a b c
2020-01-01 1 5 1
2020-01-02 2 4 2
2020-01-03 3 3 3
2020-01-04 4 2 2
2020-01-05 5 1 1
>>> sr = pd.Series(np.arange(10), index=pd.date_range("2020", periods=10))
>>> sr
2020-01-01 0
2020-01-02 1
2020-01-03 2
2020-01-04 3
2020-01-05 4
2020-01-06 5
2020-01-07 6
2020-01-08 7
2020-01-09 8
2020-01-10 9
dtype: int64
Stats¶
Hint
>>> df2 = pd.DataFrame({
... 'a': [np.nan, 2, 3],
... 'b': [4, np.nan, 5],
... 'c': [6, 7, np.nan]
... }, index=['x', 'y', 'z'])
>>> df2.vbt(freq='d').stats(column='a')
Start x
End z
Period 3 days 00:00:00
Count 2
Mean 2.5
Std 0.707107
Min 2.0
Median 2.5
Max 3.0
Min Index y
Max Index z
Name: a, dtype: object
Mapping¶
Mapping can be set both in GenericAccessor (preferred) and StatsBuilderMixin.stats():
>>> mapping = {x: 'test_' + str(x) for x in pd.unique(df2.values.flatten())}
>>> df2.vbt(freq='d', mapping=mapping).stats(column='a')
Start x
End z
Period 3 days 00:00:00
Count 2
Value Counts: test_2.0 1
Value Counts: test_3.0 1
Value Counts: test_4.0 0
Value Counts: test_5.0 0
Value Counts: test_6.0 0
Value Counts: test_7.0 0
Value Counts: test_nan 1
Name: a, dtype: object
>>> df2.vbt(freq='d').stats(column='a', settings=dict(mapping=mapping))
UserWarning: Changing the mapping will create a copy of this object.
Consider setting it upon object creation to re-use existing cache.
Start x
End z
Period 3 days 00:00:00
Count 2
Value Counts: test_2.0 1
Value Counts: test_3.0 1
Value Counts: test_4.0 0
Value Counts: test_5.0 0
Value Counts: test_6.0 0
Value Counts: test_7.0 0
Value Counts: test_nan 1
Name: a, dtype: object
Selecting a column before calling stats will consider uniques from this column only:
>>> df2['a'].vbt(freq='d', mapping=mapping).stats()
Start x
End z
Period 3 days 00:00:00
Count 2
Value Counts: test_2.0 1
Value Counts: test_3.0 1
Value Counts: test_nan 1
Name: a, dtype: object
To include all keys from mapping, pass incl_all_keys=True:
>>> df2['a'].vbt(freq='d', mapping=mapping).stats(settings=dict(incl_all_keys=True))
Start x
End z
Period 3 days 00:00:00
Count 2
Value Counts: test_2.0 1
Value Counts: test_3.0 1
Value Counts: test_4.0 0
Value Counts: test_5.0 0
Value Counts: test_6.0 0
Value Counts: test_7.0 0
Value Counts: test_nan 1
Name: a, dtype: object
StatsBuilderMixin.stats() also supports (re-)grouping:
>>> df2.vbt(freq='d').stats(column=0, group_by=[0, 0, 1])
Start x
End z
Period 3 days 00:00:00
Count 4
Mean 3.5
Std 1.290994
Min 2.0
Median 3.5
Max 5.0
Min Index y
Max Index z
Name: 0, dtype: object
Plots¶
Hint
GenericAccessor class has a single subplot based on GenericAccessor.plot():
nb_config ReadonlyConfig¶
Config of Numba methods to be attached to GenericAccessor.
ReadonlyConfig(
shuffle=dict(
func=CPUDispatcher(<function shuffle_nb at 0x132282160>),
disable_chunked=True
),
fillna=dict(
func=CPUDispatcher(<function fillna_nb at 0x13229c9a0>)
),
bshift=dict(
func=CPUDispatcher(<function bshift_nb at 0x13229d620>)
),
fshift=dict(
func=CPUDispatcher(<function fshift_nb at 0x13229dee0>)
),
diff=dict(
func=CPUDispatcher(<function diff_nb at 0x13229e660>)
),
pct_change=dict(
func=CPUDispatcher(<function pct_change_nb at 0x13229ede0>)
),
ffill=dict(
func=CPUDispatcher(<function ffill_nb at 0x13229fce0>)
),
bfill=dict(
func=CPUDispatcher(<function bfill_nb at 0x13229f560>)
),
fbfill=dict(
func=CPUDispatcher(<function fbfill_nb at 0x13229cc20>)
),
cumsum=dict(
func=CPUDispatcher(<function nancumsum_nb at 0x1322bc5e0>)
),
cumprod=dict(
func=CPUDispatcher(<function nancumprod_nb at 0x1322bcae0>)
),
rolling_sum=dict(
func=CPUDispatcher(<function rolling_sum_nb at 0x1323fb880>)
),
rolling_prod=dict(
func=CPUDispatcher(<function rolling_prod_nb at 0x132428400>)
),
rolling_min=dict(
func=CPUDispatcher(<function rolling_min_nb at 0x132473240>)
),
rolling_max=dict(
func=CPUDispatcher(<function rolling_max_nb at 0x1324739c0>)
),
expanding_min=dict(
func=CPUDispatcher(<function expanding_min_nb at 0x132496840>)
),
expanding_max=dict(
func=CPUDispatcher(<function expanding_max_nb at 0x132496fc0>)
),
rolling_any=dict(
func=CPUDispatcher(<function rolling_any_nb at 0x132495080>)
),
rolling_all=dict(
func=CPUDispatcher(<function rolling_all_nb at 0x132495800>)
),
product=dict(
func=CPUDispatcher(<function nanprod_nb at 0x1322bc180>),
is_reducing=True
)
)
GenericAccessor class¶
Accessor on top of data of any type. For both, Series and DataFrames.
Accessible via pd.Series.vbt and pd.DataFrame.vbt.
Superclasses
- Analyzable
- AttrResolverMixin
- BaseAccessor
- Cacheable
- Chainable
- Comparable
- Configured
- ExtPandasIndexer
- HasSettings
- IndexApplier
- IndexingBase
- Itemable
- PandasIndexer
- Paramable
- Pickleable
- PlotsBuilderMixin
- Prettified
- StatsBuilderMixin
- Wrapping
Inherited members
- AttrResolverMixin.deep_getattr()
- AttrResolverMixin.post_resolve_attr()
- AttrResolverMixin.pre_resolve_attr()
- AttrResolverMixin.resolve_attr()
- AttrResolverMixin.resolve_shortcut_attr()
- BaseAccessor.align()
- BaseAccessor.align_to()
- BaseAccessor.apply()
- BaseAccessor.apply_and_concat()
- BaseAccessor.apply_to_index()
- BaseAccessor.broadcast()
- BaseAccessor.broadcast_combs()
- BaseAccessor.broadcast_to()
- BaseAccessor.cls_dir
- BaseAccessor.column_only_select
- BaseAccessor.column_stack()
- BaseAccessor.combine()
- BaseAccessor.concat()
- BaseAccessor.config
- BaseAccessor.cross()
- BaseAccessor.cross()
- BaseAccessor.cross_with()
- BaseAccessor.df_accessor_cls
- BaseAccessor.empty()
- BaseAccessor.empty_like()
- BaseAccessor.eval()
- BaseAccessor.get()
- BaseAccessor.group_select
- BaseAccessor.iloc
- BaseAccessor.indexing_func()
- BaseAccessor.indexing_kwargs
- BaseAccessor.indexing_setter_func()
- BaseAccessor.items()
- BaseAccessor.loc
- BaseAccessor.make_symmetric()
- BaseAccessor.obj
- BaseAccessor.range_only_select
- BaseAccessor.rec_state
- BaseAccessor.repeat()
- BaseAccessor.resolve_column_stack_kwargs()
- BaseAccessor.resolve_row_stack_kwargs()
- BaseAccessor.resolve_shape()
- BaseAccessor.row_stack()
- BaseAccessor.self_aliases
- BaseAccessor.set()
- BaseAccessor.set_between()
- BaseAccessor.split()
- BaseAccessor.split_apply()
- BaseAccessor.sr_accessor_cls
- BaseAccessor.tile()
- BaseAccessor.to_1d_array()
- BaseAccessor.to_2d_array()
- BaseAccessor.to_data()
- BaseAccessor.to_dict()
- BaseAccessor.unstack_to_array()
- BaseAccessor.unstack_to_df()
- BaseAccessor.wrapper
- BaseAccessor.xloc
- Cacheable.get_ca_setup()
- Chainable.pipe()
- Configured.copy()
- Configured.equals()
- Configured.get_writeable_attrs()
- Configured.prettify()
- Configured.replace()
- Configured.resolve_merge_kwargs()
- Configured.update_config()
- HasSettings.get_path_setting()
- HasSettings.get_path_settings()
- HasSettings.get_setting()
- HasSettings.get_settings()
- HasSettings.has_path_setting()
- HasSettings.has_path_settings()
- HasSettings.has_setting()
- HasSettings.has_settings()
- HasSettings.reset_settings()
- HasSettings.resolve_setting()
- HasSettings.resolve_settings_paths()
- HasSettings.set_settings()
- IndexApplier.add_levels()
- IndexApplier.drop_duplicate_levels()
- IndexApplier.drop_levels()
- IndexApplier.drop_redundant_levels()
- IndexApplier.rename_levels()
- IndexApplier.select_levels()
- PandasIndexer.xs()
- 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()
- PlotsBuilderMixin.build_subplots_doc()
- PlotsBuilderMixin.override_subplots_doc()
- PlotsBuilderMixin.plots()
- StatsBuilderMixin.build_metrics_doc()
- StatsBuilderMixin.override_metrics_doc()
- StatsBuilderMixin.stats()
- Wrapping.as_param()
- Wrapping.regroup()
- Wrapping.resample()
- Wrapping.resolve_stack_kwargs()
- Wrapping.select_col()
- Wrapping.select_col_from_obj()
Subclasses
ago method¶
For each value, get the value n periods ago.
all_ago method¶
For each value, check whether all values within a window of n last periods are True.
any_ago method¶
For each value, check whether any value within a window of n last periods is True.
apply_along_axis class method¶
GenericAccessor.apply_along_axis(
apply_func_nb,
*args,
axis=1,
broadcast_named_args=None,
broadcast_kwargs=None,
template_context=None,
jitted=None,
chunked=None,
wrapper=None,
wrap_kwargs=None
)
See apply_nb() for axis=1 and row_apply_nb() for axis=0.
For details on the meta version, see apply_meta_nb() for axis=1 and row_apply_meta_nb() for axis=0.
Usage
- Using regular function:
>>> power_nb = njit(lambda a: np.power(a, 2))
>>> df.vbt.apply_along_axis(power_nb)
a b c
2020-01-01 1 25 1
2020-01-02 4 16 4
2020-01-03 9 9 9
2020-01-04 16 4 4
2020-01-05 25 1 1
- Using meta function:
>>> ratio_meta_nb = njit(lambda col, a, b: a[:, col] / b[:, col])
>>> vbt.pd_acc.apply_along_axis(
... ratio_meta_nb,
... df.vbt.to_2d_array() - 1,
... df.vbt.to_2d_array() + 1,
... wrapper=df.vbt.wrapper
... )
a b c
2020-01-01 0.000000 0.666667 0.000000
2020-01-02 0.333333 0.600000 0.333333
2020-01-03 0.500000 0.500000 0.500000
2020-01-04 0.600000 0.333333 0.333333
2020-01-05 0.666667 0.000000 0.000000
- Using templates and broadcasting:
>>> vbt.pd_acc.apply_along_axis(
... ratio_meta_nb,
... vbt.Rep('a'),
... vbt.Rep('b'),
... broadcast_named_args=dict(
... a=pd.Series([1, 2, 3, 4, 5], index=df.index),
... b=pd.DataFrame([[1, 2, 3]], columns=['a', 'b', 'c'])
... )
... )
a b c
2020-01-01 1.0 0.5 0.333333
2020-01-02 2.0 1.0 0.666667
2020-01-03 3.0 1.5 1.000000
2020-01-04 4.0 2.0 1.333333
2020-01-05 5.0 2.5 1.666667
apply_and_reduce class method¶
GenericAccessor.apply_and_reduce(
apply_func_nb,
reduce_func_nb,
apply_args=None,
reduce_args=None,
broadcast_named_args=None,
broadcast_kwargs=None,
template_context=None,
jitted=None,
chunked=None,
wrapper=None,
wrap_kwargs=None
)
For details on the meta version, see apply_and_reduce_meta_nb().
Usage
- Using regular function:
>>> greater_nb = njit(lambda a: a[a > 2])
>>> mean_nb = njit(lambda a: np.nanmean(a))
>>> df.vbt.apply_and_reduce(greater_nb, mean_nb)
a 4.0
b 4.0
c 3.0
Name: apply_and_reduce, dtype: float64
- Using meta function:
>>> and_meta_nb = njit(lambda col, a, b: a[:, col] & b[:, col])
>>> sum_meta_nb = njit(lambda col, x: np.sum(x))
>>> vbt.pd_acc.apply_and_reduce(
... and_meta_nb,
... sum_meta_nb,
... apply_args=(
... df.vbt.to_2d_array() > 1,
... df.vbt.to_2d_array() < 4
... ),
... wrapper=df.vbt.wrapper
... )
a 2
b 2
c 3
Name: apply_and_reduce, dtype: int64
- Using templates and broadcasting:
>>> vbt.pd_acc.apply_and_reduce(
... and_meta_nb,
... sum_meta_nb,
... apply_args=(
... vbt.Rep('mask_a'),
... vbt.Rep('mask_b')
... ),
... broadcast_named_args=dict(
... mask_a=pd.Series([True, True, True, False, False], index=df.index),
... mask_b=pd.DataFrame([[True, True, False]], columns=['a', 'b', 'c'])
... )
... )
a 3
b 3
c 0
Name: apply_and_reduce, dtype: int64
apply_mapping method¶
See apply_mapping().
areaplot method¶
GenericAccessor.areaplot(
line_shape='spline',
line_visible=False,
colorway=None,
trace_kwargs=None,
add_trace_kwargs=None,
fig=None,
**layout_kwargs
)
Plot stacked area.
Args
line_shape:str- Line shape.
line_visible:bool- Whether to make line visible.
colorway:strorsequence- Name of the built-in, qualitative colorway, or a list with colors.
trace_kwargs:dict- Keyword arguments passed to
plotly.graph_objects.Scatter. add_trace_kwargs:dict- Keyword arguments passed to
add_trace. fig:FigureorFigureWidget- Figure to add traces to.
**layout_kwargs- Keyword arguments for layout.
Usage
barplot method¶
Create Bar and return the figure.
Usage
bfill method¶
See bfill_nb().
binarize method¶
See sklearn.preprocessing.Binarizer.
boxplot method¶
GenericAccessor.boxplot(
column=None,
by_level=None,
trace_names=None,
group_by=None,
return_fig=True,
**kwargs
)
Create Box and return the figure.
Usage
bshift method¶
See bshift_nb().
column_apply class method¶
GenericAccessor.apply_along_axis() with axis=1.
corr method¶
GenericAccessor.corr(
other,
broadcast_kwargs=None,
jitted=None,
chunked=None,
group_by=None,
wrap_kwargs=None
)
Return correlation coefficient of non-NaN elements.
count method¶
GenericAccessor.count(
use_jitted=None,
jitted=None,
chunked=None,
group_by=None,
wrap_kwargs=None
)
Return count of non-NaN elements.
cov method¶
GenericAccessor.cov(
other,
ddof=1,
broadcast_kwargs=None,
jitted=None,
chunked=None,
group_by=None,
wrap_kwargs=None
)
Return covariance of non-NaN elements.
crossed_above method¶
GenericAccessor.crossed_above(
other,
wait=0,
dropna=False,
broadcast_kwargs=None,
jitted=None,
chunked=None,
wrap_kwargs=None
)
See crossed_above_nb().
Usage
>>> df['b'].vbt.crossed_above(df['c'])
2020-01-01 False
2020-01-02 False
2020-01-03 False
2020-01-04 False
2020-01-05 False
dtype: bool
>>> df['a'].vbt.crossed_above(df['b'])
2020-01-01 False
2020-01-02 False
2020-01-03 False
2020-01-04 True
2020-01-05 False
dtype: bool
>>> df['a'].vbt.crossed_above(df['b'], wait=1)
2020-01-01 False
2020-01-02 False
2020-01-03 False
2020-01-04 False
2020-01-05 True
dtype: bool
crossed_below method¶
GenericAccessor.crossed_below(
other,
wait=0,
dropna=True,
broadcast_kwargs=None,
jitted=None,
chunked=None,
wrap_kwargs=None
)
See crossed_below_nb().
Also, see GenericAccessor.crossed_above() for similar examples.
cumprod method¶
See nancumprod_nb().
cumsum method¶
See nancumsum_nb().
demean method¶
See demean_nb().
describe method¶
GenericAccessor.describe(
percentiles=None,
ddof=1,
jitted=None,
chunked=None,
group_by=None,
wrap_kwargs=None
)
See describe_reduce_nb().
For percentiles, see pd.DataFrame.describe.
Usage
>>> df.vbt.describe()
a b c
count 5.000000 5.000000 5.00000
mean 3.000000 3.000000 1.80000
std 1.581139 1.581139 0.83666
min 1.000000 1.000000 1.00000
25% 2.000000 2.000000 1.00000
50% 3.000000 3.000000 2.00000
75% 4.000000 4.000000 2.00000
max 5.000000 5.000000 3.00000
diff method¶
See diff_nb().
digitize method¶
Apply np.digitize.
Usage
>>> df.vbt.digitize(3)
a b c
2020-01-01 1 3 1
2020-01-02 1 3 1
2020-01-03 2 2 2
2020-01-04 3 1 1
2020-01-05 3 1 1
drawdown method¶
Get drawdown series.
drawdowns property¶
GenericAccessor.get_drawdowns() with default arguments.
ewm_mean method¶
See ewm_mean_nb().
ewm_std method¶
See ewm_std_nb().
expanding_apply class method¶
GenericAccessor.rolling_apply() but expanding.
expanding_corr method¶
Expanding version of GenericAccessor.rolling_corr().
expanding_cov method¶
Expanding version of GenericAccessor.rolling_cov().
expanding_idxmax method¶
Expanding version of GenericAccessor.rolling_idxmax().
expanding_idxmin method¶
Expanding version of GenericAccessor.rolling_idxmin().
expanding_max method¶
See expanding_max_nb().
expanding_mean method¶
Expanding version of GenericAccessor.rolling_mean().
expanding_min method¶
See expanding_min_nb().
expanding_ols method¶
Expanding version of GenericAccessor.rolling_ols().
expanding_rank method¶
Expanding version of GenericAccessor.rolling_rank().
expanding_std method¶
Expanding version of GenericAccessor.rolling_std().
expanding_zscore method¶
Expanding version of GenericAccessor.rolling_zscore().
fbfill method¶
See fbfill_nb().
ffill method¶
See ffill_nb().
fillna method¶
See fillna_nb().
find_pattern method¶
Generate pattern range records.
See PatternRanges.from_pattern_search().
flatten_grouped method¶
Flatten each group of columns.
See flatten_grouped_nb(). If all groups have the same length, see flatten_uniform_grouped_nb().
Warning
Make sure that the distribution of group lengths is close to uniform, otherwise groups with less columns will be filled with NaN and needlessly occupy memory.
Usage
>>> group_by = pd.Series(['first', 'first', 'second'], name='group')
>>> df.vbt.flatten_grouped(group_by=group_by, order='C')
group first second
2020-01-01 1.0 1.0
2020-01-01 5.0 NaN
2020-01-02 2.0 2.0
2020-01-02 4.0 NaN
2020-01-03 3.0 3.0
2020-01-03 3.0 NaN
2020-01-04 4.0 2.0
2020-01-04 2.0 NaN
2020-01-05 5.0 1.0
2020-01-05 1.0 NaN
>>> df.vbt.flatten_grouped(group_by=group_by, order='F')
group first second
2020-01-01 1.0 1.0
2020-01-02 2.0 2.0
2020-01-03 3.0 3.0
2020-01-04 4.0 2.0
2020-01-05 5.0 1.0
2020-01-01 5.0 NaN
2020-01-02 4.0 NaN
2020-01-03 3.0 NaN
2020-01-04 2.0 NaN
2020-01-05 1.0 NaN
fshift method¶
See fshift_nb().
get_drawdowns method¶
Generate drawdown records.
get_ranges method¶
Generate range records.
See Ranges.from_array().
groupby_apply class method¶
GenericAccessor.groupby_apply(
by,
reduce_func_nb,
*args,
groupby_kwargs=None,
broadcast_named_args=None,
broadcast_kwargs=None,
template_context=None,
jitted=None,
chunked=None,
wrapper=None,
wrap_kwargs=None
)
See groupby_reduce_nb().
For details on the meta version, see groupby_reduce_meta_nb().
Argument by can be an instance of Grouper, pandas.core.groupby.GroupBy, pandas.core.resample.Resampler, or any other groupby-like object that can be accepted by Grouper, or if it fails, then by pd.DataFrame.groupby with groupby_kwargs passed as keyword arguments.
Usage
- Using regular function:
>>> mean_nb = njit(lambda a: np.nanmean(a))
>>> df.vbt.groupby_apply([1, 1, 2, 2, 3], mean_nb)
a b c
1 1.5 4.5 1.5
2 3.5 2.5 2.5
3 5.0 1.0 1.0
- Using meta function:
>>> mean_ratio_meta_nb = njit(lambda idxs, group, col, a, b: \
... np.mean(a[idxs, col]) / np.mean(b[idxs, col]))
>>> vbt.pd_acc.groupby_apply(
... [1, 1, 2, 2, 3],
... mean_ratio_meta_nb,
... df.vbt.to_2d_array() - 1,
... df.vbt.to_2d_array() + 1,
... wrapper=df.vbt.wrapper
... )
a b c
1 0.200000 0.636364 0.200000
2 0.555556 0.428571 0.428571
3 0.666667 0.000000 0.000000
- Using templates and broadcasting, let's split both input arrays into 2 groups of rows and run the calculation function on each group:
>>> from vectorbtpro.base.grouping.nb import group_by_evenly_nb
>>> vbt.pd_acc.groupby_apply(
... vbt.RepEval('group_by_evenly_nb(wrapper.shape[0], 2)'),
... mean_ratio_meta_nb,
... vbt.Rep('a'),
... vbt.Rep('b'),
... broadcast_named_args=dict(
... a=pd.Series([1, 2, 3, 4, 5], index=df.index),
... b=pd.DataFrame([[1, 2, 3]], columns=['a', 'b', 'c'])
... ),
... template_context=dict(group_by_evenly_nb=group_by_evenly_nb)
... )
a b c
0 2.0 1.00 0.666667
1 4.5 2.25 1.500000
The advantage of the approach above is in the flexibility: we can pass two arrays of any broadcastable shapes and everything else is done for us.
groupby_transform class method¶
GenericAccessor.groupby_transform(
by,
transform_func_nb,
*args,
groupby_kwargs=None,
broadcast_named_args=None,
broadcast_kwargs=None,
template_context=None,
jitted=None,
wrapper=None,
wrap_kwargs=None
)
For details on the meta version, see groupby_transform_meta_nb().
For argument by, see GenericAccessor.groupby_apply().
Usage
- Using regular function:
>>> zscore_nb = njit(lambda a: (a - np.nanmean(a)) / np.nanstd(a))
>>> df.vbt.groupby_transform([1, 1, 2, 2, 3], zscore_nb)
a b c
2020-01-01 -1.000000 1.666667 -1.000000
2020-01-02 -0.333333 1.000000 -0.333333
2020-01-03 0.242536 0.242536 0.242536
2020-01-04 1.697749 -1.212678 -1.212678
2020-01-05 1.414214 -0.707107 -0.707107
- Using meta function:
>>> zscore_ratio_meta_nb = njit(lambda idxs, group, a, b: \
... zscore_nb(a[idxs]) / zscore_nb(b[idxs]))
>>> vbt.pd_acc.groupby_transform(
... [1, 1, 2, 2, 3],
... zscore_ratio_meta_nb,
... df.vbt.to_2d_array(),
... df.vbt.to_2d_array()[::-1],
... wrapper=df.vbt.wrapper
... )
a b c
2020-01-01 -0.600000 -1.666667 1.0
2020-01-02 -0.333333 -3.000000 1.0
2020-01-03 1.000000 1.000000 1.0
2020-01-04 -1.400000 -0.714286 1.0
2020-01-05 -2.000000 -0.500000 1.0
heatmap method¶
GenericAccessor.heatmap(
column=None,
x_level=None,
y_level=None,
symmetric=False,
sort=True,
x_labels=None,
y_labels=None,
slider_level=None,
active=0,
slider_labels=None,
return_fig=True,
fig=None,
**kwargs
)
Create a heatmap figure based on object's multi-index and values.
If the object is two-dimensional or the index is not a multi-index, returns a regular heatmap.
If multi-index contains more than two levels or you want them in specific order, pass x_level and y_level, each (int if index or str if name) corresponding to an axis of the heatmap. Optionally, pass slider_level to use a level as a slider.
Creates Heatmap and returns the figure.
Usage
- Plotting a figure based on a regular index:
>>> df = pd.DataFrame([
... [0, np.nan, np.nan],
... [np.nan, 1, np.nan],
... [np.nan, np.nan, 2]
... ])
>>> df.vbt.heatmap().show()
- Plotting a figure based on a multi-index:
>>> multi_index = pd.MultiIndex.from_tuples([
... (1, 1),
... (2, 2),
... (3, 3)
... ])
>>> sr = pd.Series(np.arange(len(multi_index)), index=multi_index)
>>> sr
1 1 0
2 2 1
3 3 2
dtype: int64
>>> sr.vbt.heatmap().show()
histplot method¶
GenericAccessor.histplot(
column=None,
by_level=None,
trace_names=None,
group_by=None,
return_fig=True,
**kwargs
)
Create Histogram and return the figure.
Usage
idxmax method¶
Return labeled index of max of non-NaN elements.
idxmin method¶
Return labeled index of min of non-NaN elements.
lineplot method¶
GenericAccessor.plot() with 'lines' mode.
Usage
ma method¶
GenericAccessor.ma(
window,
wtype='simple',
minp=0,
adjust=True,
jitted=None,
chunked=None,
wrap_kwargs=None
)
See ma_nb().
map class method¶
GenericAccessor.map(
map_func_nb,
*args,
broadcast_named_args=None,
broadcast_kwargs=None,
template_context=None,
jitted=None,
chunked=None,
wrapper=None,
wrap_kwargs=None
)
See map_nb().
For details on the meta version, see map_meta_nb().
Usage
- Using regular function:
>>> prod_nb = njit(lambda a, x: a * x)
>>> df.vbt.map(prod_nb, 10)
a b c
2020-01-01 10 50 10
2020-01-02 20 40 20
2020-01-03 30 30 30
2020-01-04 40 20 20
2020-01-05 50 10 10
- Using meta function:
>>> diff_meta_nb = njit(lambda i, col, a, b: a[i, col] / b[i, col])
>>> vbt.pd_acc.map(
... diff_meta_nb,
... df.vbt.to_2d_array() - 1,
... df.vbt.to_2d_array() + 1,
... wrapper=df.vbt.wrapper
... )
a b c
2020-01-01 0.000000 0.666667 0.000000
2020-01-02 0.333333 0.600000 0.333333
2020-01-03 0.500000 0.500000 0.500000
2020-01-04 0.600000 0.333333 0.333333
2020-01-05 0.666667 0.000000 0.000000
- Using templates and broadcasting:
>>> vbt.pd_acc.map(
... diff_meta_nb,
... vbt.Rep('a'),
... vbt.Rep('b'),
... broadcast_named_args=dict(
... a=pd.Series([1, 2, 3, 4, 5], index=df.index),
... b=pd.DataFrame([[1, 2, 3]], columns=['a', 'b', 'c'])
... )
... )
a b c
2020-01-01 1.0 0.5 0.333333
2020-01-02 2.0 1.0 0.666667
2020-01-03 3.0 1.5 1.000000
2020-01-04 4.0 2.0 1.333333
2020-01-05 5.0 2.5 1.666667
mapping property¶
Mapping.
max method¶
Return max of non-NaN elements.
maxabs_scale method¶
See sklearn.preprocessing.MaxAbsScaler.
mean method¶
Return mean of non-NaN elements.
median method¶
GenericAccessor.median(
use_jitted=None,
jitted=None,
chunked=None,
group_by=None,
wrap_kwargs=None
)
Return median of non-NaN elements.
metrics class variable¶
Metrics supported by GenericAccessor.
HybridConfig(
start_index=dict(
title='Start Index',
calc_func=<function GenericAccessor.<lambda> at 0x1325c6fc0>,
agg_func=None,
tags='wrapper'
),
end_index=dict(
title='End Index',
calc_func=<function GenericAccessor.<lambda> at 0x1325c7060>,
agg_func=None,
tags='wrapper'
),
total_duration=dict(
title='Total Duration',
calc_func=<function GenericAccessor.<lambda> at 0x1325c7100>,
apply_to_timedelta=True,
agg_func=None,
tags='wrapper'
),
count=dict(
title='Count',
calc_func='count',
inv_check_has_mapping=True,
tags=[
'generic',
'describe'
]
),
mean=dict(
title='Mean',
calc_func='mean',
inv_check_has_mapping=True,
tags=[
'generic',
'describe'
]
),
std=dict(
title='Std',
calc_func='std',
inv_check_has_mapping=True,
tags=[
'generic',
'describe'
]
),
min=dict(
title='Min',
calc_func='min',
inv_check_has_mapping=True,
tags=[
'generic',
'describe'
]
),
median=dict(
title='Median',
calc_func='median',
inv_check_has_mapping=True,
tags=[
'generic',
'describe'
]
),
max=dict(
title='Max',
calc_func='max',
inv_check_has_mapping=True,
tags=[
'generic',
'describe'
]
),
idx_min=dict(
title='Min Index',
calc_func='idxmin',
agg_func=None,
inv_check_has_mapping=True,
tags=[
'generic',
'index'
]
),
idx_max=dict(
title='Max Index',
calc_func='idxmax',
agg_func=None,
inv_check_has_mapping=True,
tags=[
'generic',
'index'
]
),
value_counts=dict(
title='Value Counts',
calc_func=<function GenericAccessor.<lambda> at 0x1325c71a0>,
resolve_value_counts=True,
check_has_mapping=True,
tags=[
'generic',
'value_counts'
]
)
)
Returns GenericAccessor._metrics, which gets (hybrid-) copied upon creation of each instance. Thus, changing this config won't affect the class.
To change metrics, you can either change the config in-place, override this property, or overwrite the instance variable GenericAccessor._metrics.
min method¶
Return min of non-NaN elements.
minmax_scale method¶
See sklearn.preprocessing.MinMaxScaler.
msd method¶
GenericAccessor.msd(
window,
wtype='simple',
minp=0,
adjust=True,
ddof=1,
jitted=None,
chunked=None,
wrap_kwargs=None
)
See msd_nb().
normalize method¶
See sklearn.preprocessing.Normalizer.
overlay_with_heatmap method¶
GenericAccessor.overlay_with_heatmap(
other,
column=None,
trace_kwargs=None,
heatmap_kwargs=None,
add_trace_kwargs=None,
fig=None,
**layout_kwargs
)
Plot Series as a line and overlays it with a heatmap.
Args
other:array_like- Second array. Will broadcast.
column:hashable- Column to plot.
trace_kwargs:dict- Keyword arguments passed to
plotly.graph_objects.Scatter. heatmap_kwargs:dict- Keyword arguments passed to GenericAccessor.heatmap().
add_trace_kwargs:dict- Keyword arguments passed to
add_trace. fig:FigureorFigureWidget- Figure to add traces to.
**layout_kwargs- Keyword arguments for layout.
Usage
pct_change method¶
See pct_change_nb().
plot method¶
Create Scatter and return the figure.
Usage
plot_against method¶
GenericAccessor.plot_against(
other,
column=None,
trace_kwargs=None,
other_trace_kwargs=None,
pos_trace_kwargs=None,
neg_trace_kwargs=None,
hidden_trace_kwargs=None,
add_trace_kwargs=None,
fig=None,
**layout_kwargs
)
Plot Series as a line against another line.
Args
other:array_like- Second array. Will broadcast.
column:hashable- Column to plot.
trace_kwargs:dict- Keyword arguments passed to
plotly.graph_objects.Scatter. other_trace_kwargs:dict-
Keyword arguments passed to
plotly.graph_objects.Scatterforother.Set to 'hidden' to hide.
pos_trace_kwargs:dict- Keyword arguments passed to
plotly.graph_objects.Scatterfor positive line. neg_trace_kwargs:dict- Keyword arguments passed to
plotly.graph_objects.Scatterfor negative line. hidden_trace_kwargs:dict- Keyword arguments passed to
plotly.graph_objects.Scatterfor hidden lines. add_trace_kwargs:dict- Keyword arguments passed to
add_trace. fig:FigureorFigureWidget- Figure to add traces to.
**layout_kwargs- Keyword arguments for layout.
Usage
plot_pattern method¶
GenericAccessor.plot_pattern(
pattern,
interp_mode='mixed',
rescale_mode='minmax',
vmin=nan,
vmax=nan,
pmin=nan,
pmax=nan,
invert=False,
error_type='absolute',
max_error=nan,
max_error_interp_mode=None,
column=None,
plot_obj=True,
fill_distance=False,
obj_trace_kwargs=None,
pattern_trace_kwargs=None,
lower_max_error_trace_kwargs=None,
upper_max_error_trace_kwargs=None,
add_trace_kwargs=None,
fig=None,
**layout_kwargs
)
Plot pattern.
Mimics the same similarity calculation procedure as implemented in pattern_similarity_nb().
Usage
>>> sr = pd.Series([10, 11, 12, 13, 12, 13, 14, 15, 13, 14, 11])
>>> sr.vbt.plot_pattern([1, 2, 3, 2, 1]).show()
plots_defaults property¶
Defaults for PlotsBuilderMixin.plots().
Merges PlotsBuilderMixin.plots_defaults and plots from generic.
power_transform method¶
See sklearn.preprocessing.PowerTransformer.
product method¶
See nanprod_nb().
proximity_apply class method¶
GenericAccessor.proximity_apply(
window,
reduce_func_nb,
*args,
broadcast_named_args=None,
broadcast_kwargs=None,
template_context=None,
jitted=None,
wrapper=None,
wrap_kwargs=None
)
For details on the meta version, see proximity_reduce_meta_nb().
Usage
- Using regular function:
>>> mean_nb = njit(lambda a: np.nanmean(a))
>>> df.vbt.proximity_apply(1, mean_nb)
a b c
2020-01-01 3.0 2.500000 3.000000
2020-01-02 3.0 2.666667 3.000000
2020-01-03 3.0 2.777778 2.666667
2020-01-04 3.0 2.666667 2.000000
2020-01-05 3.0 2.500000 1.500000
- Using meta function:
>>> @njit
... def mean_ratio_meta_nb(from_i, to_i, from_col, to_col, a, b):
... a_mean = np.mean(a[from_i:to_i, from_col:to_col])
... b_mean = np.mean(b[from_i:to_i, from_col:to_col])
... return a_mean / b_mean
>>> vbt.pd_acc.proximity_apply(
... 1,
... mean_ratio_meta_nb,
... df.vbt.to_2d_array() - 1,
... df.vbt.to_2d_array() + 1,
... wrapper=df.vbt.wrapper,
... )
a b c
2020-01-01 0.5 0.428571 0.500000
2020-01-02 0.5 0.454545 0.500000
2020-01-03 0.5 0.470588 0.454545
2020-01-04 0.5 0.454545 0.333333
2020-01-05 0.5 0.428571 0.200000
- Using templates and broadcasting:
>>> vbt.pd_acc.proximity_apply(
... 1,
... mean_ratio_meta_nb,
... vbt.Rep('a'),
... vbt.Rep('b'),
... broadcast_named_args=dict(
... a=pd.Series([1, 2, 3, 4, 5], index=df.index),
... b=pd.DataFrame([[1, 2, 3]], columns=['a', 'b', 'c'])
... )
... )
a b c
2020-01-01 1.000000 0.75 0.6
2020-01-02 1.333333 1.00 0.8
2020-01-03 2.000000 1.50 1.2
2020-01-04 2.666667 2.00 1.6
2020-01-05 3.000000 2.25 1.8
qqplot method¶
GenericAccessor.qqplot(
column=None,
sparams=(),
dist='norm',
plot_line=True,
line_shape_kwargs=None,
xref='x',
yref='y',
fig=None,
**kwargs
)
Plot probability plot using scipy.stats.probplot.
**kwargs are passed to GenericAccessor.scatterplot().
Usage
quantile_transform method¶
GenericAccessor.quantile_transform(
*,
n_quantiles=1000,
output_distribution='uniform',
ignore_implicit_zeros=False,
subsample=10000,
random_state=None,
copy=True,
**kwargs
)
See sklearn.preprocessing.QuantileTransformer.
ranges property¶
GenericAccessor.get_ranges() with default arguments.
rank method¶
Compute numerical data rank.
By default, equal values are assigned a rank that is the average of the ranks of those values.
realign method¶
GenericAccessor.realign(
index,
freq=None,
nan_value=None,
ffill=True,
source_rbound=False,
target_rbound=False,
jitted=None,
chunked=None,
wrap_kwargs=None,
silence_warnings=None
)
See realign_nb().
index can be either an instance of Resampler, or any index-like object.
Gives the same results as df.resample(closed='right', label='right').last().ffill() when applied on the target index of the resampler.
Usage
- Downsampling:
>>> h_index = pd.date_range('2020-01-01', '2020-01-05', freq='1h')
>>> d_index = pd.date_range('2020-01-01', '2020-01-05', freq='1d')
>>> h_sr = pd.Series(range(len(h_index)), index=h_index)
>>> h_sr.vbt.realign(d_index)
2020-01-01 0.0
2020-01-02 24.0
2020-01-03 48.0
2020-01-04 72.0
2020-01-05 96.0
Freq: D, dtype: float64
- Upsampling:
>>> d_sr = pd.Series(range(len(d_index)), index=d_index)
>>> d_sr.vbt.realign(h_index)
2020-01-01 00:00:00 0.0
2020-01-01 01:00:00 0.0
2020-01-01 02:00:00 0.0
2020-01-01 03:00:00 0.0
2020-01-01 04:00:00 0.0
... ...
2020-01-04 20:00:00 3.0
2020-01-04 21:00:00 3.0
2020-01-04 22:00:00 3.0
2020-01-04 23:00:00 3.0
2020-01-05 00:00:00 4.0
Freq: H, Length: 97, dtype: float64
realign_closing method¶
GenericAccessor.realign() but creating a resampler and using the right bound of the source and target index.
Note
The timestamps in the source and target index should denote the open time.
realign_opening method¶
GenericAccessor.realign() but creating a resampler and using the left bound of the source and target index.
rebase method¶
Rebase all series to the given base.
This makes comparing/plotting different series together easier. Will forward and backward fill NaN values.
reduce class method¶
GenericAccessor.reduce(
reduce_func_nb,
*args,
returns_array=False,
returns_idx=False,
flatten=False,
order='C',
to_index=True,
broadcast_named_args=None,
broadcast_kwargs=None,
template_context=None,
jitted=None,
chunked=None,
wrapper=None,
group_by=None,
wrap_kwargs=None
)
Reduce by column/group.
Set flatten to True when working with grouped data to pass a flattened array to reduce_func_nb. The order in which to flatten the array can be specified using order.
Set returns_array to True if reduce_func_nb returns an array.
Set returns_idx to True if reduce_func_nb returns row index/position.
Set to_index to True to return labels instead of positions.
For implementation details, see
- reduce_flat_grouped_to_array_nb() if grouped,
returns_arrayis True, andflattenis True - reduce_flat_grouped_nb() if grouped,
returns_arrayis False, andflattenis True - reduce_grouped_to_array_nb() if grouped,
returns_arrayis True, andflattenis False - reduce_grouped_nb() if grouped,
returns_arrayis False, andflattenis False - reduce_to_array_nb() if not grouped and
returns_arrayis True - reduce_nb() if not grouped and
returns_arrayis False
For implementation details on the meta versions, see
- reduce_grouped_to_array_meta_nb() if grouped and
returns_arrayis True - reduce_grouped_meta_nb() if grouped and
returns_arrayis False - reduce_to_array_meta_nb() if not grouped and
returns_arrayis True - reduce_meta_nb() if not grouped and
returns_arrayis False
reduce_func_nb can be a string denoting the suffix of a reducing function from vectorbtpro.generic.nb. For example, "sum" will refer to "sum_reduce_nb".
Usage
- Using regular function:
>>> mean_nb = njit(lambda a: np.nanmean(a))
>>> df.vbt.reduce(mean_nb)
a 3.0
b 3.0
c 1.8
Name: reduce, dtype: float64
>>> argmax_nb = njit(lambda a: np.argmax(a))
>>> df.vbt.reduce(argmax_nb, returns_idx=True)
a 2020-01-05
b 2020-01-01
c 2020-01-03
Name: reduce, dtype: datetime64[ns]
>>> df.vbt.reduce(argmax_nb, returns_idx=True, to_index=False)
a 4
b 0
c 2
Name: reduce, dtype: int64
>>> min_max_nb = njit(lambda a: np.array([np.nanmin(a), np.nanmax(a)]))
>>> df.vbt.reduce(min_max_nb, returns_array=True, wrap_kwargs=dict(name_or_index=['min', 'max']))
a b c
min 1 1 1
max 5 5 3
>>> group_by = pd.Series(['first', 'first', 'second'], name='group')
>>> df.vbt.reduce(mean_nb, group_by=group_by)
group
first 3.0
second 1.8
dtype: float64
- Using meta function:
>>> mean_meta_nb = njit(lambda col, a: np.nanmean(a[:, col]))
>>> pd.Series.vbt.reduce(
... mean_meta_nb,
... df['a'].vbt.to_2d_array(),
... wrapper=df['a'].vbt.wrapper
... )
3.0
>>> vbt.pd_acc.reduce(
... mean_meta_nb,
... df.vbt.to_2d_array(),
... wrapper=df.vbt.wrapper
... )
a 3.0
b 3.0
c 1.8
Name: reduce, dtype: float64
>>> grouped_mean_meta_nb = njit(lambda group_idxs, group, a: np.nanmean(a[:, group_idxs]))
>>> group_by = pd.Series(['first', 'first', 'second'], name='group')
>>> vbt.pd_acc.reduce(
... grouped_mean_meta_nb,
... df.vbt.to_2d_array(),
... wrapper=df.vbt.wrapper,
... group_by=group_by
... )
group
first 3.0
second 1.8
Name: reduce, dtype: float64
- Using templates and broadcasting:
>>> mean_a_b_nb = njit(lambda col, a, b: \
... np.array([np.nanmean(a[:, col]), np.nanmean(b[:, col])]))
>>> vbt.pd_acc.reduce(
... mean_a_b_nb,
... vbt.Rep('arr1'),
... vbt.Rep('arr2'),
... returns_array=True,
... broadcast_named_args=dict(
... arr1=pd.Series([1, 2, 3, 4, 5], index=df.index),
... arr2=pd.DataFrame([[1, 2, 3]], columns=['a', 'b', 'c'])
... ),
... wrap_kwargs=dict(name_or_index=['arr1', 'arr2'])
... )
a b c
arr1 3.0 3.0 3.0
arr2 1.0 2.0 3.0
resample_apply class method¶
GenericAccessor.resample_apply(
rule,
reduce_func_nb,
*args,
use_groupby_apply=False,
freq=None,
resample_kwargs=None,
broadcast_named_args=None,
broadcast_kwargs=None,
template_context=None,
wrapper=None,
wrap_kwargs=None,
**kwargs
)
Resample.
Argument rule can be an instance of Resampler, pandas.core.resample.Resampler, or any other frequency-like object that can be accepted by pd.DataFrame.resample with resample_kwargs passed as keyword arguments. If use_groupby_apply is True, uses GenericAccessor.groupby_apply() (with some post-processing). Otherwise, uses GenericAccessor.resample_to_index().
Usage
- Using regular function:
>>> mean_nb = njit(lambda a: np.nanmean(a))
>>> df.vbt.resample_apply('2d', mean_nb)
a b c
2020-01-01 1.5 4.5 1.5
2020-01-03 3.5 2.5 2.5
2020-01-05 5.0 1.0 1.0
- Using meta function:
>>> mean_ratio_meta_nb = njit(lambda idxs, group, col, a, b: \
... np.mean(a[idxs, col]) / np.mean(b[idxs, col]))
>>> vbt.pd_acc.resample_apply(
... '2d',
... mean_ratio_meta_nb,
... df.vbt.to_2d_array() - 1,
... df.vbt.to_2d_array() + 1,
... wrapper=df.vbt.wrapper
... )
a b c
2020-01-01 0.200000 0.636364 0.200000
2020-01-03 0.555556 0.428571 0.428571
2020-01-05 0.666667 0.000000 0.000000
- Using templates and broadcasting:
>>> vbt.pd_acc.resample_apply(
... '2d',
... mean_ratio_meta_nb,
... vbt.Rep('a'),
... vbt.Rep('b'),
... broadcast_named_args=dict(
... a=pd.Series([1, 2, 3, 4, 5], index=df.index),
... b=pd.DataFrame([[1, 2, 3]], columns=['a', 'b', 'c'])
... )
... )
a b c
2020-01-01 1.5 0.75 0.500000
2020-01-03 3.5 1.75 1.166667
2020-01-05 5.0 2.50 1.666667
resample_between_bounds class method¶
GenericAccessor.resample_between_bounds(
target_lbound_index,
target_rbound_index,
reduce_func_nb,
*args,
closed_lbound=True,
closed_rbound=False,
broadcast_named_args=None,
broadcast_kwargs=None,
template_context=None,
jitted=None,
chunked=None,
wrapper=None,
wrap_with_lbound=None,
wrap_kwargs=None
)
Resample between target index bounds.
Applies reduce_index_ranges_nb() on index ranges from map_bounds_to_source_ranges_nb().
For details on the meta version, see reduce_index_ranges_meta_nb().
Usage
- Using regular function:
>>> h_index = pd.date_range('2020-01-01', '2020-01-05', freq='1h')
>>> d_index = pd.date_range('2020-01-01', '2020-01-05', freq='1d')
>>> h_sr = pd.Series(range(len(h_index)), index=h_index)
>>> h_sr.vbt.resample_between_bounds(d_index, d_index.shift(), njit(lambda x: x.mean()))
2020-01-01 11.5
2020-01-02 35.5
2020-01-03 59.5
2020-01-04 83.5
2020-01-05 96.0
Freq: D, dtype: float64
- Using meta function:
>>> mean_ratio_meta_nb = njit(lambda from_i, to_i, col, a, b: \
... np.mean(a[from_i:to_i][col]) / np.mean(b[from_i:to_i][col]))
>>> vbt.pd_acc.resample_between_bounds(
... d_index,
... d_index.shift(),
... mean_ratio_meta_nb,
... h_sr.vbt.to_2d_array() - 1,
... h_sr.vbt.to_2d_array() + 1,
... wrapper=h_sr.vbt.wrapper
... )
2020-01-01 -1.000000
2020-01-02 0.920000
2020-01-03 0.959184
2020-01-04 0.972603
2020-01-05 0.979381
Freq: D, dtype: float64
- Using templates and broadcasting:
>>> vbt.pd_acc.resample_between_bounds(
... d_index,
... d_index.shift(),
... mean_ratio_meta_nb,
... vbt.Rep('a'),
... vbt.Rep('b'),
... broadcast_named_args=dict(
... a=h_sr - 1,
... b=h_sr + 1
... )
... )
2020-01-01 -1.000000
2020-01-02 0.920000
2020-01-03 0.959184
2020-01-04 0.972603
2020-01-05 0.979381
Freq: D, dtype: float64
resample_to_index class method¶
GenericAccessor.resample_to_index(
index,
reduce_func_nb,
*args,
freq=None,
before=False,
broadcast_named_args=None,
broadcast_kwargs=None,
template_context=None,
jitted=None,
chunked=None,
wrapper=None,
wrap_kwargs=None,
silence_warnings=None
)
Resample solely based on target index.
Applies reduce_index_ranges_nb() on index ranges from map_index_to_source_ranges_nb().
For details on the meta version, see reduce_index_ranges_meta_nb().
Usage
- Downsampling:
>>> h_index = pd.date_range('2020-01-01', '2020-01-05', freq='1h')
>>> d_index = pd.date_range('2020-01-01', '2020-01-05', freq='1d')
>>> h_sr = pd.Series(range(len(h_index)), index=h_index)
>>> h_sr.vbt.resample_to_index(d_index, njit(lambda x: x.mean()))
2020-01-01 11.5
2020-01-02 35.5
2020-01-03 59.5
2020-01-04 83.5
2020-01-05 96.0
Freq: D, dtype: float64
>>> h_sr.vbt.resample_to_index(d_index, njit(lambda x: x.mean()), before=True)
2020-01-01 0.0
2020-01-02 12.5
2020-01-03 36.5
2020-01-04 60.5
2020-01-05 84.5
Freq: D, dtype: float64
- Upsampling:
>>> d_sr = pd.Series(range(len(d_index)), index=d_index)
>>> d_sr.vbt.resample_to_index(h_index, njit(lambda x: x[-1]))
2020-01-01 00:00:00 0.0
2020-01-01 01:00:00 NaN
2020-01-01 02:00:00 NaN
2020-01-01 03:00:00 NaN
2020-01-01 04:00:00 NaN
... ...
2020-01-04 20:00:00 NaN
2020-01-04 21:00:00 NaN
2020-01-04 22:00:00 NaN
2020-01-04 23:00:00 NaN
2020-01-05 00:00:00 4.0
Freq: H, Length: 97, dtype: float64
- Using meta function:
>>> mean_ratio_meta_nb = njit(lambda from_i, to_i, col, a, b: \
... np.mean(a[from_i:to_i][col]) / np.mean(b[from_i:to_i][col]))
>>> vbt.pd_acc.resample_to_index(
... d_index,
... mean_ratio_meta_nb,
... h_sr.vbt.to_2d_array() - 1,
... h_sr.vbt.to_2d_array() + 1,
... wrapper=h_sr.vbt.wrapper
... )
2020-01-01 -1.000000
2020-01-02 0.920000
2020-01-03 0.959184
2020-01-04 0.972603
2020-01-05 0.979381
Freq: D, dtype: float64
- Using templates and broadcasting:
>>> vbt.pd_acc.resample_to_index(
... d_index,
... mean_ratio_meta_nb,
... vbt.Rep('a'),
... vbt.Rep('b'),
... broadcast_named_args=dict(
... a=h_sr - 1,
... b=h_sr + 1
... )
... )
2020-01-01 -1.000000
2020-01-02 0.920000
2020-01-03 0.959184
2020-01-04 0.972603
2020-01-05 0.979381
Freq: D, dtype: float64
resolve_mapping method¶
Resolve mapping.
Set mapping to False to disable mapping completely.
resolve_self method¶
GenericAccessor.resolve_self(
cond_kwargs=None,
custom_arg_names=None,
impacts_caching=True,
silence_warnings=False
)
Resolve self.
Creates a copy of this instance mapping is different in cond_kwargs.
robust_scale method¶
GenericAccessor.robust_scale(
*,
with_centering=True,
with_scaling=True,
quantile_range=(25.0, 75.0),
copy=True,
unit_variance=False,
**kwargs
)
See sklearn.preprocessing.RobustScaler.
rolling_all method¶
See rolling_all_nb().
rolling_any method¶
See rolling_any_nb().
rolling_apply class method¶
GenericAccessor.rolling_apply(
window,
reduce_func_nb,
*args,
minp=None,
broadcast_named_args=None,
broadcast_kwargs=None,
template_context=None,
jitted=None,
chunked=None,
wrapper=None,
wrap_kwargs=None
)
See rolling_reduce_nb() for integer windows and rolling_freq_reduce_nb() for frequency windows.
For details on the meta version, see rolling_reduce_meta_nb() for integer windows and rolling_freq_reduce_meta_nb() for frequency windows.
If window is None, it will become an expanding window.
Usage
- Using regular function:
>>> mean_nb = njit(lambda a: np.nanmean(a))
>>> df.vbt.rolling_apply(3, mean_nb)
a b c
2020-01-01 NaN NaN NaN
2020-01-02 NaN NaN NaN
2020-01-03 2.0 4.0 2.000000
2020-01-04 3.0 3.0 2.333333
2020-01-05 4.0 2.0 2.000000
- Using a frequency-based window:
>>> df.vbt.rolling_apply("3d", mean_nb)
a b c
2020-01-01 1.0 5.0 1.000000
2020-01-02 1.5 4.5 1.500000
2020-01-03 2.0 4.0 2.000000
2020-01-04 3.0 3.0 2.333333
2020-01-05 4.0 2.0 2.000000
- Using meta function:
>>> mean_ratio_meta_nb = njit(lambda from_i, to_i, col, a, b: \
... np.mean(a[from_i:to_i, col]) / np.mean(b[from_i:to_i, col]))
>>> vbt.pd_acc.rolling_apply(
... 3,
... mean_ratio_meta_nb,
... df.vbt.to_2d_array() - 1,
... df.vbt.to_2d_array() + 1,
... wrapper=df.vbt.wrapper,
... )
a b c
2020-01-01 NaN NaN NaN
2020-01-02 NaN NaN NaN
2020-01-03 0.333333 0.600000 0.333333
2020-01-04 0.500000 0.500000 0.400000
2020-01-05 0.600000 0.333333 0.333333
- Using templates and broadcasting:
>>> vbt.pd_acc.rolling_apply(
... 2,
... mean_ratio_meta_nb,
... vbt.Rep('a'),
... vbt.Rep('b'),
... broadcast_named_args=dict(
... a=pd.Series([1, 2, 3, 4, 5], index=df.index),
... b=pd.DataFrame([[1, 2, 3]], columns=['a', 'b', 'c'])
... )
... )
a b c
2020-01-01 NaN NaN NaN
2020-01-02 1.5 0.75 0.500000
2020-01-03 2.5 1.25 0.833333
2020-01-04 3.5 1.75 1.166667
2020-01-05 4.5 2.25 1.500000
rolling_corr method¶
GenericAccessor.rolling_corr(
other,
window,
minp=None,
broadcast_kwargs=None,
jitted=None,
chunked=None,
wrap_kwargs=None
)
See rolling_corr_nb().
rolling_cov method¶
GenericAccessor.rolling_cov(
other,
window,
minp=None,
ddof=1,
broadcast_kwargs=None,
jitted=None,
chunked=None,
wrap_kwargs=None
)
See rolling_cov_nb().
rolling_idxmax method¶
GenericAccessor.rolling_idxmax(
window,
minp=None,
local=False,
jitted=None,
chunked=None,
wrap_kwargs=None
)
See rolling_argmax_nb().
rolling_idxmin method¶
GenericAccessor.rolling_idxmin(
window,
minp=None,
local=False,
jitted=None,
chunked=None,
wrap_kwargs=None
)
See rolling_argmin_nb().
rolling_max method¶
See rolling_max_nb().
rolling_mean method¶
See rolling_mean_nb().
rolling_min method¶
See rolling_min_nb().
rolling_ols method¶
GenericAccessor.rolling_ols(
other,
window,
minp=None,
broadcast_kwargs=None,
jitted=None,
chunked=None,
wrap_kwargs=None
)
See rolling_ols_nb().
Returns two arrays: slope and intercept.
rolling_pattern_similarity method¶
GenericAccessor.rolling_pattern_similarity(
pattern,
window=None,
max_window=None,
row_select_prob=1.0,
window_select_prob=1.0,
interp_mode='mixed',
rescale_mode='minmax',
vmin=nan,
vmax=nan,
pmin=nan,
pmax=nan,
invert=False,
error_type='absolute',
distance_measure='mae',
max_error=nan,
max_error_interp_mode=None,
max_error_as_maxdist=False,
max_error_strict=False,
min_pct_change=nan,
max_pct_change=nan,
min_similarity=nan,
minp=None,
jitted=None,
chunked=None,
wrap_kwargs=None
)
See rolling_pattern_similarity_nb().
rolling_prod method¶
See rolling_prod_nb().
rolling_rank method¶
GenericAccessor.rolling_rank(
window,
minp=None,
pct=False,
jitted=None,
chunked=None,
wrap_kwargs=None
)
See rolling_rank_nb().
rolling_std method¶
GenericAccessor.rolling_std(
window,
minp=None,
ddof=1,
jitted=None,
chunked=None,
wrap_kwargs=None
)
See rolling_std_nb().
rolling_sum method¶
See rolling_sum_nb().
rolling_zscore method¶
GenericAccessor.rolling_zscore(
window,
minp=None,
ddof=1,
jitted=None,
chunked=None,
wrap_kwargs=None
)
See rolling_zscore_nb().
row_apply class method¶
GenericAccessor.apply_along_axis() with axis=0.
scale method¶
See sklearn.preprocessing.StandardScaler.
scatterplot method¶
GenericAccessor.plot() with 'markers' mode.
Usage
shuffle method¶
See shuffle_nb().
squeeze_grouped class method¶
GenericAccessor.squeeze_grouped(
squeeze_func_nb,
*args,
broadcast_named_args=None,
broadcast_kwargs=None,
template_context=None,
jitted=None,
chunked=None,
wrapper=None,
group_by=None,
wrap_kwargs=None
)
Squeeze each group of columns into a single column.
See squeeze_grouped_nb(). For details on the meta version, see squeeze_grouped_meta_nb().
Usage
- Using regular function:
>>> mean_nb = njit(lambda a: np.nanmean(a))
>>> group_by = pd.Series(['first', 'first', 'second'], name='group')
>>> df.vbt.squeeze_grouped(mean_nb, group_by=group_by)
group first second
2020-01-01 3.0 1.0
2020-01-02 3.0 2.0
2020-01-03 3.0 3.0
2020-01-04 3.0 2.0
2020-01-05 3.0 1.0
- Using meta function:
>>> mean_ratio_meta_nb = njit(lambda i, group_idxs, group, a, b: \
... np.mean(a[i][group_idxs]) / np.mean(b[i][group_idxs]))
>>> vbt.pd_acc.squeeze_grouped(
... mean_ratio_meta_nb,
... df.vbt.to_2d_array() - 1,
... df.vbt.to_2d_array() + 1,
... wrapper=df.vbt.wrapper,
... group_by=group_by
... )
group first second
2020-01-01 0.5 0.000000
2020-01-02 0.5 0.333333
2020-01-03 0.5 0.500000
2020-01-04 0.5 0.333333
2020-01-05 0.5 0.000000
- Using templates and broadcasting:
>>> vbt.pd_acc.squeeze_grouped(
... mean_ratio_meta_nb,
... vbt.Rep('a'),
... vbt.Rep('b'),
... broadcast_named_args=dict(
... a=pd.Series([1, 2, 3, 4, 5], index=df.index),
... b=pd.DataFrame([[1, 2, 3]], columns=['a', 'b', 'c'])
... ),
... group_by=[0, 0, 1]
... )
0 1
2020-01-01 0.666667 0.333333
2020-01-02 1.333333 0.666667
2020-01-03 2.000000 1.000000
2020-01-04 2.666667 1.333333
2020-01-05 3.333333 1.666667
stats_defaults property¶
Defaults for StatsBuilderMixin.stats().
Merges StatsBuilderMixin.stats_defaults and stats from generic.
std method¶
GenericAccessor.std(
ddof=1,
use_jitted=None,
jitted=None,
chunked=None,
group_by=None,
wrap_kwargs=None
)
Return standard deviation of non-NaN elements.
subplots class variable¶
Subplots supported by GenericAccessor.
HybridConfig(
plot=dict(
check_is_not_grouped=True,
plot_func='plot',
pass_trace_names=False,
tags='generic'
)
)
Returns GenericAccessor._subplots, which gets (hybrid-) copied upon creation of each instance. Thus, changing this config won't affect the class.
To change subplots, you can either change the config in-place, override this property, or overwrite the instance variable GenericAccessor._subplots.
sum method¶
Return sum of non-NaN elements.
to_daily_log_returns method¶
Get daily log returns of this object.
to_daily_returns method¶
Get daily returns of this object.
to_log_returns method¶
Get log returns of this object.
to_mapped method¶
Convert this object into an instance of MappedArray.
to_returns method¶
Get returns of this object.
transform method¶
Transform using a transformer.
A transformer can be any class instance that has transform and fit_transform methods, ideally subclassing sklearn.base.TransformerMixin and sklearn.base.BaseEstimator.
Will fit transformer if not fitted.
**kwargs are passed to the transform or fit_transform method.
Usage
>>> from sklearn.preprocessing import MinMaxScaler
>>> df.vbt.transform(MinMaxScaler((-1, 1)))
a b c
2020-01-01 -1.0 1.0 -1.0
2020-01-02 -0.5 0.5 0.0
2020-01-03 0.0 0.0 1.0
2020-01-04 0.5 -0.5 0.0
2020-01-05 1.0 -1.0 -1.0
>>> fitted_scaler = MinMaxScaler((-1, 1)).fit(np.array([[2], [4]]))
>>> df.vbt.transform(fitted_scaler)
a b c
2020-01-01 -2.0 2.0 -2.0
2020-01-02 -1.0 1.0 -1.0
2020-01-03 0.0 0.0 0.0
2020-01-04 1.0 -1.0 -1.0
2020-01-05 2.0 -2.0 -2.0
ts_heatmap method¶
Heatmap of time-series data.
value_counts method¶
GenericAccessor.value_counts(
axis=1,
normalize=False,
sort_uniques=True,
sort=False,
ascending=False,
dropna=False,
group_by=None,
mapping=None,
incl_all_keys=False,
jitted=None,
chunked=None,
wrap_kwargs=None,
**kwargs
)
Return a Series/DataFrame containing counts of unique values.
Args
axis:int- 0 - counts per row, 1 - counts per column, and -1 - counts across the whole object.
normalize:bool- Whether to return the relative frequencies of the unique values.
sort_uniques:bool- Whether to sort uniques.
sort:bool- Whether to sort by frequency.
ascending:bool- Whether to sort in ascending order.
dropna:bool- Whether to exclude counts of NaN.
group_by:any-
Group or ungroup columns.
See Grouper.
mapping:mapping_like- Mapping of values to labels.
incl_all_keys:bool- Whether to include all mapping keys, no only those that are present in the array.
jitted:any- Whether to JIT-compile value_counts_nb() or options.
chunked:any-
Whether to chunk value_counts_nb() or options.
See resolve_chunked().
wrap_kwargs:dict- Keyword arguments passed to ArrayWrapper.wrap().
**kwargs- Keyword arguments passed to apply_mapping().
Usage
>>> df.vbt.value_counts()
a b c
1 1 1 2
2 1 1 2
3 1 1 1
4 1 1 0
5 1 1 0
>>> df.vbt.value_counts(axis=-1)
1 4
2 4
3 3
4 2
5 2
Name: value_counts, dtype: int64
>>> mapping = {x: 'test_' + str(x) for x in pd.unique(df.values.flatten())}
>>> df.vbt.value_counts(mapping=mapping)
a b c
test_1 1 1 2
test_2 1 1 2
test_3 1 1 1
test_4 1 1 0
test_5 1 1 0
>>> sr = pd.Series([1, 2, 2, 3, 3, 3, np.nan])
>>> sr.vbt.value_counts(mapping=mapping)
test_1 1
test_2 2
test_3 3
NaN 1
dtype: int64
>>> sr.vbt.value_counts(mapping=mapping, dropna=True)
test_1 1
test_2 2
test_3 3
dtype: int64
>>> sr.vbt.value_counts(mapping=mapping, sort=True)
test_3 3
test_2 2
test_1 1
NaN 1
dtype: int64
>>> sr.vbt.value_counts(mapping=mapping, sort=True, ascending=True)
test_1 1
NaN 1
test_2 2
test_3 3
dtype: int64
>>> sr.vbt.value_counts(mapping=mapping, incl_all_keys=True)
test_1 1
test_2 2
test_3 3
test_4 0
test_5 0
NaN 1
dtype: int64
vidya method¶
See vidya_nb().
volume method¶
GenericAccessor.volume(
column=None,
x_level=None,
y_level=None,
z_level=None,
x_labels=None,
y_labels=None,
z_labels=None,
slider_level=None,
slider_labels=None,
active=0,
scene_name='scene',
fillna=None,
fig=None,
return_fig=True,
**kwargs
)
Create a 3D volume figure based on object's multi-index and values.
If multi-index contains more than three levels or you want them in specific order, pass x_level, y_level, and z_level, each (int if index or str if name) corresponding to an axis of the volume. Optionally, pass slider_level to use a level as a slider.
Creates Volume and returns the figure.
Usage
>>> multi_index = pd.MultiIndex.from_tuples([
... (1, 1, 1),
... (2, 2, 2),
... (3, 3, 3)
... ])
>>> sr = pd.Series(np.arange(len(multi_index)), index=multi_index)
>>> sr
1 1 1 0
2 2 2 1
3 3 3 2
dtype: int64
>>> sr.vbt.volume().show()
wm_mean method¶
See wm_mean_nb().
wwm_mean method¶
GenericAccessor.wwm_mean(
period,
minp=0,
adjust=True,
jitted=None,
chunked=None,
wrap_kwargs=None
)
See wwm_mean_nb().
wwm_std method¶
See wwm_std_nb().
zscore method¶
Compute z-score using sklearn.preprocessing.StandardScaler.
GenericDFAccessor class¶
Accessor on top of data of any type. For DataFrames only.
Accessible via pd.DataFrame.vbt.
Superclasses
- Analyzable
- AttrResolverMixin
- BaseAccessor
- BaseDFAccessor
- Cacheable
- Chainable
- Comparable
- Configured
- ExtPandasIndexer
- GenericAccessor
- HasSettings
- IndexApplier
- IndexingBase
- Itemable
- PandasIndexer
- Paramable
- Pickleable
- PlotsBuilderMixin
- Prettified
- StatsBuilderMixin
- Wrapping
Inherited members
- AttrResolverMixin.deep_getattr()
- AttrResolverMixin.post_resolve_attr()
- AttrResolverMixin.pre_resolve_attr()
- AttrResolverMixin.resolve_attr()
- AttrResolverMixin.resolve_shortcut_attr()
- BaseAccessor.align()
- BaseAccessor.align_to()
- BaseAccessor.apply()
- BaseAccessor.apply_and_concat()
- BaseAccessor.apply_to_index()
- BaseAccessor.broadcast()
- BaseAccessor.broadcast_combs()
- BaseAccessor.broadcast_to()
- BaseAccessor.column_stack()
- BaseAccessor.combine()
- BaseAccessor.concat()
- BaseAccessor.cross()
- BaseAccessor.cross()
- BaseAccessor.cross_with()
- BaseAccessor.empty()
- BaseAccessor.empty_like()
- BaseAccessor.eval()
- BaseAccessor.get()
- BaseAccessor.indexing_func()
- BaseAccessor.indexing_setter_func()
- BaseAccessor.items()
- BaseAccessor.make_symmetric()
- BaseAccessor.repeat()
- BaseAccessor.resolve_column_stack_kwargs()
- BaseAccessor.resolve_row_stack_kwargs()
- BaseAccessor.resolve_shape()
- BaseAccessor.row_stack()
- BaseAccessor.set()
- BaseAccessor.set_between()
- BaseAccessor.split()
- BaseAccessor.split_apply()
- BaseAccessor.tile()
- BaseAccessor.to_1d_array()
- BaseAccessor.to_2d_array()
- BaseAccessor.to_data()
- BaseAccessor.to_dict()
- BaseAccessor.unstack_to_array()
- BaseAccessor.unstack_to_df()
- Cacheable.get_ca_setup()
- Chainable.pipe()
- Configured.copy()
- Configured.equals()
- Configured.get_writeable_attrs()
- Configured.prettify()
- Configured.replace()
- Configured.resolve_merge_kwargs()
- Configured.update_config()
- GenericAccessor.ago()
- GenericAccessor.all_ago()
- GenericAccessor.any_ago()
- GenericAccessor.apply_along_axis()
- GenericAccessor.apply_and_reduce()
- GenericAccessor.apply_mapping()
- GenericAccessor.areaplot()
- GenericAccessor.barplot()
- GenericAccessor.bfill()
- GenericAccessor.binarize()
- GenericAccessor.boxplot()
- GenericAccessor.bshift()
- GenericAccessor.cls_dir
- GenericAccessor.column_apply()
- GenericAccessor.column_only_select
- GenericAccessor.config
- GenericAccessor.corr()
- GenericAccessor.count()
- GenericAccessor.cov()
- GenericAccessor.crossed_above()
- GenericAccessor.crossed_below()
- GenericAccessor.cumprod()
- GenericAccessor.cumsum()
- GenericAccessor.demean()
- GenericAccessor.describe()
- GenericAccessor.df_accessor_cls
- GenericAccessor.diff()
- GenericAccessor.digitize()
- GenericAccessor.drawdown()
- GenericAccessor.drawdowns
- GenericAccessor.ewm_mean()
- GenericAccessor.ewm_std()
- GenericAccessor.expanding_apply()
- GenericAccessor.expanding_corr()
- GenericAccessor.expanding_cov()
- GenericAccessor.expanding_idxmax()
- GenericAccessor.expanding_idxmin()
- GenericAccessor.expanding_max()
- GenericAccessor.expanding_mean()
- GenericAccessor.expanding_min()
- GenericAccessor.expanding_ols()
- GenericAccessor.expanding_rank()
- GenericAccessor.expanding_std()
- GenericAccessor.expanding_zscore()
- GenericAccessor.fbfill()
- GenericAccessor.ffill()
- GenericAccessor.fillna()
- GenericAccessor.find_pattern()
- GenericAccessor.flatten_grouped()
- GenericAccessor.fshift()
- GenericAccessor.get_drawdowns()
- GenericAccessor.get_ranges()
- GenericAccessor.group_select
- GenericAccessor.groupby_apply()
- GenericAccessor.groupby_transform()
- GenericAccessor.heatmap()
- GenericAccessor.histplot()
- GenericAccessor.idxmax()
- GenericAccessor.idxmin()
- GenericAccessor.iloc
- GenericAccessor.indexing_kwargs
- GenericAccessor.lineplot()
- GenericAccessor.loc
- GenericAccessor.ma()
- GenericAccessor.map()
- GenericAccessor.mapping
- GenericAccessor.max()
- GenericAccessor.maxabs_scale()
- GenericAccessor.mean()
- GenericAccessor.median()
- GenericAccessor.min()
- GenericAccessor.minmax_scale()
- GenericAccessor.msd()
- GenericAccessor.normalize()
- GenericAccessor.obj
- GenericAccessor.overlay_with_heatmap()
- GenericAccessor.pct_change()
- GenericAccessor.plot()
- GenericAccessor.plot_against()
- GenericAccessor.plot_pattern()
- GenericAccessor.plots_defaults
- GenericAccessor.power_transform()
- GenericAccessor.product()
- GenericAccessor.proximity_apply()
- GenericAccessor.qqplot()
- GenericAccessor.quantile_transform()
- GenericAccessor.range_only_select
- GenericAccessor.ranges
- GenericAccessor.rank()
- GenericAccessor.realign()
- GenericAccessor.realign_closing()
- GenericAccessor.realign_opening()
- GenericAccessor.rebase()
- GenericAccessor.rec_state
- GenericAccessor.reduce()
- GenericAccessor.resample_apply()
- GenericAccessor.resample_between_bounds()
- GenericAccessor.resample_to_index()
- GenericAccessor.resolve_mapping()
- GenericAccessor.resolve_self()
- GenericAccessor.robust_scale()
- GenericAccessor.rolling_all()
- GenericAccessor.rolling_any()
- GenericAccessor.rolling_apply()
- GenericAccessor.rolling_corr()
- GenericAccessor.rolling_cov()
- GenericAccessor.rolling_idxmax()
- GenericAccessor.rolling_idxmin()
- GenericAccessor.rolling_max()
- GenericAccessor.rolling_mean()
- GenericAccessor.rolling_min()
- GenericAccessor.rolling_ols()
- GenericAccessor.rolling_pattern_similarity()
- GenericAccessor.rolling_prod()
- GenericAccessor.rolling_rank()
- GenericAccessor.rolling_std()
- GenericAccessor.rolling_sum()
- GenericAccessor.rolling_zscore()
- GenericAccessor.row_apply()
- GenericAccessor.scale()
- GenericAccessor.scatterplot()
- GenericAccessor.self_aliases
- GenericAccessor.shuffle()
- GenericAccessor.squeeze_grouped()
- GenericAccessor.sr_accessor_cls
- GenericAccessor.stats_defaults
- GenericAccessor.std()
- GenericAccessor.sum()
- GenericAccessor.to_daily_log_returns()
- GenericAccessor.to_daily_returns()
- GenericAccessor.to_log_returns()
- GenericAccessor.to_mapped()
- GenericAccessor.to_returns()
- GenericAccessor.transform()
- GenericAccessor.ts_heatmap()
- GenericAccessor.value_counts()
- GenericAccessor.vidya()
- GenericAccessor.volume()
- GenericAccessor.wm_mean()
- GenericAccessor.wrapper
- GenericAccessor.wwm_mean()
- GenericAccessor.wwm_std()
- GenericAccessor.xloc
- GenericAccessor.zscore()
- HasSettings.get_path_setting()
- HasSettings.get_path_settings()
- HasSettings.get_setting()
- HasSettings.get_settings()
- HasSettings.has_path_setting()
- HasSettings.has_path_settings()
- HasSettings.has_setting()
- HasSettings.has_settings()
- HasSettings.reset_settings()
- HasSettings.resolve_setting()
- HasSettings.resolve_settings_paths()
- HasSettings.set_settings()
- IndexApplier.add_levels()
- IndexApplier.drop_duplicate_levels()
- IndexApplier.drop_levels()
- IndexApplier.drop_redundant_levels()
- IndexApplier.rename_levels()
- IndexApplier.select_levels()
- PandasIndexer.xs()
- 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()
- PlotsBuilderMixin.build_subplots_doc()
- PlotsBuilderMixin.override_subplots_doc()
- PlotsBuilderMixin.plots()
- StatsBuilderMixin.build_metrics_doc()
- StatsBuilderMixin.override_metrics_doc()
- StatsBuilderMixin.stats()
- Wrapping.as_param()
- Wrapping.regroup()
- Wrapping.resample()
- Wrapping.resolve_stack_kwargs()
- Wrapping.select_col()
- Wrapping.select_col_from_obj()
Subclasses
band method¶
Calculate the band by its name.
Examples for the band name:
- "50%": 50th quantile
- "Q=50%": 50th quantile
- "Q=0.5": 50th quantile
- "Z=1.96": Z-score of 1.96
- "P=95%": One-tailed significance level of 0.95 (translated into z-score)
- "P=0.95": One-tailed significance level of 0.95 (translated into z-score)
- "median": Median (50th quantile)
- "mean": Mean across all columns
- "min": Min across all columns
- "max": Max across all columns
- "lowest": Column with the lowest final value
- "highest": Column with the highest final value
plot_projections method¶
GenericDFAccessor.plot_projections(
plot_projections=True,
plot_bands=True,
plot_lower=True,
plot_middle=True,
plot_upper=True,
plot_aux_middle=True,
plot_fill=True,
colorize=True,
rename_levels=None,
projection_trace_kwargs=None,
upper_trace_kwargs=None,
middle_trace_kwargs=None,
lower_trace_kwargs=None,
aux_middle_trace_kwargs=None,
add_trace_kwargs=None,
fig=None,
**layout_kwargs
)
Plot a DataFrame where each column is a projection.
If plot_projections is True, will plot each projection as a semi-transparent line.
The arguments plot_lower, plot_middle, plot_aux_middle, and plot_upper represent bands and accept the following:
- True: Plot the band using the default quantile (20/50/80)
- False: Do not plot the band
- callable: Custom function that accepts DataFrame and reduces it across columns
- For other options see GenericDFAccessor.band()
Note
When providing z-scores, the upper should be positive, the middle should be "mean", and the lower should be negative. When providing significance levels, the middle should be "mean", while the lower should be positive and lower than the upper, for example, 25% and 75%.
Argument colorize allows the following values:
- False: Do not colorize
- True or "median": Colorize by median
- "mean": Colorize by mean
- "last": Colorize by last value
- callable: Custom function that accepts (rebased to 0) Series/DataFrame with nans already dropped and reduces it across rows
Colorization is performed by mapping the metric value of the band to the range between the minimum and maximum value across all projections where 0 is always the middle point. If none of the bands is plotted, projections got colorized. Otherwise, projections stay gray.
Usage
>>> df = pd.DataFrame({
... 0: [10, 11, 12, 11, 10],
... 1: [10, 12, 14, np.nan, np.nan],
... 2: [10, 12, 11, 12, np.nan],
... 3: [10, 9, 8, 9, 8],
... 4: [10, 11, np.nan, np.nan, np.nan],
... })
>>> df.vbt.plot_projections().show()
GenericSRAccessor class¶
Accessor on top of data of any type. For Series only.
Accessible via pd.Series.vbt.
Superclasses
- Analyzable
- AttrResolverMixin
- BaseAccessor
- BaseSRAccessor
- Cacheable
- Chainable
- Comparable
- Configured
- ExtPandasIndexer
- GenericAccessor
- HasSettings
- IndexApplier
- IndexingBase
- Itemable
- PandasIndexer
- Paramable
- Pickleable
- PlotsBuilderMixin
- Prettified
- StatsBuilderMixin
- Wrapping
Inherited members
- AttrResolverMixin.deep_getattr()
- AttrResolverMixin.post_resolve_attr()
- AttrResolverMixin.pre_resolve_attr()
- AttrResolverMixin.resolve_attr()
- AttrResolverMixin.resolve_shortcut_attr()
- BaseAccessor.align()
- BaseAccessor.align_to()
- BaseAccessor.apply()
- BaseAccessor.apply_and_concat()
- BaseAccessor.apply_to_index()
- BaseAccessor.broadcast()
- BaseAccessor.broadcast_combs()
- BaseAccessor.broadcast_to()
- BaseAccessor.column_stack()
- BaseAccessor.combine()
- BaseAccessor.concat()
- BaseAccessor.cross()
- BaseAccessor.cross()
- BaseAccessor.cross_with()
- BaseAccessor.empty()
- BaseAccessor.empty_like()
- BaseAccessor.eval()
- BaseAccessor.get()
- BaseAccessor.indexing_func()
- BaseAccessor.indexing_setter_func()
- BaseAccessor.items()
- BaseAccessor.make_symmetric()
- BaseAccessor.repeat()
- BaseAccessor.resolve_column_stack_kwargs()
- BaseAccessor.resolve_row_stack_kwargs()
- BaseAccessor.resolve_shape()
- BaseAccessor.row_stack()
- BaseAccessor.set()
- BaseAccessor.set_between()
- BaseAccessor.split()
- BaseAccessor.split_apply()
- BaseAccessor.tile()
- BaseAccessor.to_1d_array()
- BaseAccessor.to_2d_array()
- BaseAccessor.to_data()
- BaseAccessor.to_dict()
- BaseAccessor.unstack_to_array()
- BaseAccessor.unstack_to_df()
- Cacheable.get_ca_setup()
- Chainable.pipe()
- Configured.copy()
- Configured.equals()
- Configured.get_writeable_attrs()
- Configured.prettify()
- Configured.replace()
- Configured.resolve_merge_kwargs()
- Configured.update_config()
- GenericAccessor.ago()
- GenericAccessor.all_ago()
- GenericAccessor.any_ago()
- GenericAccessor.apply_along_axis()
- GenericAccessor.apply_and_reduce()
- GenericAccessor.apply_mapping()
- GenericAccessor.areaplot()
- GenericAccessor.barplot()
- GenericAccessor.bfill()
- GenericAccessor.binarize()
- GenericAccessor.boxplot()
- GenericAccessor.bshift()
- GenericAccessor.cls_dir
- GenericAccessor.column_apply()
- GenericAccessor.column_only_select
- GenericAccessor.config
- GenericAccessor.corr()
- GenericAccessor.count()
- GenericAccessor.cov()
- GenericAccessor.crossed_above()
- GenericAccessor.crossed_below()
- GenericAccessor.cumprod()
- GenericAccessor.cumsum()
- GenericAccessor.demean()
- GenericAccessor.describe()
- GenericAccessor.df_accessor_cls
- GenericAccessor.diff()
- GenericAccessor.digitize()
- GenericAccessor.drawdown()
- GenericAccessor.drawdowns
- GenericAccessor.ewm_mean()
- GenericAccessor.ewm_std()
- GenericAccessor.expanding_apply()
- GenericAccessor.expanding_corr()
- GenericAccessor.expanding_cov()
- GenericAccessor.expanding_idxmax()
- GenericAccessor.expanding_idxmin()
- GenericAccessor.expanding_max()
- GenericAccessor.expanding_mean()
- GenericAccessor.expanding_min()
- GenericAccessor.expanding_ols()
- GenericAccessor.expanding_rank()
- GenericAccessor.expanding_std()
- GenericAccessor.expanding_zscore()
- GenericAccessor.fbfill()
- GenericAccessor.ffill()
- GenericAccessor.fillna()
- GenericAccessor.find_pattern()
- GenericAccessor.flatten_grouped()
- GenericAccessor.fshift()
- GenericAccessor.get_drawdowns()
- GenericAccessor.get_ranges()
- GenericAccessor.group_select
- GenericAccessor.groupby_apply()
- GenericAccessor.groupby_transform()
- GenericAccessor.heatmap()
- GenericAccessor.histplot()
- GenericAccessor.idxmax()
- GenericAccessor.idxmin()
- GenericAccessor.iloc
- GenericAccessor.indexing_kwargs
- GenericAccessor.lineplot()
- GenericAccessor.loc
- GenericAccessor.ma()
- GenericAccessor.map()
- GenericAccessor.mapping
- GenericAccessor.max()
- GenericAccessor.maxabs_scale()
- GenericAccessor.mean()
- GenericAccessor.median()
- GenericAccessor.min()
- GenericAccessor.minmax_scale()
- GenericAccessor.msd()
- GenericAccessor.normalize()
- GenericAccessor.obj
- GenericAccessor.overlay_with_heatmap()
- GenericAccessor.pct_change()
- GenericAccessor.plot()
- GenericAccessor.plot_against()
- GenericAccessor.plot_pattern()
- GenericAccessor.plots_defaults
- GenericAccessor.power_transform()
- GenericAccessor.product()
- GenericAccessor.proximity_apply()
- GenericAccessor.qqplot()
- GenericAccessor.quantile_transform()
- GenericAccessor.range_only_select
- GenericAccessor.ranges
- GenericAccessor.rank()
- GenericAccessor.realign()
- GenericAccessor.realign_closing()
- GenericAccessor.realign_opening()
- GenericAccessor.rebase()
- GenericAccessor.rec_state
- GenericAccessor.reduce()
- GenericAccessor.resample_apply()
- GenericAccessor.resample_between_bounds()
- GenericAccessor.resample_to_index()
- GenericAccessor.resolve_mapping()
- GenericAccessor.resolve_self()
- GenericAccessor.robust_scale()
- GenericAccessor.rolling_all()
- GenericAccessor.rolling_any()
- GenericAccessor.rolling_apply()
- GenericAccessor.rolling_corr()
- GenericAccessor.rolling_cov()
- GenericAccessor.rolling_idxmax()
- GenericAccessor.rolling_idxmin()
- GenericAccessor.rolling_max()
- GenericAccessor.rolling_mean()
- GenericAccessor.rolling_min()
- GenericAccessor.rolling_ols()
- GenericAccessor.rolling_pattern_similarity()
- GenericAccessor.rolling_prod()
- GenericAccessor.rolling_rank()
- GenericAccessor.rolling_std()
- GenericAccessor.rolling_sum()
- GenericAccessor.rolling_zscore()
- GenericAccessor.row_apply()
- GenericAccessor.scale()
- GenericAccessor.scatterplot()
- GenericAccessor.self_aliases
- GenericAccessor.shuffle()
- GenericAccessor.squeeze_grouped()
- GenericAccessor.sr_accessor_cls
- GenericAccessor.stats_defaults
- GenericAccessor.std()
- GenericAccessor.sum()
- GenericAccessor.to_daily_log_returns()
- GenericAccessor.to_daily_returns()
- GenericAccessor.to_log_returns()
- GenericAccessor.to_mapped()
- GenericAccessor.to_returns()
- GenericAccessor.transform()
- GenericAccessor.ts_heatmap()
- GenericAccessor.value_counts()
- GenericAccessor.vidya()
- GenericAccessor.volume()
- GenericAccessor.wm_mean()
- GenericAccessor.wrapper
- GenericAccessor.wwm_mean()
- GenericAccessor.wwm_std()
- GenericAccessor.xloc
- GenericAccessor.zscore()
- HasSettings.get_path_setting()
- HasSettings.get_path_settings()
- HasSettings.get_setting()
- HasSettings.get_settings()
- HasSettings.has_path_setting()
- HasSettings.has_path_settings()
- HasSettings.has_setting()
- HasSettings.has_settings()
- HasSettings.reset_settings()
- HasSettings.resolve_setting()
- HasSettings.resolve_settings_paths()
- HasSettings.set_settings()
- IndexApplier.add_levels()
- IndexApplier.drop_duplicate_levels()
- IndexApplier.drop_levels()
- IndexApplier.drop_redundant_levels()
- IndexApplier.rename_levels()
- IndexApplier.select_levels()
- PandasIndexer.xs()
- 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()
- PlotsBuilderMixin.build_subplots_doc()
- PlotsBuilderMixin.override_subplots_doc()
- PlotsBuilderMixin.plots()
- StatsBuilderMixin.build_metrics_doc()
- StatsBuilderMixin.override_metrics_doc()
- StatsBuilderMixin.stats()
- Wrapping.as_param()
- Wrapping.regroup()
- Wrapping.resample()
- Wrapping.resolve_stack_kwargs()
- Wrapping.select_col()
- Wrapping.select_col_from_obj()
Subclasses
fit_pattern method¶
GenericSRAccessor.fit_pattern(
pattern,
interp_mode='mixed',
rescale_mode='minmax',
vmin=nan,
vmax=nan,
pmin=nan,
pmax=nan,
invert=False,
error_type='absolute',
max_error=nan,
max_error_interp_mode=None,
jitted=None
)
See fit_pattern_nb().
to_renko method¶
GenericSRAccessor.to_renko(
brick_size,
relative=False,
start_value=None,
max_out_len=None,
reset_index=False,
return_uptrend=False,
jitted=None,
wrap_kwargs=None
)
See to_renko_1d_nb().
to_renko_ohlc method¶
GenericSRAccessor.to_renko_ohlc(
brick_size,
relative=False,
start_value=None,
max_out_len=None,
reset_index=False,
jitted=None,
wrap_kwargs=None
)
TransformerT class¶
Base class for protocol classes.
Protocol classes are defined as::
class Proto(Protocol):
def meth(self) -> int:
...
Such classes are primarily used with static type checkers that recognize structural subtyping (static duck-typing).
For example::
__ class C__
def meth(self) -> int:
return 0
def func(x: Proto) -> int: return x.meth()
func(C()) # Passes static type check
See PEP 544 for details. Protocol classes decorated with @typing.runtime_checkable act as simple-minded runtime protocols that check only the presence of given attributes, ignoring their type signatures. Protocol classes can be generic, they are defined as::
class GenProto(Protocol[T]):
def meth(self) -> T:
...
Superclasses
typing.Generictyping.Protocol