polakowo/vectorbt

Questions about backtesting

rubix-07 opened this issue · 0 comments

Recently I have started using VectorBT for backtesting. As a rookie, I start with something simple, so I found a moving average croosover strategy. However, when I encountered this code: pf = vbt.Portfolio.from_signals(symbol, entries, exits, init_cash=100, freq='1d', sl_stop=0.05, tp_stop=0.2), I noticed that symbol is actually the close price of a stock, let's say AAPL(daily bar). However, if I want to state that, for example, If today is Monday and a golden cross(Both MA using close price) appeared then I buy at the Open tomorrow which is Tuesday, then I should change symbol to the open price of AAPL instead cause it is impossible to execute trades at Monday Close in this case?

If I decide to build a long_signal array like ['False', 'False', 'True', 'False', 'False] (e.g. rsi < 30 is True at Wednesday Close) and then I buy at the open on Thursday, do I need to shift the long_signal array by one to the right so that I'm telling VectorBT the fact that the buy will be done at the open on Thursday instead of on Wednesday?

I have a custom indicator which returns True today if some conditions are met, let say the price crosses and is bigger than a threshold, then I enter at tomorrow open. How can I make sure that the backtester will only enter the trade(in this case is a long) once instead of multiple times if the price is still bigger than the threshold tomorrow?

Any help will be greatly appreciated.