Closed Pirat83 closed 1 year ago
Example is here: https://github.com/Pirat83/pybroker-experiments/blob/master/main.py
The start_date and end_date passed to the Strategy constructor specifies the date range to download from a DataSource. The start_date and end_date passed to Strategy#backtest can be a subset of that date range. The warmup parameter specifies the number of bars to skip after the start_date before running the Strategy.
Okay so it should work like desiered. I will give it a try. Thank you very much.
Hello,
I currently have some questions about the warmup property in the
Strategy.backtest(...)
method. My goal is to set the propper warmup period that is required to initialize all my indicators and to start trading at a specific date.So let's calculate a ROC Indicator with the lenght 5 and start trading at the first of January.
So we need 5 periods to get the ROC(5) indicator calculated. This takes until the 2023-01-10 and the first trade is opened on the 2023-01-11:
My original intention was to use 'Strategy.backtest(start_date, end_date, ...)' to start trading at the 2023-01-01 and to use Pyhtons 'timedelta(days=warmup) to shift the data fetching so the warmup period is substracted from the start_date. In this way we could start trading exactly at the 2023-01-01 (where stock exchanges closed so it was in reality the 2023-01-03) .
But doing so this exception is thown:
So I came across an other idea to move the backtest start_date into future remove the warmup parameter, but this resulted into the same exception:
So I came to the conclusion that
Strategy
start_date
andend_date
should not be different thenStrategy.backtest(start_date, end_date)
and therefore I dont understand why this redundancy is kept?So idealy I would like to simply fetch i.e 1 month more data then required from the start_date from Alpaca and then start backtesting at exaclty the start_date (or the next candle). Is it possible to achive this?