Skip to content

nb module

Numba-compiled functions for portfolio optimization.


allocate_meta_nb function

allocate_meta_nb(
    n_cols,
    index_points,
    allocate_func_nb,
    *args
)

Allocate by mapping each index point.

map_func_nb must take the point index, the index point, and *args. Must return a 1-dim array with the same size as n_cols.


get_alloc_points_nb function

get_alloc_points_nb(
    filled_allocations,
    valid_only=True,
    nonzero_only=True,
    unique_only=True
)

Get allocation points from filled allocations.

If valid_only is True, does not register a new allocation when all points are NaN.v If nonzero_only is True, does not register a new allocation when all points are zero. If unique_only is True, does not register a new allocation when it's the same as the last one.


optimize_meta_nb function

optimize_meta_nb(
    n_cols,
    range_starts,
    range_ends,
    optimize_func_nb,
    *args
)

Optimize by reducing each index range.

reduce_func_nb must take the range index, the range start, the range end, and *args. Must return a 1-dim array with the same size as n_cols.


pick_idx_allocate_func_nb function

pick_idx_allocate_func_nb(
    i,
    index_point,
    allocations
)

Pick the allocation at an absolute position in an array.


pick_point_allocate_func_nb function

pick_point_allocate_func_nb(
    i,
    index_point,
    allocations
)

Pick the allocation at an index point in an array.


prepare_alloc_points_nb function

prepare_alloc_points_nb(
    index_points,
    allocations,
    group
)

Prepare allocation points.


prepare_alloc_ranges_nb function

prepare_alloc_ranges_nb(
    start_idx,
    end_idx,
    alloc_idx,
    status,
    allocations,
    group
)

Prepare allocation ranges.


random_allocate_func_nb function

random_allocate_func_nb(
    i,
    index_point,
    n_cols,
    direction=0,
    n=None
)

Generate a random allocation.


rescale_allocations_nb function

rescale_allocations_nb(
    allocations,
    to_range
)

Rescale allocations to a new scale.

Positive and negative weights are rescaled separately from each other.