Skip to content

ols module

Module with OLS.


OLS class

OLS(
    wrapper,
    input_list,
    input_mapper,
    in_output_list,
    output_list,
    param_list,
    mapper_list,
    short_name,
    **kwargs
)

Rolling Ordinary Least Squares (OLS).

The indicator can be used to detect changes in the behavior of the stocks against the market or each other.

See The Linear Regression of Time and Price.

Superclasses

Inherited members

Subclasses

  • vectorbtpro.indicators.custom.ols._OLS

angle property

Custom property.


angle_above method

OLS.angle_above(
    other,
    level_name=None,
    allow_multiple=True,
    **kwargs
)

Return True for each element where angle is above other.

See combine_objs().


angle_below method

OLS.angle_below(
    other,
    level_name=None,
    allow_multiple=True,
    **kwargs
)

Return True for each element where angle is below other.

See combine_objs().


angle_crossed_above method

OLS.angle_crossed_above(
    other,
    level_name=None,
    allow_multiple=True,
    **kwargs
)

Return True for each element where angle is crossed_above other.

See combine_objs().


angle_crossed_below method

OLS.angle_crossed_below(
    other,
    level_name=None,
    allow_multiple=True,
    **kwargs
)

Return True for each element where angle is crossed_below other.

See combine_objs().


angle_equal method

OLS.angle_equal(
    other,
    level_name=None,
    allow_multiple=True,
    **kwargs
)

Return True for each element where angle is equal other.

See combine_objs().


angle_stats method

OLS.angle_stats(
    *args,
    **kwargs
)

Stats of angle as generic.


apply_func method

OLS.apply_func(
    x,
    y,
    window=14,
    minp=None,
    ddof=0,
    with_zscore=True
)

2-dim version of ols_1d_nb.


cache_func class variable


custom_func method

IndicatorFactory.with_apply_func.<locals>.custom_func(
    input_tuple,
    in_output_tuple,
    param_tuple,
    *_args,
    input_shape=None,
    per_column=False,
    split_columns=False,
    skipna=False,
    return_cache=False,
    use_cache=True,
    jitted_loop=False,
    jitted_warmup=False,
    param_index=None,
    final_index=None,
    single_comb=False,
    execute_kwargs=None,
    **_kwargs
)

Custom function that forwards inputs and parameters to apply_func.


error property

Custom property.


error_above method

OLS.error_above(
    other,
    level_name=None,
    allow_multiple=True,
    **kwargs
)

Return True for each element where error is above other.

See combine_objs().


error_below method

OLS.error_below(
    other,
    level_name=None,
    allow_multiple=True,
    **kwargs
)

Return True for each element where error is below other.

See combine_objs().


error_crossed_above method

OLS.error_crossed_above(
    other,
    level_name=None,
    allow_multiple=True,
    **kwargs
)

Return True for each element where error is crossed_above other.

See combine_objs().


error_crossed_below method

OLS.error_crossed_below(
    other,
    level_name=None,
    allow_multiple=True,
    **kwargs
)

Return True for each element where error is crossed_below other.

See combine_objs().


error_equal method

OLS.error_equal(
    other,
    level_name=None,
    allow_multiple=True,
    **kwargs
)

Return True for each element where error is equal other.

See combine_objs().


error_stats method

OLS.error_stats(
    *args,
    **kwargs
)

Stats of error as generic.


intercept property

Output array.


intercept_above method

OLS.intercept_above(
    other,
    level_name=None,
    allow_multiple=True,
    **kwargs
)

Return True for each element where intercept is above other.

See combine_objs().


intercept_below method

OLS.intercept_below(
    other,
    level_name=None,
    allow_multiple=True,
    **kwargs
)

Return True for each element where intercept is below other.

See combine_objs().


intercept_crossed_above method

OLS.intercept_crossed_above(
    other,
    level_name=None,
    allow_multiple=True,
    **kwargs
)

Return True for each element where intercept is crossed_above other.

See combine_objs().


intercept_crossed_below method

OLS.intercept_crossed_below(
    other,
    level_name=None,
    allow_multiple=True,
    **kwargs
)

Return True for each element where intercept is crossed_below other.

See combine_objs().


intercept_equal method

OLS.intercept_equal(
    other,
    level_name=None,
    allow_multiple=True,
    **kwargs
)

Return True for each element where intercept is equal other.

See combine_objs().


intercept_stats method

OLS.intercept_stats(
    *args,
    **kwargs
)

Stats of intercept as generic.


param_select_func_nb method

OLS.param_select_func_nb(
    i,
    args_before,
    x,
    y,
    window,
    *args
)

plot method

_OLS.plot(
    column=None,
    plot_y=True,
    y_trace_kwargs=None,
    pred_trace_kwargs=None,
    add_trace_kwargs=None,
    fig=None,
    **layout_kwargs
)

Plot OLS.pred against OLS.y.

Args

column : str
Name of the column to plot.
plot_y : bool
Whether to plot OLS.y.
y_trace_kwargs : dict
Keyword arguments passed to plotly.graph_objects.Scatter for OLS.y.
pred_trace_kwargs : dict
Keyword arguments passed to plotly.graph_objects.Scatter for OLS.pred.
add_trace_kwargs : dict
Keyword arguments passed to fig.add_trace when adding each trace.
fig : Figure or FigureWidget
Figure to add traces to.
**layout_kwargs
Keyword arguments passed to fig.update_layout.

Usage

>>> vbt.OLS.run(np.arange(len(ohlcv)), ohlcv['Close']).plot().show()


plot_zscore method

_OLS.plot_zscore(
    column=None,
    alpha=0.05,
    zscore_trace_kwargs=None,
    add_shape_kwargs=None,
    add_trace_kwargs=None,
    fig=None,
    **layout_kwargs
)

Plot OLS.zscore with confidence intervals.

Args

column : str
Name of the column to plot.
alpha : float

The alpha level for the confidence interval.

The default alpha = .05 returns a 95% confidence interval.

zscore_trace_kwargs : dict
Keyword arguments passed to plotly.graph_objects.Scatter for OLS.zscore.
add_shape_kwargs : dict
Keyword arguments passed to fig.add_shape when adding the range between both confidence intervals.
add_trace_kwargs : dict
Keyword arguments passed to fig.add_trace when adding each trace.
fig : Figure or FigureWidget
Figure to add traces to.
**layout_kwargs
Keyword arguments passed to fig.update_layout.

Usage

>>> vbt.OLS.run(np.arange(len(ohlcv)), ohlcv['Close']).plot_zscore().show()


pred property

Custom property.


pred_above method

OLS.pred_above(
    other,
    level_name=None,
    allow_multiple=True,
    **kwargs
)

Return True for each element where pred is above other.

See combine_objs().


pred_below method

OLS.pred_below(
    other,
    level_name=None,
    allow_multiple=True,
    **kwargs
)

Return True for each element where pred is below other.

See combine_objs().


pred_crossed_above method

OLS.pred_crossed_above(
    other,
    level_name=None,
    allow_multiple=True,
    **kwargs
)

Return True for each element where pred is crossed_above other.

See combine_objs().


pred_crossed_below method

OLS.pred_crossed_below(
    other,
    level_name=None,
    allow_multiple=True,
    **kwargs
)

Return True for each element where pred is crossed_below other.

See combine_objs().


pred_equal method

OLS.pred_equal(
    other,
    level_name=None,
    allow_multiple=True,
    **kwargs
)

Return True for each element where pred is equal other.

See combine_objs().


pred_stats method

OLS.pred_stats(
    *args,
    **kwargs
)

Stats of pred as generic.


run class method

OLS.run(
    x,
    y,
    window=Default(value=14),
    short_name='ols',
    hide_params=None,
    hide_default=True,
    **kwargs
)

Run OLS indicator.

  • Inputs: x, y
  • Parameters: window
  • Outputs: slope, intercept, zscore
  • Lazy outputs: pred, error, angle

Pass a list of parameter names as hide_params to hide their column levels, or True to hide all. Set hide_default to False to show the column levels of the parameters with a default value.

Other keyword arguments are passed to IndicatorBase.run_pipeline().


run_combs class method

OLS.run_combs(
    x,
    y,
    window=Default(value=14),
    r=2,
    param_product=False,
    comb_func=itertools.combinations,
    run_unique=True,
    short_names=None,
    hide_params=None,
    hide_default=True,
    **kwargs
)

Create a combination of multiple OLS indicators using function comb_func.

  • Inputs: x, y
  • Parameters: window
  • Outputs: slope, intercept, zscore
  • Lazy outputs: pred, error, angle

comb_func must accept an iterable of parameter tuples and r. Also accepts all combinatoric iterators from itertools such as itertools.combinations. Pass r to specify how many indicators to run. Pass short_names to specify the short name for each indicator. Set run_unique to True to first compute raw outputs for all parameters, and then use them to build each indicator (faster).

Other keyword arguments are passed to OLS.run().

Note

This method should only be used when multiple indicators are needed. To test multiple parameters, pass them as lists to OLS.run().


slope property

Output array.


slope_above method

OLS.slope_above(
    other,
    level_name=None,
    allow_multiple=True,
    **kwargs
)

Return True for each element where slope is above other.

See combine_objs().


slope_below method

OLS.slope_below(
    other,
    level_name=None,
    allow_multiple=True,
    **kwargs
)

Return True for each element where slope is below other.

See combine_objs().


slope_crossed_above method

OLS.slope_crossed_above(
    other,
    level_name=None,
    allow_multiple=True,
    **kwargs
)

Return True for each element where slope is crossed_above other.

See combine_objs().


slope_crossed_below method

OLS.slope_crossed_below(
    other,
    level_name=None,
    allow_multiple=True,
    **kwargs
)

Return True for each element where slope is crossed_below other.

See combine_objs().


slope_equal method

OLS.slope_equal(
    other,
    level_name=None,
    allow_multiple=True,
    **kwargs
)

Return True for each element where slope is equal other.

See combine_objs().


slope_stats method

OLS.slope_stats(
    *args,
    **kwargs
)

Stats of slope as generic.


window_list property

List of window values.


x property

Input array.


x_above method

OLS.x_above(
    other,
    level_name=None,
    allow_multiple=True,
    **kwargs
)

Return True for each element where x is above other.

See combine_objs().


x_below method

OLS.x_below(
    other,
    level_name=None,
    allow_multiple=True,
    **kwargs
)

Return True for each element where x is below other.

See combine_objs().


x_crossed_above method

OLS.x_crossed_above(
    other,
    level_name=None,
    allow_multiple=True,
    **kwargs
)

Return True for each element where x is crossed_above other.

See combine_objs().


x_crossed_below method

OLS.x_crossed_below(
    other,
    level_name=None,
    allow_multiple=True,
    **kwargs
)

Return True for each element where x is crossed_below other.

See combine_objs().


x_equal method

OLS.x_equal(
    other,
    level_name=None,
    allow_multiple=True,
    **kwargs
)

Return True for each element where x is equal other.

See combine_objs().


x_stats method

OLS.x_stats(
    *args,
    **kwargs
)

Stats of x as generic.


y property

Input array.


y_above method

OLS.y_above(
    other,
    level_name=None,
    allow_multiple=True,
    **kwargs
)

Return True for each element where y is above other.

See combine_objs().


y_below method

OLS.y_below(
    other,
    level_name=None,
    allow_multiple=True,
    **kwargs
)

Return True for each element where y is below other.

See combine_objs().


y_crossed_above method

OLS.y_crossed_above(
    other,
    level_name=None,
    allow_multiple=True,
    **kwargs
)

Return True for each element where y is crossed_above other.

See combine_objs().


y_crossed_below method

OLS.y_crossed_below(
    other,
    level_name=None,
    allow_multiple=True,
    **kwargs
)

Return True for each element where y is crossed_below other.

See combine_objs().


y_equal method

OLS.y_equal(
    other,
    level_name=None,
    allow_multiple=True,
    **kwargs
)

Return True for each element where y is equal other.

See combine_objs().


y_stats method

OLS.y_stats(
    *args,
    **kwargs
)

Stats of y as generic.


zscore property

Output array.


zscore_above method

OLS.zscore_above(
    other,
    level_name=None,
    allow_multiple=True,
    **kwargs
)

Return True for each element where zscore is above other.

See combine_objs().


zscore_below method

OLS.zscore_below(
    other,
    level_name=None,
    allow_multiple=True,
    **kwargs
)

Return True for each element where zscore is below other.

See combine_objs().


zscore_crossed_above method

OLS.zscore_crossed_above(
    other,
    level_name=None,
    allow_multiple=True,
    **kwargs
)

Return True for each element where zscore is crossed_above other.

See combine_objs().


zscore_crossed_below method

OLS.zscore_crossed_below(
    other,
    level_name=None,
    allow_multiple=True,
    **kwargs
)

Return True for each element where zscore is crossed_below other.

See combine_objs().


zscore_equal method

OLS.zscore_equal(
    other,
    level_name=None,
    allow_multiple=True,
    **kwargs
)

Return True for each element where zscore is equal other.

See combine_objs().


zscore_stats method

OLS.zscore_stats(
    *args,
    **kwargs
)

Stats of zscore as generic.