risk management

In less of a Bayes haze…



No Comments

In a previous post we looked at the basic characteristics of Bayesian Statistics, and its possible applications in finance. In this entry we analyse a specific example involving stop loss levels, and implement a EURUSD exchange rate strategy.

Bayesian Inference example in finance.


This post aims to disperse any remaining Bayesian doubts and help you to better understand the inference in a financial setting.

What is the purpose of a stop loss strategy?

When we execute a trade, we obviously aim to make a profit. On occasions our bet may be wrong, and we end up in a losing position. When this occurs we want to avoid any further losses and so we close the open position. In a basic stop loss strategy, one would mark a level of permissible losses and define an exit level in terms of the trade entry price.

EURUSD Trade Stopped Out

For example, we enter in a short position in EURUSD at 1.3505 and we consider that a loss of 3% is sufficient to justify exiting a trade. The stop loss level is fixed at 1.3910 (=1.3505 x 1.03) and if we reach that level we have a guaranteed loss of 3%.

How does the Bayesian strategy differ to a basic one?

Principally it differs because the exit level is dynamic, not fixed. This means that our loss isn’t fixed, but varies depending on the place and timing of the exit. In fact, the idea is to lock in profits by adjusting the stop level. So, instead of losing from a trade we have slightly less profit than the best-case scenario. It is a trailing stop loss strategy; we modify our trade exit level recursively, according to newly observed market data. More technically, we update the posterior distribution methodically, taking into account the most recent data.

EURUSD Trade Trailing Stop_3

Imagine we enter a long position at the same entry price and we apply a dynamic stop loss level at 2%. After 1 month we reach the breakthrough point and we lock in a guaranteed profit from the trade. After 3.5 months we reach the stop loss level and exit with a 1.3% profit.

How do we implement the strategy?

Prior Distribution

On entering a new position, the first step in the strategy is to define a prior distribution describing where we expect the price to be after our chosen time horizon. This forecast can either be statistically derived, based on technical models, using other financial series and indicators. Or, less objectively, it can be based on an instinctive feeling that the market is moving in a certain direction.

However, we need more than just a single data point forecast to create a distribution. We should also account for our uncertainty in the price movement by means of probabilities. Imagine all the possible future price paths over the period. We can form the prior distribution with the probabilities of all the final price levels.

EURUSD MonteCarlo Paths

Defining one’s uncertainty in a forecast is not a straight forward task. Traders and analysts are notoriously poor at estimating extreme outcomes in finance. The distribution tails are usually a lot fatter than are accounted for. Simulation techniques and statistical analysis are particularly useful in this way because they remove bias and include unimaginable situations. Using these distribution types will improve accuracy in strategies.

Forecast Path

We have our ‘best guess’ of the spot price at the end of the period, but how did the spot get there? In this first step we must also define a path for the spot movement from the operation’s start until the end of the chosen time horizon.

There are many options. For example, at each date we could use the mean of all price paths and fix these means as our path. Alternative simpler options are using a fixed level set at the final point, or defining a linear path: on each date we move the same distance in the direction of the forecast point. In this example, the linear path is not dissimilar to the mean of all forecast paths.

EURUSD Forecast Paths_2

We use the path as a target for the real spot movements. If we expect the price to be at the forecasted level at the end, then the real spot shouldn’t deviate too much from our forecasted path. If, during the time horizon, the spot goes very off track, then the probabilities of reaching our target are reduced. This would be a signal to close the position and accept any current losses.

Updating to Posterior

Everything described up to now can be calculated at the moment of entering the trade. In the next steps, we include new future market data in the strategy when it becomes available. When we know the new spot level after each period of our trading frequency, we use it to decide whether the trade looks successful or not.

After the first period, we update the prior distribution with the most recent price movement to form a posterior distribution. In the following periods, the previous posterior distribution takes the place of the prior and we repeat the updating process with the newly available data. This is like us adjusting our forecast, except that it isn’t subjective. The method is now entirely statistical using Bayes’ theorem to update to a posterior distribution using observed data x and a prior distribution f(θ):

bayes theorem

We use the difference between the forecast path and the real spot to modify our estimate for the final spot level. The mean of the distribution is shifted and the uncertainty in the range of possible price levels is reduced. In other words, the distribution variance is smaller.EURUSD Updating to Posterior_2

As we observe in the diagram, this updating technique creates more certain posterior distributions represented by thinner curves (greater kurtosis). In other words, the forecast becomes clearer and we are more sure about the final price. In this case the mean of the distribution shifts to the right (upwards), mimicking the spot movement.

When to exit

For an automated strategy we need to define when the real spot path has deviated far enough away from the forecast path. There is no predefined rule and this again can take various forms. One possibility is to use the mean of the posterior distribution as the deciding factor. If it falls below the forecasted path then we cut our losses and close the open position. More conservative possibilities for exiting include recalculating the stop more frequently or using a greater limit for the decision point.

EURUSD UtoP Stopped Out_2

We modify the previous example and predict a 3% fall in the spot price but use the same prior variance. We are stopped out after 4 weeks. The decision point crosses the forecast path because the spot has moved far enough away from what we expected. We still lose almost 2% from this trade but it is better than the static 3% loss case.

The stop trade could be triggered by one large movement or after many small movements against your bet. It also works when the market moves laterally because the posterior distribution explains this uncertainty in the direction of the spot and helps to trigger the stop. This tends to be a weakness with typical trailing stop losses because the level is not updated and the longer the market moves horizontally the less likely it is for the trade to be profitable.

Test Strategy

We now implement this stop-loss strategy systematically over 14 years of the EURUSD exchange rate. The trades are based on technical models with good historic results. The forecasts are calculated as the market potential; what we expect to win with the trade over our chosen time horizon, 16 weeks in this case. We then create linear paths from the entry prices up to the price targets and compare these forecast paths to the real spot paths.EURUSD drawdown strategy 2000_2

The results are encouraging and the strategy does reduce losses. The annual rolling drawdown with the strategy is better (or the same) 76% of the time from 2000, with significant contributions in 2003, 2008 and 2009.

EURUSD Bayes SL Strategy 2000

The white areas in this graph are closed positions after a stop loss. We then wait for the opposite position to be signalled by our model once we have been stopped out of a trade. This is a deficiency of the current strategy, as there are many occasions where we lose out on large movements after volatile markets stop us out early (for example in 2005 and 2011).

This re-entry problem would have to be resolved and other technical details refined before using this method as part of a trading strategy. However, as a first approach this idea seems to be a promising way to reduce losses (and hence the risk) of a trading strategy.

add a comment