Skip to content
New: Star-import, signal unraveling, Python 3.12 support, and more

#
accessors module

Custom Pandas accessors for OHLC(V) data.

Methods can be accessed as follows:

- OHLCVDFAccessor -> `pd.DataFrame.vbt.ohlcv.*`

The accessors inherit vectorbtpro.generic.accessors.

Note

Accessors do not utilize caching.

## Column names

By default, vectorbt searches for columns with names 'open', 'high', 'low', 'close', and 'volume' (case doesn't matter). You can change the naming either using `feature_map` in ohlcv, or by providing `feature_map` directly to the accessor.

    >>> from vectorbtpro import *

    >>> df = pd.DataFrame({
    ...     'my_open1': [2, 3, 4, 3.5, 2.5],
    ...     'my_high2': [3, 4, 4.5, 4, 3],
    ...     'my_low3': [1.5, 2.5, 3.5, 2.5, 1.5],
    ...     'my_close4': [2.5, 3.5, 4, 3, 2],
    ...     'my_volume5': [10, 11, 10, 9, 10]
    ... })
    >>> df.vbt.ohlcv.get_feature('open')
    None

    >>> my_feature_map = {
    ...     "my_open1": "Open",
    ...     "my_high2": "High",
    ...     "my_low3": "Low",
    ...     "my_close4": "Close",
    ...     "my_volume5": "Volume",
    ... }
    >>> ohlcv_acc = df.vbt.ohlcv(freq='d', feature_map=my_feature_map)
    >>> ohlcv_acc.get_feature('open')
    0    2.0
    1    3.0
    2    4.0
    3    3.5
    4    2.5
    Name: my_open1, dtype: float64

## Stats

Hint

See StatsBuilderMixin.stats() and OHLCVDFAccessor.metrics.

    >>> ohlcv_acc.stats()
    Start                           0
    End                             4
    Period            5 days 00:00:00
    First Price                   2.0
    Lowest Price                  1.5
    Highest Price                 4.5
    Last Price                    2.0
    First Volume                   10
    Lowest Volume                   9
    Highest Volume                 11
    Last Volume                    10
    Name: agg_stats, dtype: object

## Plots

Hint

See PlotsBuilderMixin.plots() and OHLCVDFAccessor.subplots.

OHLCVDFAccessor class has a single subplot based on OHLCVDFAccessor.plot() (without volume):

    >>> ohlcv_acc.plots(settings=dict(ohlc_type='candlestick')).show()

## OHLCVDFAccessor class

    OHLCVDFAccessor(
        wrapper,
        obj=None,
        feature_map=None,
        **kwargs
    )

Accessor on top of OHLCV data. For DataFrames only.

Accessible via `pd.DataFrame.vbt.ohlcv`.

Superclasses

- Analyzable
- AttrResolverMixin
- BaseAccessor
- BaseDFAccessor
- BaseDataMixin
- Cacheable
- Chainable
- Comparable
- Configured
- ExtPandasIndexer
- GenericAccessor
- GenericDFAccessor
- HasSettings
- IndexingBase
- OHLCDataMixin
- PandasIndexer
- 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_on_index()
- BaseAccessor.broadcast()
- BaseAccessor.broadcast_combs()
- BaseAccessor.broadcast_to()
- BaseAccessor.column_stack()
- BaseAccessor.combine()
- BaseAccessor.concat()
- BaseAccessor.cross()
- BaseAccessor.cross()
- BaseAccessor.cross_with()
- BaseAccessor.drop_duplicate_levels()
- BaseAccessor.drop_levels()
- BaseAccessor.drop_redundant_levels()
- BaseAccessor.empty()
- BaseAccessor.empty_like()
- BaseAccessor.eval()
- BaseAccessor.indexing_func()
- BaseAccessor.indexing_setter_func()
- BaseAccessor.make_symmetric()
- BaseAccessor.rename_levels()
- BaseAccessor.repeat()
- BaseAccessor.resolve_column_stack_kwargs()
- BaseAccessor.resolve_row_stack_kwargs()
- BaseAccessor.resolve_shape()
- BaseAccessor.row_stack()
- BaseAccessor.select_levels()
- BaseAccessor.set()
- BaseAccessor.set_between()
- BaseAccessor.stack_index()
- BaseAccessor.tile()
- BaseAccessor.to_1d_array()
- BaseAccessor.to_2d_array()
- BaseAccessor.to_dict()
- BaseAccessor.unstack_to_array()
- BaseAccessor.unstack_to_df()
- BaseDataMixin.assert_has_feature()
- BaseDataMixin.assert_has_symbol()
- BaseDataMixin.get()
- BaseDataMixin.get_feature()
- BaseDataMixin.get_feature_idx()
- BaseDataMixin.get_symbol()
- BaseDataMixin.get_symbol_idx()
- BaseDataMixin.has_feature()
- BaseDataMixin.has_multiple_keys()
- BaseDataMixin.has_symbol()
- BaseDataMixin.prepare_key()
- BaseDataMixin.select_feature_idxs()
- BaseDataMixin.select_features()
- BaseDataMixin.select_symbol_idxs()
- BaseDataMixin.select_symbols()
- 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.column_apply()
- GenericAccessor.corr()
- GenericAccessor.count()
- GenericAccessor.cov()
- GenericAccessor.crossed_above()
- GenericAccessor.crossed_below()
- GenericAccessor.cumprod()
- GenericAccessor.cumsum()
- GenericAccessor.demean()
- GenericAccessor.describe()
- GenericAccessor.diff()
- GenericAccessor.digitize()
- GenericAccessor.drawdown()
- 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_ranges()
- GenericAccessor.groupby_apply()
- GenericAccessor.groupby_transform()
- GenericAccessor.heatmap()
- GenericAccessor.histplot()
- GenericAccessor.idxmax()
- GenericAccessor.idxmin()
- GenericAccessor.lineplot()
- GenericAccessor.ma()
- GenericAccessor.map()
- GenericAccessor.max()
- GenericAccessor.maxabs_scale()
- GenericAccessor.mean()
- GenericAccessor.median()
- GenericAccessor.min()
- GenericAccessor.minmax_scale()
- GenericAccessor.msd()
- GenericAccessor.normalize()
- GenericAccessor.overlay_with_heatmap()
- GenericAccessor.pct_change()
- GenericAccessor.plot_against()
- GenericAccessor.plot_pattern()
- GenericAccessor.power_transform()
- GenericAccessor.product()
- GenericAccessor.proximity_apply()
- GenericAccessor.qqplot()
- GenericAccessor.quantile_transform()
- GenericAccessor.rank()
- GenericAccessor.realign()
- GenericAccessor.realign_closing()
- GenericAccessor.realign_opening()
- GenericAccessor.rebase()
- 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.shuffle()
- GenericAccessor.squeeze_grouped()
- 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.wm_mean()
- GenericAccessor.wwm_mean()
- GenericAccessor.wwm_std()
- GenericAccessor.zscore()
- GenericDFAccessor.band()
- GenericDFAccessor.cls_dir
- GenericDFAccessor.column_only_select
- GenericDFAccessor.config
- GenericDFAccessor.df_accessor_cls
- GenericDFAccessor.group_select
- GenericDFAccessor.iloc
- GenericDFAccessor.indexing_kwargs
- GenericDFAccessor.loc
- GenericDFAccessor.mapping
- GenericDFAccessor.obj
- GenericDFAccessor.plot_projections()
- GenericDFAccessor.range_only_select
- GenericDFAccessor.ranges
- GenericDFAccessor.rec_state
- GenericDFAccessor.self_aliases
- GenericDFAccessor.sr_accessor_cls
- GenericDFAccessor.wrapper
- GenericDFAccessor.xloc
- 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()
- OHLCDataMixin.close
- OHLCDataMixin.daily_log_returns
- OHLCDataMixin.daily_returns
- OHLCDataMixin.drawdowns
- OHLCDataMixin.feature_wrapper
- OHLCDataMixin.features
- OHLCDataMixin.get_daily_log_returns()
- OHLCDataMixin.get_daily_returns()
- OHLCDataMixin.get_drawdowns()
- OHLCDataMixin.get_log_returns()
- OHLCDataMixin.get_returns()
- OHLCDataMixin.get_returns_acc()
- OHLCDataMixin.has_ohlc
- OHLCDataMixin.has_ohlcv
- OHLCDataMixin.high
- OHLCDataMixin.hlc3
- OHLCDataMixin.log_returns
- OHLCDataMixin.low
- OHLCDataMixin.ohlc
- OHLCDataMixin.ohlc4
- OHLCDataMixin.ohlcv
- OHLCDataMixin.open
- OHLCDataMixin.returns
- OHLCDataMixin.returns_acc
- OHLCDataMixin.symbol_wrapper
- OHLCDataMixin.symbols
- OHLCDataMixin.trade_count
- OHLCDataMixin.volume
- OHLCDataMixin.vwap
- 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.regroup()
- Wrapping.resolve_stack_kwargs()
- Wrapping.select_col()
- Wrapping.select_col_from_obj()
- Wrapping.split()

### feature_map property

Column names.

### metrics class variable

Metrics supported by OHLCVDFAccessor.

    HybridConfig(
        start=dict(
            title='Start',
            calc_func=<function OHLCVDFAccessor.<lambda> at 0x7ff338c2b0a0>,
            agg_func=None,
            tags='wrapper'
        ),
        end=dict(
            title='End',
            calc_func=<function OHLCVDFAccessor.<lambda> at 0x7ff338c2b130>,
            agg_func=None,
            tags='wrapper'
        ),
        period=dict(
            title='Period',
            calc_func=<function OHLCVDFAccessor.<lambda> at 0x7ff338c2b1c0>,
            apply_to_timedelta=True,
            agg_func=None,
            tags='wrapper'
        ),
        first_price=dict(
            title='First Price',
            calc_func=<function OHLCVDFAccessor.<lambda> at 0x7ff338c2b250>,
            resolve_ohlc=True,
            tags=[
                'ohlcv',
                'ohlc'
            ]
        ),
        lowest_price=dict(
            title='Lowest Price',
            calc_func=<function OHLCVDFAccessor.<lambda> at 0x7ff338c2b2e0>,
            resolve_ohlc=True,
            tags=[
                'ohlcv',
                'ohlc'
            ]
        ),
        highest_price=dict(
            title='Highest Price',
            calc_func=<function OHLCVDFAccessor.<lambda> at 0x7ff338c2b370>,
            resolve_ohlc=True,
            tags=[
                'ohlcv',
                'ohlc'
            ]
        ),
        last_price=dict(
            title='Last Price',
            calc_func=<function OHLCVDFAccessor.<lambda> at 0x7ff338c2b400>,
            resolve_ohlc=True,
            tags=[
                'ohlcv',
                'ohlc'
            ]
        ),
        first_volume=dict(
            title='First Volume',
            calc_func=<function OHLCVDFAccessor.<lambda> at 0x7ff338c2b490>,
            resolve_volume=True,
            tags=[
                'ohlcv',
                'volume'
            ]
        ),
        lowest_volume=dict(
            title='Lowest Volume',
            calc_func=<function OHLCVDFAccessor.<lambda> at 0x7ff338c2b520>,
            resolve_volume=True,
            tags=[
                'ohlcv',
                'volume'
            ]
        ),
        highest_volume=dict(
            title='Highest Volume',
            calc_func=<function OHLCVDFAccessor.<lambda> at 0x7ff338c2b5b0>,
            resolve_volume=True,
            tags=[
                'ohlcv',
                'volume'
            ]
        ),
        last_volume=dict(
            title='Last Volume',
            calc_func=<function OHLCVDFAccessor.<lambda> at 0x7ff338c2b640>,
            resolve_volume=True,
            tags=[
                'ohlcv',
                'volume'
            ]
        )
    )

Returns `OHLCVDFAccessor._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 `OHLCVDFAccessor._metrics`.

### plot method

    OHLCVDFAccessor.plot(
        ohlc_type=None,
        plot_volume=None,
        ohlc_trace_kwargs=None,
        volume_trace_kwargs=None,
        add_trace_kwargs=None,
        volume_add_trace_kwargs=None,
        fig=None,
        **layout_kwargs
    )

Plot OHLC(V) data.

Args

`ohlc_type`

  Either 'OHLC', 'Candlestick' or Plotly trace.

  Pass None to use the default.

`plot_volume` :`bool`
  Whether to plot volume beneath.
`ohlc_trace_kwargs` :`dict`
  Keyword arguments passed to `ohlc_type`.
`volume_trace_kwargs` :`dict`
  Keyword arguments passed to `plotly.graph_objects.Bar`.
`add_trace_kwargs` :`dict`
  Keyword arguments passed to `add_trace` for OHLC.
`volume_add_trace_kwargs` :`dict`
  Keyword arguments passed to `add_trace` for volume.
`fig` :`Figure` or `FigureWidget`
  Figure to add traces to.
`**layout_kwargs`
  Keyword arguments for layout.

Usage

    >>> vbt.YFData.pull("BTC-USD").get().vbt.ohlcv.plot().show()

100%

### plot_ohlc method

    OHLCVDFAccessor.plot_ohlc(
        ohlc_type=None,
        trace_kwargs=None,
        add_trace_kwargs=None,
        fig=None,
        **layout_kwargs
    )

Plot OHLC data.

Args

`ohlc_type`

  Either 'OHLC', 'Candlestick' or Plotly trace.

  Pass None to use the default.

`trace_kwargs` :`dict`
  Keyword arguments passed to `ohlc_type`.
`add_trace_kwargs` :`dict`
  Keyword arguments passed to `add_trace`.
`fig` :`Figure` or `FigureWidget`
  Figure to add traces to.
`**layout_kwargs`
  Keyword arguments for layout.

### plot_volume method

    OHLCVDFAccessor.plot_volume(
        trace_kwargs=None,
        add_trace_kwargs=None,
        fig=None,
        **layout_kwargs
    )

Plot volume data.

Args

`trace_kwargs` :`dict`
  Keyword arguments passed to `plotly.graph_objects.Bar`.
`add_trace_kwargs` :`dict`
  Keyword arguments passed to `add_trace`.
`fig` :`Figure` or `FigureWidget`
  Figure to add traces to.
`**layout_kwargs`
  Keyword arguments for layout.

### plots_defaults property

Defaults for PlotsBuilderMixin.plots().

Merges GenericAccessor.plots_defaults and `plots` from ohlcv.

### resample method

    OHLCVDFAccessor.resample(
        *args,
        wrapper_meta=None,
        **kwargs
    )

Perform resampling on OHLCVDFAccessor.

### stats_defaults property

Defaults for StatsBuilderMixin.stats().

Merges GenericAccessor.stats_defaults and `stats` from ohlcv.

### subplots class variable

Subplots supported by OHLCVDFAccessor.

    HybridConfig(
        plot=dict(
            title='OHLC',
            xaxis_kwargs=dict(
                showgrid=True,
                rangeslider_visible=False
            ),
            yaxis_kwargs=dict(
                showgrid=True
            ),
            check_is_not_grouped=True,
            plot_func='plot',
            plot_volume=False,
            tags='ohlcv'
        )
    )

Returns `OHLCVDFAccessor._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 `OHLCVDFAccessor._subplots`.

#### Cookie consent

We use cookies to recognize your repeated visits and preferences, as well as to measure the effectiveness of our documentation and whether users find what they're searching for. With your consent, you're helping us to make our documentation better.

- Google Analytics
- GitHub

Manage settings