Skip to content

Multiple assets with adjust_sl_func_nb #758

@sergejlazuk

Description

@sergejlazuk

Hello,
I would like to pass different arguments per Asset (price columns) into adjust_sl_func_nb. I use adjust_sl_args callback.

For same args for all assets it works, e.g. like this: (here I pass 10 and 20 as inputs into adjust_sl_func_nb which is used by all assets):

pf=vbt.Portfolio.from_signals(
        close=np.array([[10.,20.,30.,40.],[100.,200.,300.,400.]]).T,
        entries=np.array([[True,False,False,False],[True,False,False,False]]).T,
        size=1, size_type='Amount',direction='LongOnly',
        use_stops=True,
	adjust_sl_func_nb=my_adjust_sl_func_nb, 
        adjust_sl_args=(10., 20.), 
        init_cash=10000)

But how do i pass different args per asset?
I tried as below (tuple of tuples), but it does not work:

pf=vbt.Portfolio.from_signals(
        close=np.array([[10.,20.,30.,40.],[100.,200.,300.,400.]]).T,
        entries=np.array([[True,False,False,False],[True,False,False,False]]).T,
        size=1, size_type='Amount',direction='LongOnly',
        use_stops=True,
	adjust_sl_func_nb=my_adjust_sl_func_nb,
        adjust_sl_args=((10., 20.), (11., 21.)),
        init_cash=10000)

Error:

No implementation of function Function(<built-in function sub>) found for signature:
 
 >>> sub(float64, UniTuple(float64 x 2))

Thanks a lot.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions