Skip to content

logs module

Base class for working with log records.

Order records capture information on simulation logs. Logs are populated when simulating a portfolio and can be accessed as Portfolio.logs.

>>> from vectorbtpro import *

>>> np.random.seed(42)
>>> price = pd.DataFrame({
...     'a': np.random.uniform(1, 2, size=100),
...     'b': np.random.uniform(1, 2, size=100)
... }, index=[datetime(2020, 1, 1) + timedelta(days=i) for i in range(100)])
>>> size = pd.DataFrame({
...     'a': np.random.uniform(-100, 100, size=100),
...     'b': np.random.uniform(-100, 100, size=100),
... }, index=[datetime(2020, 1, 1) + timedelta(days=i) for i in range(100)])
>>> pf = vbt.Portfolio.from_orders(price, size, fees=0.01, freq='d', log=True)
>>> logs = pf.logs

>>> logs.filled.count()
a    88
b    99
Name: count, dtype: int64

>>> logs.ignored.count()
a    0
b    0
Name: count, dtype: int64

>>> logs.rejected.count()
a    12
b     1
Name: count, dtype: int64

Stats

>>> logs['a'].stats()
Start                             2020-01-01 00:00:00
End                               2020-04-09 00:00:00
Period                              100 days 00:00:00
Total Records                                     100
Status Counts: None                                 0
Status Counts: Filled                              88
Status Counts: Ignored                              0
Status Counts: Rejected                            12
Status Info Counts: None                           88
Status Info Counts: NoCashLong                     12
Name: a, dtype: object

StatsBuilderMixin.stats also supports (re-)grouping:

>>> logs.stats(group_by=True)
Start                             2020-01-01 00:00:00
End                               2020-04-09 00:00:00
Period                              100 days 00:00:00
Total Records                                     200
Status Counts: None                                 0
Status Counts: Filled                             187
Status Counts: Ignored                              0
Status Counts: Rejected                            13
Status Info Counts: None                          187
Status Info Counts: NoCashLong                     13
Name: group, dtype: object

Plots

This class does not have any subplots.


logs_attach_field_config ReadonlyConfig

Config of fields to be attached to Logs.

ReadonlyConfig(
    res_side=dict(
        attach_filters=True
    ),
    res_status=dict(
        attach_filters=True
    ),
    res_status_info=dict(
        attach_filters=True
    )
)

logs_field_config ReadonlyConfig

Field config for Logs.

ReadonlyConfig(
    dtype=np.dtype([
        ('id', 'int64'),
        ('group', 'int64'),
        ('col', 'int64'),
        ('idx', 'int64'),
        ('price_area_open', 'float64'),
        ('price_area_high', 'float64'),
        ('price_area_low', 'float64'),
        ('price_area_close', 'float64'),
        ('st0_cash', 'float64'),
        ('st0_position', 'float64'),
        ('st0_debt', 'float64'),
        ('st0_locked_cash', 'float64'),
        ('st0_free_cash', 'float64'),
        ('st0_val_price', 'float64'),
        ('st0_value', 'float64'),
        ('req_size', 'float64'),
        ('req_price', 'float64'),
        ('req_size_type', 'int64'),
        ('req_direction', 'int64'),
        ('req_fees', 'float64'),
        ('req_fixed_fees', 'float64'),
        ('req_slippage', 'float64'),
        ('req_min_size', 'float64'),
        ('req_max_size', 'float64'),
        ('req_size_granularity', 'float64'),
        ('req_leverage', 'float64'),
        ('req_leverage_mode', 'int64'),
        ('req_reject_prob', 'float64'),
        ('req_price_area_vio_mode', 'int64'),
        ('req_allow_partial', 'bool'),
        ('req_raise_reject', 'bool'),
        ('req_log', 'bool'),
        ('res_size', 'float64'),
        ('res_price', 'float64'),
        ('res_fees', 'float64'),
        ('res_side', 'int64'),
        ('res_status', 'int64'),
        ('res_status_info', 'int64'),
        ('st1_cash', 'float64'),
        ('st1_position', 'float64'),
        ('st1_debt', 'float64'),
        ('st1_locked_cash', 'float64'),
        ('st1_free_cash', 'float64'),
        ('st1_val_price', 'float64'),
        ('st1_value', 'float64'),
        ('order_id', 'int64')
    ]),
    settings=dict(
        id=dict(
            title='Log Id'
        ),
        col=dict(
            title='Column'
        ),
        idx=dict(
            title='Index'
        ),
        group=dict(
            title='Group'
        ),
        price_area_open=dict(
            title='[PA] Open'
        ),
        price_area_high=dict(
            title='[PA] High'
        ),
        price_area_low=dict(
            title='[PA] Low'
        ),
        price_area_close=dict(
            title='[PA] Close'
        ),
        st0_cash=dict(
            title='[ST0] Cash'
        ),
        st0_position=dict(
            title='[ST0] Position'
        ),
        st0_debt=dict(
            title='[ST0] Debt'
        ),
        st0_locked_cash=dict(
            title='[ST0] Locked Cash'
        ),
        st0_free_cash=dict(
            title='[ST0] Free Cash'
        ),
        st0_val_price=dict(
            title='[ST0] Valuation Price'
        ),
        st0_value=dict(
            title='[ST0] Value'
        ),
        req_size=dict(
            title='[REQ] Size'
        ),
        req_price=dict(
            title='[REQ] Price'
        ),
        req_size_type=dict(
            title='[REQ] Size Type',
            mapping=SizeTypeT(
                Amount=0,
                Value=1,
                Percent=2,
                Percent100=3,
                ValuePercent=4,
                ValuePercent100=5,
                TargetAmount=6,
                TargetValue=7,
                TargetPercent=8,
                TargetPercent100=9
            )
        ),
        req_direction=dict(
            title='[REQ] Direction',
            mapping=DirectionT(
                LongOnly=0,
                ShortOnly=1,
                Both=2
            )
        ),
        req_fees=dict(
            title='[REQ] Fees'
        ),
        req_fixed_fees=dict(
            title='[REQ] Fixed Fees'
        ),
        req_slippage=dict(
            title='[REQ] Slippage'
        ),
        req_min_size=dict(
            title='[REQ] Min Size'
        ),
        req_max_size=dict(
            title='[REQ] Max Size'
        ),
        req_size_granularity=dict(
            title='[REQ] Size Granularity'
        ),
        req_leverage=dict(
            title='[REQ] Leverage'
        ),
        req_leverage_mode=dict(
            title='[REQ] Leverage Mode',
            mapping=LeverageModeT(
                Lazy=0,
                Eager=1
            )
        ),
        req_reject_prob=dict(
            title='[REQ] Rejection Prob'
        ),
        req_price_area_vio_mode=dict(
            title='[REQ] Price Area Violation Mode',
            mapping=PriceAreaVioModeT(
                Ignore=0,
                Cap=1,
                Error=2
            )
        ),
        req_allow_partial=dict(
            title='[REQ] Allow Partial'
        ),
        req_raise_reject=dict(
            title='[REQ] Raise Rejection'
        ),
        req_log=dict(
            title='[REQ] Log'
        ),
        res_size=dict(
            title='[RES] Size'
        ),
        res_price=dict(
            title='[RES] Price'
        ),
        res_fees=dict(
            title='[RES] Fees'
        ),
        res_side=dict(
            title='[RES] Side',
            mapping=OrderSideT(
                Buy=0,
                Sell=1
            )
        ),
        res_status=dict(
            title='[RES] Status',
            mapping=OrderStatusT(
                Filled=0,
                Ignored=1,
                Rejected=2
            )
        ),
        res_status_info=dict(
            title='[RES] Status Info',
            mapping=OrderStatusInfoT(
                SizeNaN=0,
                PriceNaN=1,
                ValPriceNaN=2,
                ValueNaN=3,
                ValueZeroNeg=4,
                SizeZero=5,
                NoCash=6,
                NoOpenPosition=7,
                MaxSizeExceeded=8,
                RandomEvent=9,
                CantCoverFees=10,
                MinSizeNotReached=11,
                PartialFill=12
            )
        ),
        st1_cash=dict(
            title='[ST1] Cash'
        ),
        st1_position=dict(
            title='[ST1] Position'
        ),
        st1_debt=dict(
            title='[ST1] Debt'
        ),
        st1_locked_cash=dict(
            title='[ST1] Locked Cash'
        ),
        st1_free_cash=dict(
            title='[ST1] Free Cash'
        ),
        st1_val_price=dict(
            title='[ST1] Valuation Price'
        ),
        st1_value=dict(
            title='[ST1] Value'
        ),
        order_id=dict(
            title='Order Id',
            mapping='ids'
        )
    )
)

Logs class

Logs(
    wrapper,
    records_arr,
    open=None,
    high=None,
    low=None,
    close=None,
    **kwargs
)

Extends PriceRecords for working with log records.

Superclasses

Inherited members


col cached_property

Mapped array of the field col.


field_config property

Field config of Logs.

HybridConfig(
    dtype=np.dtype([
        ('id', 'int64'),
        ('group', 'int64'),
        ('col', 'int64'),
        ('idx', 'int64'),
        ('price_area_open', 'float64'),
        ('price_area_high', 'float64'),
        ('price_area_low', 'float64'),
        ('price_area_close', 'float64'),
        ('st0_cash', 'float64'),
        ('st0_position', 'float64'),
        ('st0_debt', 'float64'),
        ('st0_locked_cash', 'float64'),
        ('st0_free_cash', 'float64'),
        ('st0_val_price', 'float64'),
        ('st0_value', 'float64'),
        ('req_size', 'float64'),
        ('req_price', 'float64'),
        ('req_size_type', 'int64'),
        ('req_direction', 'int64'),
        ('req_fees', 'float64'),
        ('req_fixed_fees', 'float64'),
        ('req_slippage', 'float64'),
        ('req_min_size', 'float64'),
        ('req_max_size', 'float64'),
        ('req_size_granularity', 'float64'),
        ('req_leverage', 'float64'),
        ('req_leverage_mode', 'int64'),
        ('req_reject_prob', 'float64'),
        ('req_price_area_vio_mode', 'int64'),
        ('req_allow_partial', 'bool'),
        ('req_raise_reject', 'bool'),
        ('req_log', 'bool'),
        ('res_size', 'float64'),
        ('res_price', 'float64'),
        ('res_fees', 'float64'),
        ('res_side', 'int64'),
        ('res_status', 'int64'),
        ('res_status_info', 'int64'),
        ('st1_cash', 'float64'),
        ('st1_position', 'float64'),
        ('st1_debt', 'float64'),
        ('st1_locked_cash', 'float64'),
        ('st1_free_cash', 'float64'),
        ('st1_val_price', 'float64'),
        ('st1_value', 'float64'),
        ('order_id', 'int64')
    ]),
    settings=dict(
        id=dict(
            name='id',
            title='Log Id',
            mapping='ids'
        ),
        col=dict(
            name='col',
            title='Column',
            mapping='columns',
            as_customdata=False
        ),
        idx=dict(
            name='idx',
            title='Index',
            mapping='index'
        ),
        group=dict(
            title='Group'
        ),
        price_area_open=dict(
            title='[PA] Open'
        ),
        price_area_high=dict(
            title='[PA] High'
        ),
        price_area_low=dict(
            title='[PA] Low'
        ),
        price_area_close=dict(
            title='[PA] Close'
        ),
        st0_cash=dict(
            title='[ST0] Cash'
        ),
        st0_position=dict(
            title='[ST0] Position'
        ),
        st0_debt=dict(
            title='[ST0] Debt'
        ),
        st0_locked_cash=dict(
            title='[ST0] Locked Cash'
        ),
        st0_free_cash=dict(
            title='[ST0] Free Cash'
        ),
        st0_val_price=dict(
            title='[ST0] Valuation Price'
        ),
        st0_value=dict(
            title='[ST0] Value'
        ),
        req_size=dict(
            title='[REQ] Size'
        ),
        req_price=dict(
            title='[REQ] Price'
        ),
        req_size_type=dict(
            title='[REQ] Size Type',
            mapping=SizeTypeT(
                Amount=0,
                Value=1,
                Percent=2,
                Percent100=3,
                ValuePercent=4,
                ValuePercent100=5,
                TargetAmount=6,
                TargetValue=7,
                TargetPercent=8,
                TargetPercent100=9
            )
        ),
        req_direction=dict(
            title='[REQ] Direction',
            mapping=DirectionT(
                LongOnly=0,
                ShortOnly=1,
                Both=2
            )
        ),
        req_fees=dict(
            title='[REQ] Fees'
        ),
        req_fixed_fees=dict(
            title='[REQ] Fixed Fees'
        ),
        req_slippage=dict(
            title='[REQ] Slippage'
        ),
        req_min_size=dict(
            title='[REQ] Min Size'
        ),
        req_max_size=dict(
            title='[REQ] Max Size'
        ),
        req_size_granularity=dict(
            title='[REQ] Size Granularity'
        ),
        req_leverage=dict(
            title='[REQ] Leverage'
        ),
        req_leverage_mode=dict(
            title='[REQ] Leverage Mode',
            mapping=LeverageModeT(
                Lazy=0,
                Eager=1
            )
        ),
        req_reject_prob=dict(
            title='[REQ] Rejection Prob'
        ),
        req_price_area_vio_mode=dict(
            title='[REQ] Price Area Violation Mode',
            mapping=PriceAreaVioModeT(
                Ignore=0,
                Cap=1,
                Error=2
            )
        ),
        req_allow_partial=dict(
            title='[REQ] Allow Partial'
        ),
        req_raise_reject=dict(
            title='[REQ] Raise Rejection'
        ),
        req_log=dict(
            title='[REQ] Log'
        ),
        res_size=dict(
            title='[RES] Size'
        ),
        res_price=dict(
            title='[RES] Price'
        ),
        res_fees=dict(
            title='[RES] Fees'
        ),
        res_side=dict(
            title='[RES] Side',
            mapping=OrderSideT(
                Buy=0,
                Sell=1
            )
        ),
        res_status=dict(
            title='[RES] Status',
            mapping=OrderStatusT(
                Filled=0,
                Ignored=1,
                Rejected=2
            )
        ),
        res_status_info=dict(
            title='[RES] Status Info',
            mapping=OrderStatusInfoT(
                SizeNaN=0,
                PriceNaN=1,
                ValPriceNaN=2,
                ValueNaN=3,
                ValueZeroNeg=4,
                SizeZero=5,
                NoCash=6,
                NoOpenPosition=7,
                MaxSizeExceeded=8,
                RandomEvent=9,
                CantCoverFees=10,
                MinSizeNotReached=11,
                PartialFill=12
            )
        ),
        st1_cash=dict(
            title='[ST1] Cash'
        ),
        st1_position=dict(
            title='[ST1] Position'
        ),
        st1_debt=dict(
            title='[ST1] Debt'
        ),
        st1_locked_cash=dict(
            title='[ST1] Locked Cash'
        ),
        st1_free_cash=dict(
            title='[ST1] Free Cash'
        ),
        st1_val_price=dict(
            title='[ST1] Valuation Price'
        ),
        st1_value=dict(
            title='[ST1] Value'
        ),
        order_id=dict(
            title='Order Id',
            mapping='ids'
        )
    )
)

Returns Logs._field_config, which gets (hybrid-) copied upon creation of each instance. Thus, changing this config won't affect the class.

To change fields, you can either change the config in-place, override this property, or overwrite the instance variable Logs._field_config.


group cached_property

Mapped array of the field group.


id cached_property

Mapped array of the field id.


idx cached_property

Mapped array of the field idx.


metrics property

Metrics supported by Logs.

HybridConfig(
    start_index=dict(
        title='Start Index',
        calc_func=<function Logs.<lambda> at 0x172511260>,
        agg_func=None,
        tags='wrapper'
    ),
    end_index=dict(
        title='End Index',
        calc_func=<function Logs.<lambda> at 0x172511300>,
        agg_func=None,
        tags='wrapper'
    ),
    total_duration=dict(
        title='Total Duration',
        calc_func=<function Logs.<lambda> at 0x1725113a0>,
        apply_to_timedelta=True,
        agg_func=None,
        tags='wrapper'
    ),
    total_records=dict(
        title='Total Records',
        calc_func='count',
        tags='records'
    ),
    res_status_counts=dict(
        title='Status Counts',
        calc_func='res_status.value_counts',
        incl_all_keys=True,
        post_calc_func=<function Logs.<lambda> at 0x172511440>,
        tags=[
            'logs',
            'res_status',
            'value_counts'
        ]
    ),
    res_status_info_counts=dict(
        title='Status Info Counts',
        calc_func='res_status_info.value_counts',
        post_calc_func=<function Logs.<lambda> at 0x1725114e0>,
        tags=[
            'logs',
            'res_status_info',
            'value_counts'
        ]
    )
)

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


order_id cached_property

Mapped array of the field order_id.


plots_defaults class property

Defaults for PlotsBuilderMixin.plots.

Merges PriceRecords.plots_defaults and plots from logs.


price_area_close cached_property

Mapped array of the field price_area_close.


price_area_high cached_property

Mapped array of the field price_area_high.


price_area_low cached_property

Mapped array of the field price_area_low.


price_area_open cached_property

Mapped array of the field price_area_open.


req_allow_partial cached_property

Mapped array of the field req_allow_partial.


req_direction cached_property

Mapped array of the field req_direction.


req_fees cached_property

Mapped array of the field req_fees.


req_fixed_fees cached_property

Mapped array of the field req_fixed_fees.


req_leverage cached_property

Mapped array of the field req_leverage.


req_leverage_mode cached_property

Mapped array of the field req_leverage_mode.


req_log cached_property

Mapped array of the field req_log.


req_max_size cached_property

Mapped array of the field req_max_size.


req_min_size cached_property

Mapped array of the field req_min_size.


req_price cached_property

Mapped array of the field req_price.


req_price_area_vio_mode cached_property

Mapped array of the field req_price_area_vio_mode.


req_raise_reject cached_property

Mapped array of the field req_raise_reject.


req_reject_prob cached_property

Mapped array of the field req_reject_prob.


req_size cached_property

Mapped array of the field req_size.


req_size_granularity cached_property

Mapped array of the field req_size_granularity.


req_size_type cached_property

Mapped array of the field req_size_type.


req_slippage cached_property

Mapped array of the field req_slippage.


res_fees cached_property

Mapped array of the field res_fees.


res_price cached_property

Mapped array of the field res_price.


res_side cached_property

Mapped array of the field res_side.


res_side_buy cached_property

Records filtered by res_side == 0.


res_side_sell cached_property

Records filtered by res_side == 1.


res_size cached_property

Mapped array of the field res_size.


res_status cached_property

Mapped array of the field res_status.


res_status_filled cached_property

Records filtered by res_status == 0.


res_status_ignored cached_property

Records filtered by res_status == 1.


res_status_info cached_property

Mapped array of the field res_status_info.


res_status_info_cant_cover_fees cached_property

Records filtered by res_status_info == 10.


res_status_info_max_size_exceeded cached_property

Records filtered by res_status_info == 8.


res_status_info_min_size_not_reached cached_property

Records filtered by res_status_info == 11.


res_status_info_no_cash cached_property

Records filtered by res_status_info == 6.


res_status_info_no_open_position cached_property

Records filtered by res_status_info == 7.


res_status_info_partial_fill cached_property

Records filtered by res_status_info == 12.


res_status_info_price_nan cached_property

Records filtered by res_status_info == 1.


res_status_info_random_event cached_property

Records filtered by res_status_info == 9.


res_status_info_size_nan cached_property

Records filtered by res_status_info == 0.


res_status_info_size_zero cached_property

Records filtered by res_status_info == 5.


res_status_info_val_price_nan cached_property

Records filtered by res_status_info == 2.


res_status_info_value_nan cached_property

Records filtered by res_status_info == 3.


res_status_info_value_zero_neg cached_property

Records filtered by res_status_info == 4.


res_status_rejected cached_property

Records filtered by res_status == 2.


st0_cash cached_property

Mapped array of the field st0_cash.


st0_debt cached_property

Mapped array of the field st0_debt.


st0_free_cash cached_property

Mapped array of the field st0_free_cash.


st0_locked_cash cached_property

Mapped array of the field st0_locked_cash.


st0_position cached_property

Mapped array of the field st0_position.


st0_val_price cached_property

Mapped array of the field st0_val_price.


st0_value cached_property

Mapped array of the field st0_value.


st1_cash cached_property

Mapped array of the field st1_cash.


st1_debt cached_property

Mapped array of the field st1_debt.


st1_free_cash cached_property

Mapped array of the field st1_free_cash.


st1_locked_cash cached_property

Mapped array of the field st1_locked_cash.


st1_position cached_property

Mapped array of the field st1_position.


st1_val_price cached_property

Mapped array of the field st1_val_price.


st1_value cached_property

Mapped array of the field st1_value.


stats_defaults class property

Defaults for StatsBuilderMixin.stats.

Merges PriceRecords.stats_defaults and stats from logs.


subplots property

Subplots supported by Logs.

HybridConfig()

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