Skip to content
New: Star-import, signal unraveling, Python 3.12 support, and more

#
nb module

Numba-compiled functions for returns.

Provides an arsenal of Numba-compiled functions that are used by accessors and for measuring portfolio performance. These only accept NumPy arrays and other Numba-compatible types.

Note

vectorbt treats matrices as first-class citizens and expects input arrays to be 2-dim, unless function has suffix `_1d` or is meant to be input to another function. Data is processed along index (axis 0).

All functions passed as argument must be Numba-compiled.

## alpha_1d_nb function

    alpha_1d_nb(
        adj_rets,
        adj_bm_returns,
        ann_factor
    )

Annualized alpha.

## alpha_nb function

    alpha_nb(
        adj_rets,
        adj_bm_returns,
        ann_factor
    )

2-dim version of alpha_1d_nb().

## alpha_rollmeta_nb function

    alpha_rollmeta_nb(
        from_i,
        to_i,
        col,
        adj_rets,
        adj_bm_returns,
        ann_factor
    )

Rolling apply meta function based on alpha_1d_nb().

## annualized_return_1d_nb function

    annualized_return_1d_nb(
        rets,
        ann_factor,
        period=None,
        log_returns=False
    )

Annualized total return.

This is equivalent to the compound annual growth rate (CAGR).

## annualized_return_nb function

    annualized_return_nb(
        rets,
        ann_factor,
        period=None,
        log_returns=False
    )

2-dim version of annualized_return_1d_nb().

## annualized_volatility_1d_nb function

    annualized_volatility_1d_nb(
        rets,
        ann_factor,
        levy_alpha=2.0,
        ddof=0
    )

Annualized volatility of a strategy.

## annualized_volatility_nb function

    annualized_volatility_nb(
        rets,
        ann_factor,
        levy_alpha=2.0,
        ddof=0
    )

2-dim version of annualized_volatility_1d_nb().

## beta_1d_nb function

    beta_1d_nb(
        rets,
        bm_returns,
        ddof=0
    )

Beta.

## beta_nb function

    beta_nb(
        rets,
        bm_returns,
        ddof=0
    )

2-dim version of beta_1d_nb().

## beta_rollmeta_nb function

    beta_rollmeta_nb(
        from_i,
        to_i,
        col,
        rets,
        bm_returns,
        ddof=0
    )

Rolling apply meta function based on beta_1d_nb().

## calmar_ratio_1d_nb function

    calmar_ratio_1d_nb(
        rets,
        ann_factor,
        period=None,
        log_returns=False
    )

Calmar ratio, or drawdown ratio, of a strategy.

## calmar_ratio_nb function

    calmar_ratio_nb(
        rets,
        ann_factor,
        period=None,
        log_returns=False
    )

2-dim version of calmar_ratio_1d_nb().

## capture_ratio_1d_nb function

    capture_ratio_1d_nb(
        rets,
        bm_returns,
        ann_factor,
        period=None,
        log_returns=False
    )

Capture ratio.

## capture_ratio_nb function

    capture_ratio_nb(
        rets,
        bm_returns,
        ann_factor,
        period=None,
        log_returns=False
    )

2-dim version of capture_ratio_1d_nb().

## capture_ratio_rollmeta_nb function

    capture_ratio_rollmeta_nb(
        from_i,
        to_i,
        col,
        rets,
        bm_returns,
        ann_factor,
        period=None,
        log_returns=False
    )

Rolling apply meta function based on capture_ratio_1d_nb().

## common_sense_ratio_1d_nb function

    common_sense_ratio_1d_nb(
        rets
    )

Common Sense Ratio.

## common_sense_ratio_nb function

    common_sense_ratio_nb(
        rets
    )

2-dim version of common_sense_ratio_1d_nb().

## cond_value_at_risk_1d_nb function

    cond_value_at_risk_1d_nb(
        rets,
        cutoff=0.05
    )

Conditional value at risk (CVaR) of a returns stream.

## cond_value_at_risk_nb function

    cond_value_at_risk_nb(
        rets,
        cutoff=0.05
    )

2-dim version of cond_value_at_risk_1d_nb().

## cond_value_at_risk_noarr_1d_nb function

    cond_value_at_risk_noarr_1d_nb(
        rets,
        cutoff=0.05
    )

cond_value_at_risk_1d_nb() that does not allocate any arrays.

## cum_returns_1d_nb function

    cum_returns_1d_nb(
        rets,
        start_value=1.0,
        log_returns=False
    )

Cumulative returns.

## cum_returns_final_1d_nb function

    cum_returns_final_1d_nb(
        rets,
        start_value=1.0,
        log_returns=False
    )

Total return.

## cum_returns_final_nb function

    cum_returns_final_nb(
        rets,
        start_value=1.0,
        log_returns=False
    )

2-dim version of cum_returns_final_1d_nb().

## cum_returns_nb function

    cum_returns_nb(
        rets,
        start_value=1.0,
        log_returns=False
    )

2-dim version of cum_returns_1d_nb().

## deannualized_return_nb function

    deannualized_return_nb(
        ret,
        ann_factor
    )

Deannualized return.

## down_capture_ratio_1d_nb function

    down_capture_ratio_1d_nb(
        rets,
        bm_returns,
        ann_factor,
        period=None,
        log_returns=False
    )

Capture ratio for periods when the benchmark return is negative.

## down_capture_ratio_nb function

    down_capture_ratio_nb(
        rets,
        bm_returns,
        ann_factor,
        period=None,
        log_returns=False
    )

2-dim version of down_capture_ratio_1d_nb().

## down_capture_ratio_rollmeta_nb function

    down_capture_ratio_rollmeta_nb(
        from_i,
        to_i,
        col,
        rets,
        bm_returns,
        ann_factor,
        period=None,
        log_returns=False
    )

Rolling apply meta function based on down_capture_ratio_1d_nb().

## downside_risk_1d_nb function

    downside_risk_1d_nb(
        adj_rets,
        ann_factor
    )

Downside deviation below a threshold.

## downside_risk_nb function

    downside_risk_nb(
        adj_rets,
        ann_factor
    )

2-dim version of downside_risk_1d_nb().

## get_return_nb function

    get_return_nb(
        input_value,
        output_value,
        log_returns=False,
        inf_to_nan=False,
        nan_to_zero=False
    )

Calculate return from input and output value.

## information_ratio_1d_nb function

    information_ratio_1d_nb(
        adj_rets,
        ddof=0
    )

Information ratio of a strategy.

## information_ratio_nb function

    information_ratio_nb(
        adj_rets,
        ddof=0
    )

2-dim version of information_ratio_1d_nb().

## max_drawdown_1d_nb function

    max_drawdown_1d_nb(
        rets,
        log_returns=False
    )

Total maximum drawdown (MDD).

## max_drawdown_nb function

    max_drawdown_nb(
        rets,
        log_returns=False
    )

2-dim version of max_drawdown_1d_nb().

## omega_ratio_1d_nb function

    omega_ratio_1d_nb(
        adj_rets
    )

Omega ratio of a strategy.

## omega_ratio_nb function

    omega_ratio_nb(
        adj_rets
    )

2-dim version of omega_ratio_1d_nb().

## profit_factor_1d_nb function

    profit_factor_1d_nb(
        rets
    )

Profit factor.

## profit_factor_nb function

    profit_factor_nb(
        rets
    )

2-dim version of profit_factor_1d_nb().

## returns_1d_nb function

    returns_1d_nb(
        arr,
        init_value=nan,
        log_returns=False
    )

Calculate returns.

## returns_nb function

    returns_nb(
        arr,
        init_value=nan,
        log_returns=False
    )

2-dim version of returns_1d_nb().

## rolling_sharpe_acc_nb function

    rolling_sharpe_acc_nb(
        in_state
    )

Accumulator of `rolling_sharpe_nb`.

Takes a state of type RollSharpeAIS and returns a state of type RollSharpeAOS.

## rolling_sharpe_ratio_nb function

    rolling_sharpe_ratio_nb(
        returns,
        window,
        ann_factor,
        minp=None,
        ddof=0
    )

Calculate rolling Sharpe ratio.

Uses rolling_sharpe_acc_nb() at each iteration.

## sharpe_ratio_1d_nb function

    sharpe_ratio_1d_nb(
        adj_rets,
        ann_factor,
        ddof=0
    )

Sharpe ratio of a strategy.

## sharpe_ratio_nb function

    sharpe_ratio_nb(
        adj_rets,
        ann_factor,
        ddof=0
    )

2-dim version of sharpe_ratio_1d_nb().

## sortino_ratio_1d_nb function

    sortino_ratio_1d_nb(
        adj_rets,
        ann_factor
    )

Sortino ratio of a strategy.

## sortino_ratio_nb function

    sortino_ratio_nb(
        adj_rets,
        ann_factor
    )

2-dim version of sortino_ratio_1d_nb().

## tail_ratio_1d_nb function

    tail_ratio_1d_nb(
        rets
    )

Ratio between the right (95%) and left tail (5%).

## tail_ratio_nb function

    tail_ratio_nb(
        rets
    )

2-dim version of tail_ratio_1d_nb().

## tail_ratio_noarr_1d_nb function

    tail_ratio_noarr_1d_nb(
        rets
    )

tail_ratio_1d_nb() that does not allocate any arrays.

## up_capture_ratio_1d_nb function

    up_capture_ratio_1d_nb(
        rets,
        bm_returns,
        ann_factor,
        period=None,
        log_returns=False
    )

Capture ratio for periods when the benchmark return is positive.

## up_capture_ratio_nb function

    up_capture_ratio_nb(
        rets,
        bm_returns,
        ann_factor,
        period=None,
        log_returns=False
    )

2-dim version of up_capture_ratio_1d_nb().

## up_capture_ratio_rollmeta_nb function

    up_capture_ratio_rollmeta_nb(
        from_i,
        to_i,
        col,
        rets,
        bm_returns,
        ann_factor,
        period=None,
        log_returns=False
    )

Rolling apply meta function based on up_capture_ratio_1d_nb().

## value_at_risk_1d_nb function

    value_at_risk_1d_nb(
        rets,
        cutoff=0.05
    )

Value at risk (VaR) of a returns stream.

## value_at_risk_nb function

    value_at_risk_nb(
        rets,
        cutoff=0.05
    )

2-dim version of value_at_risk_1d_nb().

## value_at_risk_noarr_1d_nb function

    value_at_risk_noarr_1d_nb(
        rets,
        cutoff=0.05
    )

value_at_risk_1d_nb() that does not allocate any arrays.

#### Cookie consent

We use cookies to recognize your repeated visits and preferences, as well as to measure the effectiveness of our documentation and whether users find what they're searching for. With your consent, you're helping us to make our documentation better.

- Google Analytics
- GitHub

Manage settings