Backtest Mode

What is the backtesting about?

Backtest allows you to verify properties of your trading strategies basing on historic market data. All you need to test your strategy is file with recorded exchange sessions of some instrument. Empirica Suite supports files of intraday and tick data data types. These are the most common and widely available formats among providers of historical exchange data. Order book data type is not supported in demo version.

Example backtest results in Empirica Suite

Despite the fact that during backtesting you cannot directly simulate market influence of strategy’s orders, this form of offline strategies’ verification is considered as most reliable. Firstly, it bases on real market history. Secondly, it is powerful – informations obtained from backtest allow our software to calculate canonic statistics which estimate strategy’s risk & potential. Set of such statistics can be further extended in many ways. Moreover, backtesting is very scalable. Depending on data granulation in your historical files and your will – TradePad is able both: to track results of long period strategy’s flow or focus on strategy’s behaviour during short, critical market events. Finally, probably the biggest advantage of backtesting is that they are repeatable. That gives you the unique ability to run your strategy concept on the same historical data multiple times with various initial parameters and it will always receive the same sequence of exchange events. This way you can precisely compare parameters’ influence on strategy’s performance in selected scenario to find the most proper ones.

Entering the backtest mode in TradePad

To enter the backtest mode you need to select mode: BACKTEST in the Menu & tool bar:

Entrance to BACKTEST mode

Most of frames you can see now should be familiar. Backtest in Empirica Suite is designed to be as similar to other modes as possible – just to enable you to work with it without tentativeness. However you can notice two frames characteristic for this mode:

Backtest Data Manager

Backtest Data Manager frame

This frame allows you to import and then manage all available backtest files data. This process is described in section Backtest data management.

Backtest Manager

Backtest Manager frame

This is playlist creator. Here you can choose from previously prepared data files and compose your backtest. Preparation of backtest execution section provides more details.

In TradePad backtest mode every single strategy creation invokes backtest process to begin. Progress of execution is visible in strategy’s frame.

Work with backtest

Importing backtest data from raw files

When you obtained some raw data file in text-based format first thing to do is to import it into TradePad. You can do it via Backtest Data Manager. Click Import... button to see Backtest File Importer frame.

Backtest File Importer frame

In this place you can adjust source and settings of data import in the universal way.

  1. First click the Browse... button to find and choose the historical data file you want to import.
  2. Then adjust basic settings like data type, delimiter, date & time formats used in the file.
  3. Choose what granulation and preciseness of data you need by setting data interval and price precision values.
  4. Decide if currently imported data should overwrite already existing one. If you allow for this, if there exists such backtest data of the same instrument, exchange and interval, the intersecting part will be overwritten.
  5. If the first line of file (you can peek it in Input first line section below) contains column headers, you should omit it to properly parse file.
  6. Data providers offer files with variously ordered data fields, therefore in section Map input data you are able to define proper meaning of values for all lines.
  7. List of fields is characteristic to the data type. Not every data file contains all fields essential for proper import to Empirica Suite, like exchange or instrument name – in such case you can define it manually in Define fields section.
  8. Click Import button and wait until import is finished.

Basing on user’s adjustments TradePad automatically parses whole file and creates new data entry in Backtest Data Manager. Now your newly obtained backtest data is ready to be used. Remember that files that are being imported should have data entries ordered by time-stamp, in other case it might be not fully imported for safety and integrity reasons.

Additionally, if you have more files of the same format, you can save your adjustments as an preset by clicking floppy disc icon Floppy Disc Icon in the bottom-left corner of Backtest File Importer. This will help to avoid repeating already done work again in the future. When you already have some saved presets you can just select one of them, choose a new data file and import new data quickly.

Backtest data management

When you have already imported data into TradePad, in Backtest Data Manager frame you can model it.

Tradepad allows you to precisely adjust backtest session data to your needs. Backtest Data Manager frame is divided into two sections. First – general one – presents you list of already imported instruments with additional data about exchanges, timespan and data format. In this section you can require to import or delete data. Importing data from raw files is described above, in section Importing backtest data from raw files.

When you select one of imported instruments in the table, section below is being filled with instrument’s data divided into daily files. Again, you can select and delete any daily files you want to.

Preparation of backtest execution

When you have already organized instruments’ data, you can prepare your “backtest playlist” - subset of all available data that will be processed during the backtesting. After clicking Add... button you will see dialog that allows you to choose any of previously prepared instruments, decide which period you are interested with and include it to the playlist.

Selecting owned instruments data to backtest

Empirica Suite allows you to add multiple instruments of various periods and process them in parallel to test multi-instrumental strategies like arbitrage.

Chart of multiple backtest files ran simultaneously in single backtest

To single backtest playlist you can add only these data files that have the same interval and data type.

Running & backtesting strategy

To backtest a strategy you need to deploy it into TradePad first. You can read detailed description of strategies’ management in Strategies chapter. Choose one of deployed strategies from User’s Strategies frame.

Strategy’s frame is quite universal for all modes. It is well described in Strategy frame common elements. Choosing your strategy’s test parameters & imported instrument data you want to use in backtest is identical like setting strategy in LIVE/SIMULATED EXCHANGE modes. If you like to assume that your initial capital or risk free rate are different than default – you can set them too, but in Statistics tab. See Initial values of Statistics for further information.

When you already prepared your strategy to run – you may click Start button that begins backtest. Calculation’s progress is visible on progress bar in the bottom of strategy’s frame. After the backtest ends you may enter the Statistics tab once again and see all statistics that could been calculated. Statistics chapter provides definition of all calculated statistics and more detailed description of view concerning them.

Also, Chart tab can provide useful information. You can observe instruments’ price charts and strategy buy/sell actions when backtest is done.

Chart presenting strategy's flow during backtest

By selecting a rectangle with cursor in the chart it is possible to zoom marked period. To zoom in start select a rectangle moving the cursor from left to right. Zoom out to initial time span may be done by moving mouse in the opposite way during selection.

In BACKTEST mode chart is being drawn exactly like in any other one: since strategy’s creation to its end. Therefore charts of strategies with stop condition (ex. time-restricted ones) are drawn not to the end of longest backtest data, but only to the end of strategy’s flow.

You may decide that you want to check the same strategy and data again, but with some changed parameters. Just click Rerun... after backtest ends – all data previous is preserved and you can adjust parameters and test strategy again. You are also able to stop strategy manually in any time while backtesting too – but its progress will be then incomplete.

Backtest optimization

Sometimes it is very difficult to predict the best parameter’s value or its domain is potentially huge. Empirica Suite supports you then with strategy optimization. In the bottom of Strategy Frame you can notice an Optimize... button. Backtest Optimizer is a kind of automate that runs selected strategy for all possible parameters’ values from bounds you have restricted. Because of that, it is not recommended to run optimization with massive bounds - it may drastically affect the system performance.

Optimization frame

Setup general parameters like strategy, initial capital and risk free rate. Then choose an instrument and portfolio, exactly like in single strategy. Before start you should only decide which parameters will be fixed during all startegy iterations (unmarked check-box Optimize next to parameter’s name) and which will be optimized (marked checkbox Optimize). You can set static values of fixed parameters or define bounds and iteration step of optimized ones.

After Start... button is clicked backtest optimizer begins to iterate over all combinations of parameters – it runs backtest feed multiple times and during each data flow tests strategy with various parameters in parallel. Optimization provides statistics values for all strategy’s runs with valid initial parameters. Quick brief of them is visible in Backtest Result section (empty rows means that strategy for specific parameters did not start properly). By double-clicking any row of backtest Result table you can open Strategy Frame of pointed, finished strategy simulation – this is a standard Strategy Frame (described in Strategies chapter), so you can analyze all statistics, chart and logger.

After all optimization finished, you can compare strategy runs basing on calculated parameters results. Export CSV... button allows you to export optimization data in spreadsheet programs-friendly CSV format. It is possible to save optimization’s result by pressing Save results... button. It can be loaded by selecting File\Open optimization result inside menu. You can also quickly rerun backtest adjusting parameters again.