Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community. It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
How to develop your own backtester in C/C++ or C# ?
I use IB-API but still using NT7 as a trusted platform. Despite I'm satisfied with it, I'm interested to develop my own backtester in C or C#, along with other functional modules. Since I'm just an economist/trader, not a CS guy, I'm learning yet superior programming abilities. So, I'd like to speed my process up and was wondering if there are some : courses, tutorials specialized in these kind of development to learn from.
Thanks in advance for any idea or suggestion
Can you help answer these questions from other members on NexusFi?
If you go down the c# path there are a couple of open source libraries available, one is used (or developed) by QuantConnect, which is also a c# online backtest engine;
Hi. Ive got quite a bit of experience doing this having done it myself.
All I can say its that it gets very cool having a backtester that does what you need to do,
and if you find anything interesting on the internet you can just add the functionality yourself.
Saying that though, the coding really took me more than a year and a half (part time).
Its also very mathematical, so you constantly have to test the values and make sure every calculation is right.
(TL;DR) Just saying it will take quite a long time and you need to be quite familiar with coding concepts
like object orientation, sorting algorithms, etc
I have build several backtesting tools in SQL. I also develop in C#. The key concepts are largely the same in terms of what you are trying to solve for.
You can hack together a basic HLOC testing system really easily, but if you want to get into the nuances of "would you have realistically gotten filled or not" there are more things to consider.
1. Market Orders: Despite the common misconception that these fill instantly, there is a queue for market orders as well. So you would need to consider this into your logic to have accurate slippage..
2. Execution time relative to realistic latency: This is a huge design consideration if you want to make your system have value. If you mess this part up, the whole project may be worthless. The thing you need to do is built a latency trigger into your system so once you get your alpha signal that tells you to "get in, get out, or cancel", you need to then have a wait period of X before you mark your position in the queue. X = your latency. If you don't know this yet, I can show you how to test this.
3. Limit Orders: This is a big one... Depending on how well you handle this part, your system may be good or completely worthless. When I say completely worthless here is an example. Check the box in NinjaTrader 7 to fill limit orders on touch and then run a simple strategy with random entries (flip a coin on direction / when to get in) and set a profit target and stop loss at 3 ticks. Then watch your account run up millions of fake dollars.... Unless you want your custom testing platform to make the same mistake you will have to do better here.
You will be solving for both level 2 and level 1 data feeds and using volume to define if and when orders get filled. So conceptually you will need to be able to compute lots of running totals in different columns. In SQL, I just have a 5 - 10 different columns calculating different things cumulatively, or one column / another column and if that > 100% then do this.... or that.... etc.
If you are going at this in C# or just application code without a database, your best shot is to use a list. in C# you can use a list object from the Linq class I believe. Here you would just insert specific variables into your list, run your calculations and after you determine the outcome of a trade, clear your list and then repeat.
Keep us posted on how it goes.
Best of luck!
Ian
In the analytical world there is no such thing as art, there is only the science you know and the science you don't know. Characterizing the science you don't know as "art" is a fools game.