As we said in our previous article, we can classify trading systems into two groups: those based on models and those based on exploitation or data mining.

In this article we will discuss in detail the systems of the first type, defined as those who propose a model to represent the behavior of the market and from it, try to get benefits.

The algorithms that are part of this group are usually very simple in terms of the rules they use, although its development is usually relatively complex depending on the algorithm. The starting point of the models used for this type of strategy is the detection of a **market inefficiency** we want to exploit. Inefficiency produces an anomaly or a pattern on the price that can be described using a mathematical model that allows us to predict to some extent where the price will be in the next period based on a function based on historical price information.Let’s look at some of the most common strategies based on models.

## Trends

Probably the trend in the price curve is the most significant and most exploited anomaly. We can define what is the trend in a simple form as a kind of momentum or inertia which remains in the price movement once it starts. This type of inertia is not presented in price curves whose behavior is represented by a **random walk process**.

There are many methods to try to detect the trend, although the most common are those which are based on **moving averages**. The problem is that these kinds of methods always end up failing because the use of moving averages can not distinguish what is a real trend of a random succession of peaks and valleys within a price curve.

**The reason is obvious: **the trend is not present in the market all the time. Any assets traded in markets can have long periods without trend. Even within a random walk we can find brief movements upward and downward and still not have any trend. That is why in this type of strategy is always necessary to have a good filter that detects the market regime in which we are to enable or disable the strategy if there is no trend in the market.

## Reversion to the mean

In the case of models based on mean reversion, we assume that there is a “fair price” for the analyzed asset, so we will buy when the market price falls below the estimated level and sell when the price it is above the measured value. If the model is correct, the price should return to its average more often than in a random walk. The fact is that a series of random numbers will revert to its mean with a probability of 75% so any probability above that level will be considered a market inefficiency.

One way to model such mean reversion processes would be:

**y**= Price in period i

**y^**= fair price of the asset. It can be represented for example by a mean.

**λ**= Half-life factor

**εt**= Term of random noise

The larger λ, the weaker the reversion to the mean. In general, λ has a value between 50 and 200, understanding that value as the number of bars or periods that takes the price to revert to the mean. For a more accurate value of λ we can perform a simple linear regression between **yt-1** and **(yt-1 – y^)**.

We have other examples with the **transformation of Fisher**, which generates a series without trend bounded between -1 and +1, and **Hurst exponent** (on which I have pending an article by the way), which tells us that we are in a process to reverts to the mean when its value is below 0.5.

In any case, the idea is always the same: eliminate the trend in prices and normalize the result, generating an oscillatory process that will trigger purchases when you reach the minimum sales thereof and when the top is reached.

## Statistical Arbitration

Where **y1** and **y2** are the prices of both assets and factors **h1** and **h2** are their coverage ratios. These ratios are calculated such that the difference obtained, ** y**, is equal to zero or to a constant value. The calculation of these factors is performed by a linear regression between

**y1**and

**y2**. Subsequently a strategy of reversion to the mean is applied over the resulting difference,

**.**

*y*The problem with these models is that if ** y** is not stationary (ie, its average tends to change over time), coverage ratios should be adjusted in real time to compensate for the displacement using advanced mathematical methods such as

**Kalman**

**filter**.

## Restrictions on Price

A restriction in the price is the result of an artificial force causing a constant drift in the price or sets a range, floor or ceiling fixed price. The most famous example of this is probably known to all our readers: the floor set by the **SNB **in EUR/CHF, whose removal caused the catastrophic consequences we all know. But to date price restrictions still exist in other currency pairs and assets of other classes.

All these interventions in the markets can be harnessed using simple models of reversion to the mean, however we should have implemented excellent mechanisms of risk management and contingency plans for a possible situation of little or no liquidity, if the hand “**holding the market**“decides to retire.

### Market cycles

The presence of cycles in the price curve is generated by feedback, particularly when a large number of traders are synchronized because they believe that there is a “**fair price**” in an asset, so that they trade in a “**reversal to the average mode**“, buying and selling based on the distance at which the price is located from that fair price. This causes oscillations with a fixed period that is maintained over a period.

We can mathematically represent this behavior by an equation as follows:

*Ci*is the cycle period and

*Di*the dominant cycle phase. If we estimate these values we can calculate the optimal points of entry and exit while the cycle is maintained.

The methods used in these cases to detect cycles and calculate the parameters *Ci *and *Di* are somewhat more complex, including **Fourier transformations** and lowpass filters.

The big problem that can be found when analyzing price series looking for cycles is that apparently their period is not linear (ie not constant) which tremendously complicates its estimate and therefore its application in trading.

## Clusters or Groups

The same effect that causes prices to oscillate can also create clusters or groups of orders at certain price levels, which allows to explain the appearance of demand and supply zones (that is, what we generally term as **support **and **resistance**).

However, although everyone is able to draw horizontal lines marking support and resistance on the charts, as far as I know there are virtually no strategies that are able to exploit profitably these levels all the time. The most interesting can be found in the use of price frequency histograms(commonly known as **Market Profile**) although its analysis is not exactly simple.

## Price patterns

The emergence of patterns in the price curve is derived from the repetitive behavior of traders. Indeed, I dare say that these formations are not only caused by the behavior itself, but by the belief that such behavior exist that fed back to the potential pattern.While there are many myths about it (the famous chartists patterns as the well known Head and Shoulders or other like** wedges** or **triangles**), the truth is that so far nobody has been able to prove statistically that these patterns allow to obtain an advantage in the market, largely due to the difficulty of their programming.Anyway, if you want to look for patterns in price curves rigorously (please, no viewing the price chart visually, because the risk of becoming victims of your own mind), it is best to use **algorithms based on Fréchet distance**, as it allows us to compare price series with ideal patterns to determine their similarity.

## Seasonality in markets

The behavior of supply and demand can also show patterns that occur regularly in time, so they can be detected and exploited by strategies. A typical example of this type of behavior is the famous pattern of the last and first day of the month or the yen’s rise in spring repatriation of profits by Japanese companies.To find these types of inefficiencies, ideally traders shoud represent daily, weekly and monthly average return and compare the results to see whether there is a statistically significant difference in one day, week or month.

The big problem of seasonality is that they are easy to detect patterns so they really last very short time on the market, something that makes sense. If you know that everyone does the same in one point of time and there are people who take advantage of it, then you will end up imitating that behavior for the same reason, to make money. Well, that’s what ends up with the usefulness of a seasonal pattern.

## Price gaps

As we know, in some ocassions there are discontinuities in the price curcer, commonly referred to as price gaps. Such discontinuities occur because traders have changed their thinking on the market during the period of time when the market has been closed. **But is it possible to exploit the gaps to create a strategy?** Apparently yes, there are many strategies consistently profitable, but require considerable patience. One is known as **One Night Stand System of Joe Krutsinger**, in which you get benefits from the gaps that occur on weekends in the Forex market. You can see the rules of the strategy and results through 2007 here. The explanation of why this strategy works seems to be that the traders of the Forex market are reluctant to hold positions over the weekend and therefore prefer to close positions on Friday and reopen on Sunday night which produces a variation in prices.

## Autoregression and Heteroscedasticity

No doubt words widely used in the argot of the quant traders. Basically the idea behind these terms is that prices oscillates and magnitude of the oscillations vary over time (ie, the price is variable in variance, so it is not constant).In mathematical terms, the ARIMA (autoregressive) and GARCH (heteroskedasticity) models start with the assumption that it is possible to predict, respectively, yields or future volatility through a linear combination of past returns or volatilities.While these models require some advanced mathematical knowledge, the truth is that combining them seems possible to find promising opportunities as you can see in this **excellent post** on the QuantStart blog which show the application of these models to the** S&P 500**. In any case, when using these models traders should not forget that the series used are stationary in mean and variance and before applying them the correlogram of the series must be examined to determine whether these models are appropriate. On these models if there is interest I will write an article in the coming weeks.After analyzing trading systems based on models in a future article we will continue with trading systems based on data mining.