NexusFi: Find Your Edge


Home Menu

 





How to develop your own backtester in C/C++ or C# ?


Discussion in Platforms and Indicators

Updated
      Top Posters
    1. looks_one bchip with 2 posts (3 thanks)
    2. looks_two pstrusi with 2 posts (0 thanks)
    3. looks_3 amoeba with 1 posts (2 thanks)
    4. looks_4 iantg with 1 posts (0 thanks)
    1. trending_up 3,407 views
    2. thumb_up 5 thanks given
    3. group 5 followers
    1. forum 5 posts
    2. attach_file 0 attachments




 
Search this Thread

How to develop your own backtester in C/C++ or C# ?

  #1 (permalink)
pstrusi
Lalin Pontevedra Spain
 
Posts: 20 since Sep 2013
Thanks Given: 10
Thanks Received: 9

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

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Exit Strategy
NinjaTrader
Are there any eval firms that allow you to sink to your …
Traders Hideout
Futures True Range Report
The Elite Circle
Online prop firm The Funded Trader (TFT) going under?
Traders Hideout
ZombieSqueeze
Platforms and Indicators
 
  #2 (permalink)
 
amoeba's Avatar
 amoeba 
Sydney, NSW, Australia
 
Experience: Intermediate
Platform: Sierra Chart, Python, C#
Broker: Interactive Brokers
Trading: MJNK, ASX, SPI
Posts: 205 since Jan 2014
Thanks Given: 98
Thanks Received: 284

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;

https://www.quantconnect.com/

or GitHub source at https://github.com/QuantConnect/Lean

Reply With Quote
Thanked by:
  #3 (permalink)
 bchip 
Torino, Italy
 
Experience: Advanced
Platform: TradeStation
Trading: ES,YM,CL,GC
Posts: 132 since Sep 2017
Thanks Given: 160
Thanks Received: 116



pstrusi View Post
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

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


Good luck.

Reply With Quote
Thanked by:
  #4 (permalink)
pstrusi
Lalin Pontevedra Spain
 
Posts: 20 since Sep 2013
Thanks Given: 10
Thanks Received: 9


bchip View Post
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


Good luck.

By any chance would you remind some reference in the net to check it?
Thanks!!

Reply With Quote
  #5 (permalink)
 bchip 
Torino, Italy
 
Experience: Advanced
Platform: TradeStation
Trading: ES,YM,CL,GC
Posts: 132 since Sep 2017
Thanks Given: 160
Thanks Received: 116


pstrusi View Post
By any chance would you remind some reference in the net to check it?
Thanks!!

Hi

Not sure which part you need references on.
One of the other traders on this forum posted this link:
https://github.com/rediar/InteractiveBrokers-Algo-System

Which is their Java project connecting to IB.

Other than that indicators have many websites that help on calculations,
I found this book also to be quite useful:
https://www.amazon.com/Technical-Analysis-2nd-Steven-Achelis/dp/0071826297

Reply With Quote
Thanked by:
  #6 (permalink)
 iantg 
charlotte nc
 
Experience: Advanced
Platform: My Own System
Broker: Optimus
Trading: Emini (ES, YM, NQ, ect.)
Posts: 408 since Jan 2015
Thanks Given: 90
Thanks Received: 1,147

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.
Visit my NexusFi Trade Journal Reply With Quote




Last Updated on July 30, 2018


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts