Skip to content

ctx_helpers module

Numba-compiled context helper functions for portfolio simulation.


col_has_free_cash_nb function

col_has_free_cash_nb(
    c,
    col
)

Check whether a column has free cash.


col_has_orders_nb function

col_has_orders_nb(
    c,
    col
)

Check whether there is any order in a column.


col_in_long_position_nb function

col_in_long_position_nb(
    c,
    col
)

Check whether a column is in a long position.


col_in_position_nb function

col_in_position_nb(
    c,
    col
)

Check whether a column is in a position.


col_in_short_position_nb function

col_in_short_position_nb(
    c,
    col
)

Check whether a column is in a short position.


get_allocation_nb function

get_allocation_nb(
    c
)

Get allocation of the current column in the current group.


get_cash_nb function

get_cash_nb(
    c
)

Get cash of the current column or group with cash sharing.


get_col_allocation_nb function

get_col_allocation_nb(
    c,
    col,
    group=None
)

Get allocation of a column in its group.


get_col_cash_nb function

get_col_cash_nb(
    c,
    col
)

Get cash of a column.


get_col_debt_nb function

get_col_debt_nb(
    c,
    col
)

Get debt of a column.


get_col_entry_trade_records_nb function

get_col_entry_trade_records_nb(
    c,
    col,
    init_position=0.0,
    init_price=nan
)

Get entry trade records of a column up to this point.


get_col_exit_trade_records_nb function

get_col_exit_trade_records_nb(
    c,
    col,
    init_position=0.0,
    init_price=nan
)

Get exit trade records of a column up to this point.


get_col_free_cash_nb function

get_col_free_cash_nb(
    c,
    col
)

Get free cash of a column.


get_col_last_order_nb function

get_col_last_order_nb(
    c,
    col
)

Get the last order in a column.


get_col_leverage_nb function

get_col_leverage_nb(
    c,
    col
)

Get leverage of a column.


get_col_limit_info_nb function

get_col_limit_info_nb(
    c,
    col
)

Get limit order information of a column.


get_col_limit_target_price_nb function

get_col_limit_target_price_nb(
    c,
    col
)

Get target price of limit order in a column.


get_col_locked_cash_nb function

get_col_locked_cash_nb(
    c,
    col
)

Get locked cash of a column.


get_col_order_count_nb function

get_col_order_count_nb(
    c,
    col
)

Get number of order records for a column.


get_col_order_records_nb function

get_col_order_records_nb(
    c,
    col
)

Get order records for a column.


get_col_position_nb function

get_col_position_nb(
    c,
    col
)

Get position of a column.


get_col_position_records_nb function

get_col_position_records_nb(
    c,
    col,
    init_position=0.0,
    init_price=nan
)

Get position records of a column up to this point.


get_col_position_value_nb function

get_col_position_value_nb(
    c,
    col
)

Get position value of a column.


get_col_sl_info_nb function

get_col_sl_info_nb(
    c,
    col
)

Get SL order information of a column.


get_col_sl_target_price_nb function

get_col_sl_target_price_nb(
    c,
    col
)

Get target price of SL order in a column.


get_col_tp_info_nb function

get_col_tp_info_nb(
    c,
    col
)

Get TP order information of a column.


get_col_tp_target_price_nb function

get_col_tp_target_price_nb(
    c,
    col
)

Get target price of TP order in a column.


get_col_tsl_info_nb function

get_col_tsl_info_nb(
    c,
    col
)

Get TSL/TTP order information of a column.


get_col_tsl_target_price_nb function

get_col_tsl_target_price_nb(
    c,
    col
)

Get target price of TSL/TTP order in a column.


get_col_val_price_nb function

get_col_val_price_nb(
    c,
    col
)

Get valuation price of a column.


get_col_value_nb function

get_col_value_nb(
    c,
    col
)

Get value of a column.


get_debt_nb function

get_debt_nb(
    c
)

Get debt of the current column.


get_entry_trade_records_nb function

get_entry_trade_records_nb(
    c,
    init_position=0.0,
    init_price=nan
)

Get entry trade records of the current column up to this point.


get_exit_trade_records_nb function

get_exit_trade_records_nb(
    c,
    init_position=0.0,
    init_price=nan
)

Get exit trade records of the current column up to this point.


get_free_cash_nb function

get_free_cash_nb(
    c
)

Get free cash of the current column or group with cash sharing.


get_group_cash_nb function

get_group_cash_nb(
    c,
    group
)

Get cash of a group.


get_group_free_cash_nb function

get_group_free_cash_nb(
    c,
    group
)

Get free cash of a group.


get_group_position_value_nb function

get_group_position_value_nb(
    c,
    group
)

Get position value of a group.


get_group_value_nb function

get_group_value_nb(
    c,
    group
)

Get value of a group.


get_last_order_nb function

get_last_order_nb(
    c
)

Get the last order in the current column.


get_leverage_nb function

get_leverage_nb(
    c
)

Get leverage of the current column.


get_limit_info_nb function

get_limit_info_nb(
    c
)

Get limit order information of the current column.


get_limit_target_price_nb function

get_limit_target_price_nb(
    c
)

Get target price of limit order in the current column.


get_locked_cash_nb function

get_locked_cash_nb(
    c
)

Get locked cash of the current column.


get_n_active_positions_nb function

get_n_active_positions_nb(
    c,
    all_groups=False
)

Get the number of active positions in the current group (regardless of cash sharing).

To calculate across all groups, set all_groups to True.


get_order_count_nb function

get_order_count_nb(
    c
)

Get number of order records for the current column.


get_order_records_nb function

get_order_records_nb(
    c
)

Get order records for the current column.


get_position_nb function

get_position_nb(
    c
)

Get position of the current column.


get_position_records_nb function

get_position_records_nb(
    c,
    init_position=0.0,
    init_price=nan
)

Get position records of the current column up to this point.


get_position_value_nb function

get_position_value_nb(
    c
)

Get position value of the current column.


get_sl_info_nb function

get_sl_info_nb(
    c
)

Get SL order information of the current column.


get_sl_target_price_nb function

get_sl_target_price_nb(
    c
)

Get target price of SL order in the current column.


get_tp_info_nb function

get_tp_info_nb(
    c
)

Get TP order information of the current column.


get_tp_target_price_nb function

get_tp_target_price_nb(
    c
)

Get target price of TP order in the current column.


get_tsl_info_nb function

get_tsl_info_nb(
    c
)

Get TSL/TTP order information of the current column.


get_tsl_target_price_nb function

get_tsl_target_price_nb(
    c
)

Get target price of TSL/TTP order in the current column.


get_val_price_nb function

get_val_price_nb(
    c
)

Get valuation price of the current column.


get_value_nb function

get_value_nb(
    c
)

Get value of the current column or group with cash sharing.


group_has_free_cash_nb function

group_has_free_cash_nb(
    c,
    group
)

Check whether a group has free cash.


has_free_cash_nb function

has_free_cash_nb(
    c
)

Check whether the current column or group with cash sharing has free cash.


has_orders_nb function

has_orders_nb(
    c
)

Check whether there is any order in the current column.


in_long_position_nb function

in_long_position_nb(
    c
)

Check whether the current column is in a long position.


in_position_nb function

in_position_nb(
    c
)

Check whether the current column is in a position.


in_short_position_nb function

in_short_position_nb(
    c
)

Check whether the current column is in a short position.


order_closed_position_nb function

order_closed_position_nb(
    c
)

Check whether the order has closed out an existing position.


order_decreased_position_nb function

order_decreased_position_nb(
    c
)

Check whether the order has decreased or closed an existing position.


order_filled_nb function

order_filled_nb(
    c
)

Check whether the order was filled.


order_increased_position_nb function

order_increased_position_nb(
    c
)

Check whether the order has opened or increased an existing position.


order_opened_position_nb function

order_opened_position_nb(
    c
)

Check whether the order has opened a new position.


order_reversed_position_nb function

order_reversed_position_nb(
    c
)

Check whether the order has reversed an existing position.


stop_group_sim_nb function

stop_group_sim_nb(
    c,
    group
)

Stop the simulation of a group.


stop_sim_nb function

stop_sim_nb(
    c
)

Stop the simulation of the current group.