vectorbt icon indicating copy to clipboard operation
vectorbt copied to clipboard

Apply take profit / stop loss to from_orders function

Open jejebelfort opened this issue 2 years ago • 3 comments

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 avatar Apr 26 '22 02:04 jejebelfort

@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 avatar Apr 26 '22 11:04 polakowo

@polakowo thanks a lot, that helps clarifying ;)

jejebelfort avatar Apr 27 '22 07:04 jejebelfort

Do you have youtube channel ? We cant install everytime new errors.

denizhantoy avatar Aug 10 '22 12:08 denizhantoy