Metrics for Algorithmic Trading  [draft version, please report errors or suggestions, thanks]


In finance there are several metrics which can be applied to algorithmic trading as well. However, a trader may find more useful and intuitive, other, more specific, metrics, specifically designed for the context of automated trading systems and algorithmic trading.

The famous SDX (Signed Direction Index) and the other metrics described below have been proposed by Prof. Tom Gastaldi (and also implemented within G-Bot, the Algorithmical Platform project).


Summary of metrics on this page

- $peed
- Sideways %
- SDX - Signed Direction Index
- SCX - Signed Cointegration Index


 

Preliminary notes

 

Algorithmical reference system

The concept of "timeframe" is replaced by a reference system formed by gridlines. This is because an algorithmic trading system, to the purpose of decision taking, focuses mainly on price changes.

Imagine the price range subdivided in intervals of a given width (based on a prespecified percentage, for instance 0.1%).
Let's call the lines marking the intervals, "grid lines" (or "price grid lines").  The distance between 2 given adjacent price grid lines is called Gridsize and corresponds to a given amount called Gridvalue.

The grid line reference system is the base of all algorithmical trading system. Changing the grid value means expanding or shrinking our trading "timeframe" and our trading game, except that here our "clock" is defined solely based on price moves. For instance, the scalps could be defined in terms of a factor of the gridspacing.

Example (a grid of 0.1%):

PriceGrid
(Picture taken from G-Bot Algorithmic Platform)


Now we can define some metrics.


$ Speed (of the price) of an instrument
Alternate names: "$peed", absolute trailing speed

For an algorithmic trader, the concept of volatility (standard deviation of log returns) is somehow useful. However, a more specific concept can be defined, which is even more easily interpretable in an algorithmic trading context, and also can help better managing risk. The concept of "speed" also allows to introduce a "directional" component, which is not present in the volatility concept (volatility is simply the the standard deviation of the log returns).

The $peed of an instrument is, intuitively speaking, "the amount of money it travels in an hour". Let's see a more operative, algorithmical definition.

Definition and algorithm

As the price moves, the scalp lines will be "touched" (or "hit") by the price. We consider a list of k (for instance k=10) last hits, where a "hit" is defined as the pair:

                               Hit = (T, P)

where: T is the instant of the event, and P is the price of the grid line being hit.

A new Hit is inserted at the end of the list of hits only if it has a price different from the previous hit. If the total length of the list exceeds k, we remove the oldest entries, in order to keep fixed the maximum number k of items within the list.

Let's denote the Hit list as:

                            Hit(0) , .... , Hit(k-1)

Clearly, as the price moves, the hit list will be created dynamically, and when it reaches length k, its size is kept fixed, by removing the oldest entries.

Given the list of the Hits, we define (k-1) price changes, and (k-1) elapsed time intervals (expressed in hours), defined as follows:

S(i) = P(i) - P(i-1)    i= 1, ... , k-1

E(i) = T(i) - T(i-1)    i= 1, ... , k-1

the trailing speed is defined as follows:

                          (k - 1)
$peed  =   -----------------   *  Gridvalue
                   Sum of all E(i)

Note that the Speed value depends also on the two "parameters": the Gridsize and the number k of HitPoints in the list. These should be chosen appropriately, depending on your trading horizon.

The reason why the speed is measured on grid lines is because this allows us also to identify sideways and directional components, as we will see below.

Example:

Speeds of various instruments

($peeds of various instruments (futures): picture taken from G-Bot Algorithmic Platform)


Trending and Sideways %  (of the price) of an instrument
Alternate names: sideways percentage of speed, horizontal component of speed

When an instrument moves at a certain speed, its "trajectory" can develop mostly sideways, or it can be "trending" up or down. This percentage index expresses how much of the total speed of the instrument is expressed sideways. Clearly, the complement to 100 is the percentage of the speed expressed directionally.

Definition and algorithm

We decompose the total speed into 2 components: a sideways component and a directional component. Alternatively, we can say, an "horizontal" component and "vertical" component.

                                     Speed  =   Horizontal Speed + Vertical Speed      

where:

Horizontal Speed  = S * Speed 

Vertical Speed   =  V * Speed

with S + V = 1

 The vertical-component coefficient V is defined as:

             |  Sum (S(i)>0) of |S(i)| - Sum (S(i)<0) of |S(i)|   |
V  =  ------------------------------------------------------
                                  Sum of all |S(i)|

Given the vertical speed, we can obtain the horizontal speed by difference:

          Horizontal Speed  =  Speed   - Vertical Speed

Finally, the Trending and Sideways percentages are defined as:

                              Vertical Speed
Trending %    =  -----------------------    * 100
                                   Speed  

                               Horizontal Speed
Sideways %    =  -----------------------    * 100
                                   Speed  

Example:

[picture to be inserted]

 



SDX - Signed Direction Index (of the price) of an instrument


The V coefficient of the directional component, taken with its sign, is a good metric to indicate the direction and momentum of the price of an instrument:

                                Sum (S(i)>0) of |S(i)| - Sum (S(i)<0) of |S(i)|
SDX = 100 *      ---------------------------------------------------
                                                     Sum of all |S(i)|


it ranges between -100 ("trend" downward) and 100 ("trend" upward). Values (positive or negative) near 0, indicate a condition of "sideways" market.

 

Weighted version

A weighted version can also be considered, by assigning different (positive) weights w(i) to the consecutive moves S(i):

                                Sum (S(i)>0) of |S(i) w(i)| - Sum (S(i)<0) of |S(i) w(i) |
SDXw = 100 *   ---------------------------------------------------------------
                                                     Sum of all |S(i) w(i)|

 

Example. SDX for various instruments

SDX examples


 

Relationships between the above concepts

From the definitions, one may notice that :

Trending %   =  | SDX |

Sideways %   =  100 - | SDX |

As it is intuitive, the trending percentage is given by the absolute value of the signed direction index.

 

Notes

From the definition, one may notice that the SDX will only take a finite set of values. So take this into account if using it. For instance (for the unweighted version):

6  : { -100.00 -60.00 -20.00 20.00 60.00 100.00 }
7  : { -100.00 -66.67 -33.33 0.00 33.33 66.67 100.00 }
8  : { -100.00 -71.43 -42.86 -14.29 14.29 42.86 71.43 100.00 }
9  : { -100.00 -75.00 -50.00 -25.00 0.00 25.00 50.00 75.00 100.00 }
10 : { -100.00 -77.78 -55.56 -33.33 -11.11 11.11 33.33 55.56 77.78 100.00 }
11 : { -100.00 -80.00 -60.00 -40.00 -20.00 0.00 20.00 40.00 60.00 80.00 100.00 }



SCX - Signed Cointegration Index (for a pair of instruments)

One fundamental (and rather persistent) aspect in the market is the tendency of some instruments to "track each other" ("positively" or "negatively").  This can result in price curves which "look" essentially the same (example ES and YM) or that are essentially "specular" (e.g., UB and YM).

Sometimes we hear talking about positive or negative "correlation" between instruments. 
In statistics, the "correlation coefficient" is a measure of "linear" correlation.

Here I introduce a simple index to measure the tendency of two price curves to look like the same (index = 1) or to be a mirror image of each other (index = -1).

So, I define such cointegration index as follows.
Consider, for each of 2 instruments, a truncated sequence of k last prices taken at an interval of T minutes. We consider a list of k (for instance k=96) last prices, each one recorded every 30 minutes. Each time, a new price is inserted at the end of the list of prices. If the total length of the list exceeds k, we remove the oldest entries, in order to keep fixed the maximum number k of items in the list.

Denote these 2 lists (the recording times are the same for the two lists) as:

P1(0), P1(1),   ... , P1(k-1),    (for Instrument 1)

P2(0), P2(1),   ... , P2(k-1),   (for Instrument 2)

A simple, but effective, cointegration index, ranging in the interval [-1, 1] can be obtained as:

                   Sum of ( sign( P1(i) - P1(i-1) ) * sign( P2(i) - P2(i-1) ) )
SCX = --------------------------------------------------------------------
                                            k - 1

This index will range between -1 and 1. A value of 1 means perfect "cointegration" (they "track each other"); -1 is also a perfect (negative) cointegration. Values near 0 will indicate situations where the 2 instruments are, say, in no cointegration relation:

-1 ("specular" shapes)  -------- 0 (no cointegration) --------- 1 (similar shapes)

(The obvious reason why I only consider the sign of the corresponding increments is to make the index more "robust" and insensitive to absolute spread variations, gaps, structural changes, etc.)


Example. SCX for various pairs of instruments

CointegrationIndex

 

For this index too, one might consider an obvious "weigheted" version.

A possible useful application of this index is are low risk and powerful  arbitrage algorithms or pair trading (Clearly, in such a case, we will also need to appropriately determine the relative direction of each instrument w.r.t. the other one, which is pretty simple to do.)

 

G-Bot site::

G-BOTHome