Multiple assets with `adjust_sl_func_nb`
Opened this issue · 1 comments
sergejlazuk commented
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.
polakowo commented
In adjust_sl_func_nb
, c.col
gives you the current column, such that you can pass a custom array in adjust_sl_args
and then select from that array using that column.