160 backtesting projects on Github, but only 4 of them in C++. Also only 4 in C#, which I use:
https://github.com/search?q=stock+backtest&type=Repositories
https://github.com/search?q=stock+backtest&type=Repositories
At my shop, we have developed and use both a separate C++ engine for backtesting high frequency strategies (though it's a bit of a tricky game and is a "glimpse" at best) and a separate python backtest engine for lower turnover strategies. Sadly I can't share or contribute, but I can give my (biased but professional) opinion on the state of backtesting engines in the open source space as well as opine on what you are trying to build.First the status of my own work.
Definitely fall into this category. This kind of backtesting is simple, and it's really just an abstraction of a live trader, but with pre-existing data. Hence my integration of the backtesting framework into a live trading application. Wouldn't you say that having a simple setting like this minimizes the drawbacks that I think you're talking about?A fixed interval (bar-based) backtester creates a target position based on a snapshot of the market at some given point in time
Touched on this above. I suspect that this piece of advice is from professional experience at a real investment firm with complicated strategies. I imagine that the strategies you're trying to make are difficult to simulate in the first place, and may not be possible at all unless you start going crazy with randomization algorithms, since the latency of your data stream has a high variance in proportion to the mean (whereas my simple model has a variance in much lower proportion to the mean). Milliseconds just don't matter in the latter case, but matter a lot in the former. Is this is the main motivation of your perspective here?Also, do not try to combine backtesting engine with actual live execution, it's silly and will give you more problems than benefits
This is a great insight. I believe what you're trying to say is that the backtester is really just supposed to tell you what your strategy's expectations (as in probability) are in terms of trade volume, trade profit, available capital, and relative performance, for a given piece of data in a known market setting. It will also make 1:1 comparisons like you mentioned easy. This kind of approach will definitely make its way into my current project.backtest analysis, especially on turnover, pnl/trade analysis, drawdowns (both depth and length) and market correlation.
Order book-based (synonym for depth-of-book right, or L2 data right?) is supposed to mean HF strategies? Also, LL development?Unless you have real life LL development experience, I'd avoid anything order-book based.
I checked out Lean. Super awesome project! I'd heard of quantconnect before starting on building a backtester. I didn't really look into them because at the time, I didn't want to learn C# and I thought that developing a C++ backtester like BackTrader would only take like one summer. The codebase they've developed looks massive, and its probably supposed to support literally any kind of strategy. That's not what I'm going for. The strategies my backtester is supposed to support have a lot to do with statistical signal processing and discrete events (hence the time map). This system has been especially useful when running intra-day strategies on lots of data lines from IB. As you could probably guess, that SP has a lot of FFT and linear algebra in it, which plenty of C++ apis will easily integrate into.
Accurate. Implementing a backtester like Lean is simply untractable for a single shmuck like myself. But I don't want the kind of generality that they're going for. My backtester will have enough stuff to support data-driven strategies for momentum, volatility, and others. The detailed stuff like reading data will come as it needs to.
If enough people care about a C++ backtester and I'm able to recruit interested parties, then one day a C++ backtester like theirs could be possible.
A valuable perspective to consider. I'm open to any kind of strategy that works, but according to my reading, volatility bets and momentum strategies can work well with sufficient signal processing. I'm definitely going to see what quantconnect/lean has to offer and learn some C# in the near future though. They seem to support a lot of broker APIs, and I like the idea of being to move between brokers if the current one isn't being cooperative.
Just to confirm @traider, you're not interested in developing a C++ backtester?
For most part, yes, you'd use full order book (at least a few levels away from the touch) to figure out order book pressures, overhangs etc. It's HFTs bread and butter. LL = low latency. Some trade/book pressure strategies would only use top of the book, especially for situations where you are doing it across related products.Order book-based (synonym for depth-of-book right, or L2 data right?) is supposed to mean HF strategies? Also, LL development?
I think it's best to think of this in turnover terms (since my target positions are sliced for execution, sometimes I get a lot of trades that are not really "trades"). Stuff that turns over from once a day and higher is "non-HFT" for the purposes of this discussion. To be honest, even higher turnover strategies can be simulated well enough using bar data (e.g. secondly bars) as long as you make some assumptions about the market microstructure.Two more questions: how many trades a day does your typical "low frequency" strategy make? How many for the high frequency strategies?
Best way to think of your backtest is that it's a Tinder profile. The ones that look ugly you swipe left right away and that's that. The ones that look passable (depending on how desperate you are) you swipe right, only to frequently discover flaming pimples and hairy armpits. Whenever that happens, you always wish that you had more pictures beforehand. Similarly, the task of a good backtesting framework is to to show you the potential issues with the strategy in every way possible. Sometimes it's possible to fix these issues without overfitting and go on. Sometimes you drop the idea all together after seeing these issues.This is a great insight. I believe what you're trying to say is that the backtester is really just supposed to tell you what your strategy's expectations (as in probability) are in terms of trade volume, trade profit, available capital, and relative performance, for a given piece of data in a known market setting. It will also make 1:1 comparisons like you mentioned easy. This kind of approach will definitely make its way into my current project.
If we can find common ground for future plans maybe develop some aspects together?
If using python ML libs then those are C anyway.You don't need C++ for writing a backtester.
I would say exactly the opposite, unless you are dealing with very short holding times or doing any sort of market making. Avoid using bid/ask spread, order simulation or simulating fills directly in the backtest process and simulate everything at mid, while maintaining good alpha/trade and volume participation statistics.In developing backtester id reccomend to implement bid and ask data, at least for order simulation if working on lower timeframes or penny stocks.
Without spreads its much easyer to find too much unrealistic oppertunity IMO.I would say exactly the opposite
Execution is highly uncertain and you would rather separate it into your implementation analysis that includes TCA/volume/slicing etc. This way you can also optimize execution holistically instead of doing it on per-strategy basis.