Any good structure for a simple self-made backtesting platform?

Discussion in 'Programming' started by j2ee, May 11, 2013.

  1. j2ee


    After long discussion in other posts, I start to develop my simple trading system in C# and Microsoft SQL. I will use free virtual studio C# express 2010 and SQL Server 2008 R2 Express. I don't expect my database to be anything close to 10GB limit yet so it is fine for me for now.

    I will also create a live trading program with IB, but have to do a lot of backtesting first so backtesting is my focus first.

    So what is the correct structure of a simple backtesting? I cannot find any book seriously talk about it. I can only find out this blog talks about how to build one with excel:

    Designing and Developing a Simple Trading System part 1 - 5

    Any idea? Should I build the system like the example in excel blog so mainly write the test result in sql database?

    I can see there are some people develop their own system over here. Mine will not be anything close to HFT, would be something like from analysis 1 second data to daily data.

    I hope some of you will share, thanks!
  2. Most back testing structure I've seen is based on bars as units of calculation. For example, each bar is a data point that is used to calculate when to buy or sell.

    So if you are using the close of the bar as your price data, once each bar closes your program does the calculation again.

    Example eazylanguage ma crossover signal:

    if average(close,50) > average(close,200) then buy next bar at open;

    ......This will be slightly more involved in C because you will code the "average" function directly instead of calling from the program.

    The entire program structure is basically a for/next loop that reruns every time a new bar closes.
  3. j2ee


    I see, let's say I store a mini s&p future daily history data in a table in my database, then do I temporary store everything in an array? For your example, do I store even average (close,50) in a array, then store average (close,200) in another array, and store the buying signal in another array?

    Should I use array or linklist?

    I am using C#.
  4. I'm not a programmer by profession, so what little I know is from programming backtests on commercial platforms.

    But an array sounds like the way this would be done (trying to remember back from highschool electives & pascal programming classes). I think excel based backtests run as "stationary arrays" that "run" the back test as you pull down the cell box corner of the right most column.

    Funny story about programming in excel: we were doing fringe numerical method problems in engineering school with MATLAB, using methodz I can't even remember, and one of my study mates showed me how to solve the same problem (approximately, but very closely) by writing the array in excel, checking some menu box for "multiple calculations" and self-referencing all the cells. It set off this chain reaction and the solution was found in 1/10 the time compared to writing the MATLAB program....


    *edit - I just remembered how we could do this in MATLAB: you can use a delineated text file to store the data and call from the file as the program runs.
  5. dom993



    Your problem is you have no idea what you are doing. And how would you? You don't have any experience in automated trading. You are making this really impossible for yourself.

    Step back. Start using an existing platform, develop a few profitable strategies, in the process you'll learn quite a bit about what services a platform should provide. Then start trading live - on a simulated account of course, I recommend using IB sim account for that. And you'll learn some more doing that. At some point, you'll have a complete understanding of what an automated trading platform must offer to be viable.

  6. j2ee


    easy language is limited and i cannot do what i want with easy language. i can build a trading system that works but i want to know how to build with good structure to have good speed and effective OOP structure. Even someone is hired to work in ibank or trading system company, the job is very specific like just design the backend or front end of a big system, so technically almost no one has professional individual simple trading system build experience. Even excel is better than retail trading system out there because at least knowing the backtest is exactly what i design and it is precised. Backtest with retail software out there just give me the result, I don't even know how they calculate and does it precised, the biggest problem is still once I am not with normal common way of strategy that requires programming to build the strategy, easy language just never works or almost impossible to learn how to do with that easy language. It is pointless to be professional with an easy language, it is valueless in professional financial IT industry. Commonly only Java, C#, C++/C mean the most for programming language. Some people mention R but it is still very rarely in job market.
  7. Gizzz


    I think you need to create an algorithm, it is mostly looping over some time-span and some IF statements.

    SQL is neither needed nor efficient. Store the data in binary-files on SSD.

    edit: do you have data to work with?
  8. j2ee


    Thanks. What do you mean by time-span? Store the calculations step bye step with different array/linked list? Should I use array or linked list?
  9. dom993


    I agree C# is a much better choice than EasyLanguage, however you could use Ninja or MultiChart .NET or TradeLink and develop your strategies in C#.

    "Excel is better than retail trading system" is just as stupid as trying to develop your own platform. What makes money is the trading algo, not the platform, and this is where you should spend your energy.
  10. vicirek


    Read about structure or struct. This is a type that can be put in collections (queues, lists, sorted lists) or arrays to work from RAM or written to binary file on disk or if you prefer as text file after conversion.

    Your back test data has to be accessed somehow and most commonly it is by symbol and date/time stamp for each data point of your design. Your structure would group different types of data in one convenient type; for example O H L C or bid ask last fields as double, time stamp as datetime, tick, epoch, or string, also symbol plus reserve some additional fields for volume etc.

    Similar concepts would correspond to sql data storage and access with sql specific syntax.

    Once you have idea how your data will look like you can develop simple algorithm to work with the data which obviously involves iteration over array or collection plus some back test logic to obtain desirable result.

    If you want to start programming the best way is to do it the hard way and learn real language first by trial and error because using any of the easy way commercial platforms will leave you with very limited toolset. There is no other way of learning programming other than developing real application and you have chosen the hardest project which is trading application with live data stream in networked environment working with third party software, feeds and api.
    #10     May 11, 2013