Documentation
Building blocks
Understand the core abstractions that support advanced workflows
In the following sections, we will explore some sub-packages, modules, and especially classes that
serve as building blocks for advanced functionalities in VBT, such as
Portfolio. To demonstrate this, we will
gradually build a custom class, CorrStats, which enables us to analyze the correlation between two
arrays in the most efficient and flexible way 🧠
Utilities
VBT uses a modular project structure composed of several subpackages. Each subpackage is designed for a specific area of analysis.
The utils subpackage provides a set of utilities that power every part of VBT ⚡
These utilities are loosely connected and offer small but powerful reusable code snippets that can
be used independently of other functionality.
The main reason we avoid importing third-party packages and instead implement many utilities from scratch is to maintain full control over execution and code quality.
Formatting
VBT includes its own formatting engine that can pretty-print any Python object.
It is much more advanced than formatting with JSON because it
recognizes native Python data types and adds intelligent formatting for more structured data types,
such as np.dtype and namedtuple. In many cases, you can even convert the formatted string back
into a Python object using eval.
Let's beautify a nested dictionary using prettify
and then convert the string back into an object:
from vectorbtpro import *
dct = {'planet' : {'has': {'plants': 'yes', 'animals': 'yes', 'cryptonite': 'no'}, 'name': 'Earth'}}
print(vbt.prettify(dct)){
'planet': {
'has': {
'plants': 'yes',
'animals': 'yes',
'cryptonite': 'no'
},
'name': 'Earth'
}
}eval(vbt.prettify(dct)) == dctTrueCurious why we used vbt.prettify instead of vbt.utils.formatting.prettify?
Any utility that may be useful to the end user can be accessed directly from vbt.
To see which utilities are accessible from the root of the package, visit
vectorbtpro/utils/__init__.py
or any other subpackage, and look for the objects that are listed in __all__.
The Prettified class implements the
abstract method Prettified.prettify,
which can be overridden by a subclass to pretty-print an instance using
prettify.
Read below to learn how this method can be used to introspect instances of various classes.
Pickling
Pickling is the process of converting a Python object into a byte stream to store it in a file or database.
The Pickleable class enables pickling
of objects of any complexity using Dill
(or pickle if Dill is not installed).
Each subclass inherits ready-to-use methods for serializing, deserializing, saving to a file,
and loading from a file. This is especially powerful because it allows us to persist
objects containing any type of data, including instances of Data
and Portfolio.
Configuring
VBT relies heavily on automation driven by specifications. The specification for most repetitive tasks is usually stored in "configs," which serve as settings for specific tasks, data structures, or even classes. This approach makes most parts of VBT transparent, easily traversable, and programmatically changeable.
The Config class is like a dictionary on steroids:
it extends Python's dict with various configuration features, such as frozen keys,
read-only values, dot notation access to keys, and nested updates. The most notable feature
is the ability to reset a config to its initial state and even create checkpoints, which is
especially useful for settings. In addition, since Config
inherits from Pickleable, we can save any
configuration to disk, and by subclassing Prettified
we can beautify it (this approach is used to generate the API reference):
print(vbt.Records.field_config)Config(
dtype=None,
settings={
'id': {
'name': 'id',
'title': 'Id'
},
'col': {
'name': 'col',
'title': 'Column',
'mapping': 'columns'
},
'idx': {
'name': 'idx',
'title': 'Timestamp',
'mapping': 'index'
}
}
)Configs are very common structures in VBT. There are three main types of configs (that either
subclass or partially use Config) used throughout VBT:
This section explores the sub-packages, modules, and core classes that serve as building blocks for advanced functionality throughout VBT.
It explains how these pieces fit together by gradually constructing a custom analysis class, covering the foundations needed to build efficient and flexible extensions of your own.
Copyright © 2021–2026 Oleg Polakow. All rights reserved.
Site content and documentation are provided for using and evaluating VectorBT PRO and for educational purposes. Any other use, including building or supporting competing products or services, requires prior written consent.