vectorbt
vectorbt copied to clipboard
Apply take profit / stop loss to from_orders function
First of all, many thanks for this great library!
I am trying to backtest a long-short strategy where say I short 2 stocks and long 2 stocks.
I am using the vbt.Portfolio.from_orders
function and relying on size_type = 'targetpercent'
I input a size DataFrame with my target percentage positions.
However, there is no tp_stop
or sl_stop
parameters in the function, so how can I take those TP/SL into account in such a backtest?
Examples are more than appreciated.
Many thanks in advance!
@jejebelfort stop loss orders are only supported in Portfolio.from_signals, and only one position is allowed to be opened at a time in both Portfolio.from_orders and Portfolio.from_signals. Your best bet is to write a custom order function with Portfolio.from_order_func.
@polakowo thanks a lot, that helps clarifying ;)
Do you have youtube channel ? We cant install everytime new errors.