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

# analysis module

Numba-compiled functions for portfolio analysis.

## align_init_cash_nb function

    align_init_cash_nb(
        init_cash_raw,
        free_cash_flow,
        cash_deposits=0.0
    )

Align initial cash to the maximum negative free cash flow.

Adds 1 for easier computing returns.

## allocations_nb function

    allocations_nb(
        asset_value,
        value,
        group_lens
    )

Get allocations per column.

## asset_flow_nb function

    asset_flow_nb(
        target_shape,
        order_records,
        col_map,
        direction=2,
        init_position=0.0
    )

Get asset flow series per column.

Returns the total transacted amount of assets at each time step.

## asset_pnl_nb function

    asset_pnl_nb(
        init_position_value,
        asset_value,
        cash_flow
    )

Get asset (realized and unrealized) PnL series per column/group.

## asset_returns_nb function

    asset_returns_nb(
        init_position_value,
        asset_value,
        cash_flow,
        log_returns=False
    )

Get asset return series per column/group.

## asset_value_grouped_nb function

    asset_value_grouped_nb(
        asset_value,
        group_lens
    )

Get asset value series per group.

## asset_value_nb function

    asset_value_nb(
        close,
        assets
    )

Get asset value series per column.

## assets_nb function

    assets_nb(
        asset_flow,
        init_position=0.0
    )

Get asset series per column.

Returns the current position at each time step.

## cash_deposits_grouped_nb function

    cash_deposits_grouped_nb(
        target_shape,
        cash_deposits_raw,
        group_lens,
        cash_sharing
    )

Get cash deposit series per group.

## cash_deposits_nb function

    cash_deposits_nb(
        target_shape,
        cash_deposits_raw,
        group_lens,
        cash_sharing,
        split_shared=False
    )

Get cash deposit series per column.

## cash_flow_grouped_nb function

    cash_flow_grouped_nb(
        cash_flow,
        group_lens
    )

Get cash flow series per group.

## cash_flow_nb function

    cash_flow_nb(
        target_shape,
        order_records,
        col_map,
        free=False,
        cash_earnings=0.0
    )

Get (free) cash flow series per column.

## cash_grouped_nb function

    cash_grouped_nb(
        target_shape,
        cash_flow_grouped,
        group_lens,
        init_cash_grouped,
        cash_deposits_grouped=0.0
    )

Get cash series per group.

## cash_nb function

    cash_nb(
        cash_flow,
        init_cash,
        cash_deposits=0.0
    )

Get cash series per column.

## get_asset_pnl_nb function

    get_asset_pnl_nb(
        input_asset_value,
        output_asset_value,
        cash_flow
    )

Get asset PnL from the input and output asset value, and the cash flow.

## get_asset_return_nb function

    get_asset_return_nb(
        input_asset_value,
        output_asset_value,
        cash_flow,
        log_returns=False
    )

Get asset return from the input and output asset value, and the cash flow.

## get_free_cash_diff_nb function

    get_free_cash_diff_nb(
        position_before,
        position_now,
        debt_now,
        price,
        fees
    )

Get updated debt and free cash flow.

## get_long_size_nb function

    get_long_size_nb(
        position_before,
        position_now
    )

Get long size.

## get_short_size_nb function

    get_short_size_nb(
        position_before,
        position_now
    )

Get short size.

## gross_exposure_nb function

    gross_exposure_nb(
        asset_value,
        value
    )

Get gross exposure per column/group.

## init_cash_grouped_nb function

    init_cash_grouped_nb(
        init_cash_raw,
        group_lens,
        cash_sharing
    )

Get initial cash per group.

## init_cash_nb function

    init_cash_nb(
        init_cash_raw,
        group_lens,
        cash_sharing,
        split_shared=False
    )

Get initial cash per column.

## init_position_value_nb function

    init_position_value_nb(
        n_cols,
        init_position=0.0,
        init_price=nan
    )

Get initial position value per column.

## init_value_grouped_nb function

    init_value_grouped_nb(
        group_lens,
        init_position_value,
        init_cash_grouped
    )

Get initial value per group.

## init_value_nb function

    init_value_nb(
        init_position_value,
        init_cash
    )

Get initial value per column.

## long_assets_nb function

    long_assets_nb(
        assets
    )

Get long-only assets.

## market_value_grouped_nb function

    market_value_grouped_nb(
        close,
        group_lens,
        init_value,
        cash_deposits=0.0
    )

Get market value per group.

## market_value_nb function

    market_value_nb(
        close,
        init_value,
        cash_deposits=0.0
    )

Get market value per column.

## returns_nb function

    returns_nb(
        value,
        init_value,
        cash_deposits=0.0,
        cash_deposits_as_input=False,
        log_returns=False
    )

Get return series per column/group.

## short_assets_nb function

    short_assets_nb(
        assets
    )

Get short-only assets.

## sum_grouped_nb function

    sum_grouped_nb(
        arr,
        group_lens
    )

Squeeze each group of columns into a single column using sum operation.

## total_profit_grouped_nb function

    total_profit_grouped_nb(
        total_profit,
        group_lens
    )

Get total profit per group.

## total_profit_nb function

    total_profit_nb(
        target_shape,
        close,
        order_records,
        col_map,
        init_position=0.0,
        init_price=nan,
        cash_earnings=0.0
    )

Get total profit per column.

A much faster version than the one based on value_nb().

## value_nb function

    value_nb(
        cash,
        asset_value
    )

Get portfolio value series per column/group.

#### 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