Skip to content

accessors module

Custom Pandas accessors for OHLC(V) data.

Methods can be accessed as follows:

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

>>> 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

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

Inherited members


feature_map property

Column names.


metrics class variable

Metrics supported by OHLCVDFAccessor.

HybridConfig(
    start_index=dict(
        title='Start Index',
        calc_func=<function OHLCVDFAccessor.<lambda> at 0x16438f880>,
        agg_func=None,
        tags='wrapper'
    ),
    end_index=dict(
        title='End Index',
        calc_func=<function OHLCVDFAccessor.<lambda> at 0x16438f920>,
        agg_func=None,
        tags='wrapper'
    ),
    total_duration=dict(
        title='Total Duration',
        calc_func=<function OHLCVDFAccessor.<lambda> at 0x16438f9c0>,
        apply_to_timedelta=True,
        agg_func=None,
        tags='wrapper'
    ),
    first_price=dict(
        title='First Price',
        calc_func=<function OHLCVDFAccessor.<lambda> at 0x16438fa60>,
        resolve_ohlc=True,
        tags=[
            'ohlcv',
            'ohlc'
        ]
    ),
    lowest_price=dict(
        title='Lowest Price',
        calc_func=<function OHLCVDFAccessor.<lambda> at 0x16438fb00>,
        resolve_ohlc=True,
        tags=[
            'ohlcv',
            'ohlc'
        ]
    ),
    highest_price=dict(
        title='Highest Price',
        calc_func=<function OHLCVDFAccessor.<lambda> at 0x16438fba0>,
        resolve_ohlc=True,
        tags=[
            'ohlcv',
            'ohlc'
        ]
    ),
    last_price=dict(
        title='Last Price',
        calc_func=<function OHLCVDFAccessor.<lambda> at 0x16438fc40>,
        resolve_ohlc=True,
        tags=[
            'ohlcv',
            'ohlc'
        ]
    ),
    first_volume=dict(
        title='First Volume',
        calc_func=<function OHLCVDFAccessor.<lambda> at 0x16438fce0>,
        resolve_volume=True,
        tags=[
            'ohlcv',
            'volume'
        ]
    ),
    lowest_volume=dict(
        title='Lowest Volume',
        calc_func=<function OHLCVDFAccessor.<lambda> at 0x16438fd80>,
        resolve_volume=True,
        tags=[
            'ohlcv',
            'volume'
        ]
    ),
    highest_volume=dict(
        title='Highest Volume',
        calc_func=<function OHLCVDFAccessor.<lambda> at 0x16438fe20>,
        resolve_volume=True,
        tags=[
            'ohlcv',
            'volume'
        ]
    ),
    last_volume=dict(
        title='Last Volume',
        calc_func=<function OHLCVDFAccessor.<lambda> at 0x16438fec0>,
        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.