Back testing key concepts

This topic contains 0 replies, has 1 voice, and was last updated by Seer Seer 8 years, 3 months ago.

Viewing 1 post (of 1 total)
  • Author
  • #529

    In this section we’ll focus on the key concepts that you’ll need to understand when building and backtesting trading systems with Seer. You’ll be introduced to important concepts such as eventscolumnsbarsback and heartbeats. Once you’ve understood these concepts, you’ll find Seer easy to develop with!


    The real world is event driven

    Seer uses event-driven programming model. When you write logic for your trading system you are writing logic and rules that responds to an event.

    But what actually is an Event?

    Traditional programming logic follows it’s own control flow, while event-driven programmes respond to some external action. For example, in a graphical user interface, an event is generated when the user clicks the mouse button or presses a key on the keyboard. It’s the job of the running application to respond to these events.

    Event programming is a better way to model the real world as it simplifies the logic that is needed to respond to actual action in real-time. Trading can be broken down into events such as the close of a bar or the filling of an order.

    The traditional backtesting approach will iterate (loop through) all the bars in the backtesting period. While in an event driven environment an event is generated for each bar in the backtesting period. As your logic is written to respond to an event, rather than in a loop, your trading system is easily deployable in real-time operation as it models the real-world.

    Each event allows you to attach some Seerscript that is executed when the event is triggered. To see a diagram of how the events are triggered, see event execution order in the Seerscript Reference.


    Time Series Data and the Column

    Time series data in the context of trading is the price data of the underlying instrument collected over time. The processing of this time series data enables all technical analysis. Other common terms for describing time series data include vector and array processing.

    The diagram below shows time series data for a stock displayed in a spreadsheet.

    As you can see in this diagram, each row shows all the price points (Open, High, Low, Close and Volume) for a specific date time. Each column shows a single price point, as it changes over time.

    At first glance it might seem that interacting with a row would be more logical than interacting with a column, but this is not the case. For example, if you wanted to calculate and plot a simple moving average of the Close price point, you would use all the price points of the Close column.

    Within Seer, the Column is used to encompass the whole series of data for a single price point such as Close or Volume. Conceptually, the view presented in a spreadsheet of time series data is a good representation of how Seer handles the data internally. The column headings, DateTime, Open, High, Low, Close and Volume are all Seer columns which you then use with indicators, charts and trading systems. For example, to create an 8 bar simple moving average of the close you would use:



    And to plot a 8 bar simple moving average of the close you would use:



    In the above Seerscript example we are calling the SMA indicator, and passing the Close column and the number of bars we want the simple moving average to be based upon. The SMA indicator returns a new column with, with all cells populated with the correct values.

    What if you want to access a single value in time series data rather than a whole column? For example, if you wanted to access the data for the close on the 3rd of July, you would use cell D3 in the spreadsheet.

    Before we explain how we do this in Seer, consider one important point. If you add the time series data for the 6th of July to the spreadsheet, would D3 be still the value you want? As all the data would be shifted down by one row, D3 now holds a different value. In reality, D3 may or may not contain the value you want, as it depends on the context of what you want. In Seer, this context is always based upon the latest bar, and all accesses of a column are relative to this bar.


    Events and Columns working together

    The concept of an event and the column working together are integral to how Seer works.

    For example, lets take a simple five bar backtest from the 10th of October to the 14th of October, with 3 simple statements:



    As you can probably guess, Now(Close) returns the value of the close of the current bar, while Ago returns the value of the bar X bars ago. Both Now and Ago work on a relative basis to the last bar.

    In the diagram above, you can see the values change as a new event is generated (the close of each new bar).

    As logic is run in the context of the event, it can be run in a backtesting or live context with equal validity, at any time frame. Although the above logic is running on daily bars, it can be run on weekly bars, 5-minute bars or 89 tick bars by simply changing the time when the events are generated.

    As the bar event can effectively be triggered at any time frame you have to tell what time frame you want Seer to beat at. This setting is called the heartbeat and is set in the trading system object. The heartbeat beats at a set timeframe, such as Day, Hour, TenMinutes or even a time frame that you’ve defined yourself.

    In the above example you’ll also notice that for bar 1, there are two previous bars – the 6th and 7th of October. These bars are included as they are needed by the backtest – specifically by Ago(Close,2). This requirement for including bars before the first event is acted upon is called barsback. In this example, the barsback requirement is 2 bars, with the default being 45 bars. This value is set manually via the Time Frame object that’s associated with the system heartbeat.

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.