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

# from_orders module

Numba-compiled functions for portfolio simulation based on orders.

## from_orders_nb function

    from_orders_nb(
        target_shape,
        group_lens,
        open=nan,
        high=nan,
        low=nan,
        close=nan,
        init_cash=100.0,
        init_position=0.0,
        init_price=nan,
        cash_deposits=0.0,
        cash_earnings=0.0,
        cash_dividends=0.0,
        size=inf,
        price=inf,
        size_type=0,
        direction=2,
        fees=0.0,
        fixed_fees=0.0,
        slippage=0.0,
        min_size=nan,
        max_size=nan,
        size_granularity=nan,
        leverage=1.0,
        leverage_mode=0,
        reject_prob=0.0,
        price_area_vio_mode=0,
        allow_partial=True,
        raise_reject=False,
        log=False,
        val_price=inf,
        from_ago=0,
        call_seq=None,
        auto_call_seq=False,
        ffill_val_price=True,
        update_value=False,
        save_state=False,
        save_value=False,
        save_returns=False,
        max_order_records=None,
        max_log_records=0
    )

Creates on order out of each element.

Iterates in the column-major order. Utilizes flexible broadcasting.

Note

Should be only grouped if cash sharing is enabled.

Single value must be passed as a 0-dim array (for example, by using `np.asarray(value)`).

Usage

- Buy and hold using all cash and closing price (default):

    >>> from vectorbtpro import *
    >>> from vectorbtpro.records.nb import col_map_nb
    >>> from vectorbtpro.portfolio.nb import from_orders_nb, asset_flow_nb

    >>> close = np.array([1, 2, 3, 4, 5])[:, None]
    >>> sim_out = from_orders_nb(
    ...     target_shape=close.shape,
    ...     group_lens=np.array([1]),
    ...     call_seq=np.full(close.shape, 0),
    ...     close=close
    ... )
    >>> col_map = col_map_nb(sim_out.order_records['col'], close.shape[1])
    >>> asset_flow = asset_flow_nb(close.shape, sim_out.order_records, col_map)
    >>> asset_flow
    array([[100.],
           [  0.],
           [  0.],
           [  0.],
           [  0.]])

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