polakowo / vectorbt

Find your trading edge, using the fastest engine for backtesting, algorithmic trading, and research.
https://vectorbt.dev
Other
4.36k stars 619 forks source link

How to iterate backtest with different combinations of TP and SL? #506

Open jasonxtrading opened 2 years ago

jasonxtrading commented 2 years ago

Hi,

I am trying to make a backtest of a breakout strategy on stocks and would like to find the right combination of TP and SL? I have realised that in vbt.Portfolio.from_signals(close_price,entries,tp_stop = 0.01,sl_stop= 0.005) you cannot give a range of scalars, but only one scalar.

I would like to backtest the strategy with TP target between 0.01 and 0.05 and the same for SL.

Any ideas of how can I go about this?

Thanks in advance.

httran13 commented 1 year ago

there's an example here : https://github.com/polakowo/vectorbt/blob/b5d49438492e442c936c8580d2e1580f1eda5e47/vectorbt/signals/generators.py#L686

eromoe commented 1 year ago

@httran13 This only analyze signals before simulation . If I have a Custom IndicatorFactory , is that mean I need create a corresponding SignalFactory to generate sl_stop, tp_stop, wonder if here any convenient way .

Would you share any idea about optimisze sl_stop, tp_stop base on simulation return value (asset_value)?