1
$\begingroup$

I saw and reviewed many python backtesting libraries - pyalgotrade, zipline, catalyst, backtrader, etc.

It seems that none of the provide a straightforward way to perform "Tick-based or Multi-timeframe backtesting on CRYPTO".

  • pyalgotrade seems to be only close-based.
  • zipline is for stocks.
  • catalyst (a fork of zipline) can simulate ticks with 1min closes, but their data provider for data ingestion is down.
  • backtrader seems to be only close-based.

What I want to achieve

I want to perform backtests such that:

  1. Indicators being calculated with daily timeframe data.
  2. Main loop progress with tick-based data or at least like zipline (with closes of a shorter timeframe, like 1min).

And I need feature two for the following:

  • being able to simulate stop-losses, i.e. within candle body or shadows - not only in candle close.
  • being able to backtest intra-bar strategies, so it could simulate entry and exits within body of a single bar.

Thanks in advance.

$\endgroup$
0
$\begingroup$

Have you tried using ccxt? This library is available on GitHub and offers most of what you’re looking for. It offers minutely candle data from several dozen exchanges as well as a backtesting framework which implements indicators really well. I’m not sure if they offer intra-candle strategies but their features support what you’re looking for otherwise.

$\endgroup$
3
  • $\begingroup$ Didn't know that ccxt is able to backtest. Will check it and respond here later. Thanks. $\endgroup$ – Amin Saqi Feb 3 at 13:29
  • $\begingroup$ Has this library answered the question? If so please feel free to accept the answer but if not, let us know what the shortcomings of it were. $\endgroup$ – Hamish Gibson Feb 3 at 19:48
  • $\begingroup$ As I guessed before, ccxt does not offer ANY of what I'm looking for - It's just an exchange integration library, however a good one, maybe the best. $\endgroup$ – Amin Saqi Feb 5 at 20:18
0
$\begingroup$

I have been looking for it also, and I don't think anything is able to do that. I personally re-built some backtrading program, and I think it's pretty straightforward to do especially with Pandas' ability to resample data by time and build candles from it. https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.resample.html

You have 2 set of data:

  • The ticks/trades, over which you look in real time to compute your balance, stop loss, take profit etc. Could be 1 minute candles also (and you use the "close" data as the tick, or could be live ticks).
  • The candles on which you build your indicators etc, that you can also build on-the-go as you loop over your ticks-trades. Personally, I pre-build the candles with pandas so I can "verify" that the live-built data from the trades matches exactly. And I also use the pre-computed candles to know at which time I should recompute the indicators (because when you loop over all the ticks/trades, you won't recompute the indicators every time, you have to wait for the candle to be completely built)

As for getting the data... You can get pretty good 1 minute candles (200 days) from Binance, or full trade history from Kraken from the API. Those are free and easy to get, maybe there are other ones.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.