Skip to main content

portfolio_pipeline

portfolio_pipeline(
    data: vectorbtpro.data.base.Data,
    s1: str,
    s2: str,
    model_func: Callable,
    signal_func: Callable,
    long_entries: float,
    long_exits: float,
    short_entries: float,
    short_exits: float,
    preprocess_func: Callable = None,
    metrics: str | List[str= None,
    use_close: bool = True,
    size: float | numpy.ndarray = 50,
    size_type: str | numpy.ndarray = 'valuepercent100',
    allow_partial: float | numpy.ndarray = None,
    fees: float | numpy.ndarray = None,
    fixed_fees: float | numpy.ndarray = None,
    slippage: float | numpy.ndarray = None,
    min_size: float | numpy.ndarray = None,
    max_size: float | numpy.ndarray = None,
    size_granularity: float | numpy.ndarray = None,
    sl_stop: float | numpy.ndarray = None,
    tsl_stop: float | numpy.ndarray = None,
    tp_stop: float | numpy.ndarray = None,
    accumulate: bool | str | numpy.ndarray = None,
    init_cash: float | numpy.ndarray = None,
    cash_sharing: bool = True,
    group_by: bool = True,
    call_seq: str | bool = 'auto',
    fill_pos_info: bool = False,
    log: bool | numpy.ndarray = None,
    portfolio_kwargs: Dict[str, Any] = None,
    **model_params,
) ‑> vectorbtpro.portfolio.base.Portfolio | float | List[float| pandas.core.series.Series | pandas.core.frame.DataFrame
Executes the portfolio pipeline. Parameters:
NameTypeDefaultDescription
datavbt.Data--The input data.
s1str--First symbol.
s2str--Second symbol.
model_functp.Callable--Function to compute model output.
signal_functp.Callable--Function to generate signals.
long_entriesfloat--Long entry signals.
long_exitsfloat--Long exit signals.
short_entriesfloat--Short entry signals.
short_exitsfloat--Short exit signals.
preprocess_functp.CallableNonePreprocessing function(s) to apply (default is None).
metricsstrNoneMetrics to compute (default is None).
use_closeboolTrueWhether to use ‘Close’ prices (default is True).
sizefloat50Size of each order (default is 50).
size_typestrvaluepercent100Type of size (default is “valuepercent100”).
allow_partialfloatNoneWhether to allow partial fills (default is None).
feesfloatNoneFees per order (default is None).
fixed_feesfloatNoneFixed fees per order (default is None).
slippagefloatNoneSlippage per order (default is None).
min_sizefloatNoneMinimum size of each order (default is None).
max_sizefloatNoneMaximum size of each order (default is None).
size_granularityfloatNoneGranularity of size (default is None).
sl_stopfloatNoneStop-loss level (default is None).
tsl_stopfloatNoneTrailing stop-loss level (default is None).
tp_stopfloatNoneTake-profit level (default is None).
accumulateboolNoneWhether to accumulate orders (default is None).
init_cashfloatNoneInitial cash (default is None).
cash_sharingboolTrueWhether to share cash between assets (default is True).
group_byboolTrueWhether to group by symbol (default is True).
call_seqboolautoCall sequence (default is “auto”).
fill_pos_infoboolFalseWhether to fill position info (default is False).
logboolNoneWhether to log orders (default is None).
portfolio_kwargstp.KwargsNoneAdditional keyword arguments for the portfolio simulation.
model_paramstp.Kwargs--Additional parameters for model_func.
Returns:
TypeDescription
vbt.Portfolio or float or tp.List[float] or tp.SeriesFrameThe result of the portfolio simulation.

portfolio_pipeline_nb

portfolio_pipeline_nb(
    open: numpy.ndarray,
    high: numpy.ndarray,
    low: numpy.ndarray,
    close: numpy.ndarray,
    preprocess_func_nb: Callable,
    model_func_nb: Callable,
    metrics_func_nb: Callable,
    signal_func_nb: Callable,
    long_entries: float = -1.0,
    long_exits: float = 0.0,
    short_entries: float = 1.0,
    short_exits: float = 0.0,
    size: int | float = 50,
    sl_stop: float = nan,
    tsl_stop: float = nan,
    tp_stop: float = nan,
) ‑> Any
Executes the portfolio pipeline. Parameters:
NameTypeDefaultDescription
opentp.Array1d--Open prices.
hightp.Array1d--High prices.
lowtp.Array1d--Low prices.
closetp.Array1d--Close prices.
model_func_nbtp.Callable--Function to compute model output.
metrics_func_nbtp.Callable--Function to compute metrics.
signal_func_nbtp.Callable--Function to generate signals.
long_entriesfloat-1.0Long entry signals. Defaults to -1.0.
long_exitsfloat0.0Long exit signals. Defaults to 0.0.
short_entriesfloat1.0Short entry signals. Defaults to 1.0.
short_exitsfloat0.0Short exit signals. Defaults to 0.0.
preprocess_func_nbtp.CallableNonePreprocessing function(s) to apply. Defaults to None.
sizeint--or float, default 50 Size of each order. Defaults to 50.
sl_stopfloatnp.nanStop-loss level. Defaults to np.nan.
tsl_stopfloatnp.nanTrailing stop-loss level. Defaults to np.nan.
tp_stopfloatnp.nanTake-profit level. Defaults to np.nan.
Returns:
TypeDescription
tp.AnyThe result of the portfolio simulation.