records module¶
Generic Numba-compiled functions for records.
bar_price_nb function¶
Return the bar price.
dd_decline_duration_nb function¶
Compute the duration of the peak-to-valley phase of each drawdown record.
dd_drawdown_nb function¶
Compute the drawdown of each drawdown record.
dd_recovery_duration_nb function¶
Compute the duration of the valley-to-recovery phase of each drawdown record.
dd_recovery_duration_ratio_nb function¶
Compute the ratio of the recovery duration to the decline duration of each drawdown record.
dd_recovery_return_nb function¶
Compute the recovery return of each drawdown record.
drawdown_1d_nb function¶
Compute drawdown.
drawdown_nb function¶
2-dim version of drawdown_1d_nb().
fill_drawdown_record_nb function¶
fill_drawdown_record_nb(
new_records,
counts,
i,
col,
start_idx,
valley_idx,
start_val,
valley_val,
end_val,
status
)
Fill a drawdown record.
find_pattern_1d_nb function¶
find_pattern_1d_nb(
arr,
pattern,
window=None,
max_window=None,
row_select_prob=1.0,
window_select_prob=1.0,
roll_forward=False,
interp_mode=3,
rescale_mode=0,
vmin=nan,
vmax=nan,
pmin=nan,
pmax=nan,
invert=False,
error_type=0,
distance_measure=0,
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=0.85,
minp=None,
overlap_mode=0,
max_records=None,
col=0
)
Find all occurrences of a pattern in an array.
Uses pattern_similarity_nb() to fill records of the type pattern_range_dt.
Goes through the array, and for each window selected between window and max_window (including), checks whether the window of array values is similar enough to the pattern. If so, writes a new range to the output array. If window_select_prob is set, decides whether to test a window based on the given probability. The same for row_select_prob but on rows.
If roll_forward, windows are rolled forward (start_idx is guaranteed to be sorted), otherwise backward (end_idx is guaranteed to be sorted).
By default, creates an empty record array of the same size as the number of rows in arr. This can be increased or decreased using max_records.
find_pattern_nb function¶
find_pattern_nb(
arr,
pattern,
window=None,
max_window=None,
row_select_prob=1.0,
window_select_prob=1.0,
roll_forward=False,
interp_mode=3,
rescale_mode=0,
vmin=nan,
vmax=nan,
pmin=nan,
pmax=nan,
invert=False,
error_type=0,
distance_measure=0,
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=0.85,
minp=None,
overlap_mode=0,
max_records=None
)
2-dim version of find_pattern_1d_nb().
get_drawdowns_nb function¶
Fill drawdown records by analyzing a time series.
Only close must be provided, other time series are optional.
Usage
>>> from vectorbtpro import *
>>> close = np.array([
... [1, 5, 1, 3],
... [2, 4, 2, 2],
... [3, 3, 3, 1],
... [4, 2, 2, 2],
... [5, 1, 1, 3]
... ])
>>> records = vbt.nb.get_drawdowns_nb(None, None, None, close)
>>> pd.DataFrame.from_records(records)
id col start_idx valley_idx end_idx start_val valley_val end_val \
0 0 1 0 4 4 5.0 1.0 1.0
1 0 2 2 4 4 3.0 1.0 1.0
2 0 3 0 2 4 3.0 1.0 3.0
status
0 0
1 0
2 1
get_ranges_from_delta_nb function¶
get_ranges_from_delta_nb(
n_rows,
idx_arr,
id_arr,
col_map,
index=None,
delta=0,
delta_use_index=False,
shift=0
)
Build delta ranges.
get_ranges_nb function¶
Fill range records between gaps.
Usage
- Find ranges in time series:
>>> from vectorbtpro import *
>>> a = np.array([
... [np.nan, np.nan, np.nan, np.nan],
... [ 2, np.nan, np.nan, np.nan],
... [ 3, 3, np.nan, np.nan],
... [np.nan, 4, 4, np.nan],
... [ 5, np.nan, 5, 5],
... [ 6, 6, np.nan, 6]
... ])
>>> records = vbt.nb.get_ranges_nb(a, np.nan)
>>> pd.DataFrame.from_records(records)
id col start_idx end_idx status
0 0 0 1 3 1
1 1 0 4 5 0
2 0 1 2 4 1
3 1 1 5 5 0
4 0 2 3 5 1
5 0 3 4 5 0
map_ranges_to_projections_nb function¶
map_ranges_to_projections_nb(
close,
col_arr,
start_idx_arr,
end_idx_arr,
status_arr,
index=None,
proj_start=0,
proj_start_use_index=False,
proj_period=None,
proj_period_use_index=False,
incl_end_idx=True,
extend=False,
rebase=True,
start_value=1.0,
ffill=False,
remove_empty=False
)
Map each range into a projection.
Returns two arrays:
- One-dimensional array where elements are record indices
- Two-dimensional array where rows are projections
range_coverage_nb function¶
range_coverage_nb(
start_idx_arr,
end_idx_arr,
status_arr,
col_map,
index_lens,
overlapping=False,
normalize=False
)
Get coverage of range records.
Set overlapping to True to get the number of overlapping steps. Set normalize to True to get the number of steps in relation either to the total number of steps (when overlapping=False) or to the number of covered steps (when overlapping=True).
range_duration_nb function¶
Get duration of each range record.
ranges_to_mask_nb function¶
Convert ranges to 2-dim mask.