Popular Posts

Editor'S Choice - 2020

Basket Trading or How to Find and Trade Dependency Instruments

Good afternoon, friends forex traders!

In continuation of the topic of arbitration, today we will consider the option of portfolio trading - “basketball trading”. Unlike pair trading, basketball trading involves trading a whole basket of interconnected instruments. The main advantage of this method is the creation of a market-neutral portfolio that allows you to earn on any market condition, regardless of its specific direction.

Portfolio trading is fundamentally different from traditional trading strategies. It is usually customary to create a strategy for a tool, taking into account its features. We will take the return path - try to create a new tool that has ideal characteristics for our strategy.

Perfect portfolio

The easiest way to build a portfolio is to assemble a group of undervalued instruments based on their growth. It can be stocks, currency pairs, investment accounts and, in general, anything. One such example is Warren Buffett's portfolio. In general, many indices can be attributed to examples, the composition of which periodically changes to maintain the growth of the curve.

We can say that the arbitrage portfolio is a separate synthetic tool to which you can give any desired characteristics. Imagine that you have a chance to create your own trading instrument of arbitrary nature, what will its chart look like?

I think you will want to create an instrument that will be easiest to trade. For example, an instrument that is constantly in the channel, or an instrument whose graph is constantly growing. That is, not a strategy adapts to a tool, but rather, a tool to a strategy.

Trading such a portfolio is extremely simple. In such conditions, even a knowingly unprofitable martingale will work, since we will always know that the price will surely return to the average.

We can get a similar graph by subtracting its moving average from the price of the instrument. That is, the price of the instrument + its average represents an ideal market-neutral portfolio. The problem is that we cannot trade medium.

Here we come to one important point. Our task is not to create beautiful schedule, and find real relationships tools. If the instruments are in no way connected, the portfolio will immediately crumble outside the testing interval, and goodbye to market neutrality. On the other hand, a beautiful schedule may well be evidence of an interconnectedness, and this is also worth considering.

However, the only true way to create a co-integrated portfolio has not yet been invented, since it is unclear how, in fact, to find the very underlying relationships. In the example of pair trading between EURUSD and GBPUSD, we determined the dependence of two currency pairs using Pearson's correlation. Now the task is getting more complicated - we need to determine the relationship between several tools.

Recycle Complex

Set of indicatorsRecycle furthest than anyone else in solving the problem of finding the perfect asset portfolio. The program receives an arbitrary number of time series (currency pairs, stocks, indices ...) and gives a ready-made portfolio with the smallest dispersion (the narrowest schedule). In other words, by adjusting the share of each instrument in the portfolio, we get the flattest possible chart. Why do we need this?

Let's remember once again how to get a market neutral position by trading two interdependent instruments. So, we have two trading instruments with similar charts (the name of the instrument does not matter):

As you can see, the charts of the instruments move in concert, but in different directions. Thus, if we simultaneously open two positions of the same direction, the graph of total profit will be a straight line. That is, regardless of the direction of the market, the equity of the overall position will always be near zero. A set of Recycle indicators solves the same problem, but simultaneously with a bundle of tools.

In total, the kit includes several routines:

  • Recycle2 - directly an indicator showing the dynamics of the synthetics and the values ​​of correlation coefficients (relationship values) in the portfolio;
  • RecycleShadow2 - an additional adviser that allows you to watch the synthetics dynamics on history (run before Recycle2);
  • RecycleHistory - a script for swapping history. It is necessary to display the past history of the instrument (can be launched at any time);
  • RecycleProfit - displays the spread dynamics in money. This chart can be guided in calculating potential profits. Also in this window settlement lots are shown for creating a neutral position.

Preparation for work

First, download and open the archive attached to the article - there are source code files for three software packages. We are interested in the Recycle 2 folder.

Next, you need to open the terminal data directory. This is done through File - Open the data directory.

Now, in the window that opens, you need to transfer the files from the "Recycle 2" directory.

To display the synthetics graph on a story, you first need to run EXP_RecycleShadow2. Without it, only the value of the current bar will be calculated.

After that, launch Recycle itself.

The main parameters of the Recycle indicator:

  • SymbolStr - a list of tools (separated by commas) for calculating synthetics. As instruments, it makes sense to indicate only major pairs or any instruments that do not have a strict mathematical dependence. That is, it does not make sense to specify crosses to search for dependencies;
  • Depth - number of bars for synthetics calculation;
  • Method - a way to build synthetics. Method number 4 is considered the most optimal.

For example, running Recycle for the EURUSD, GBPUSD and USDCHF instruments will give you a similar picture. Recycle immediately distributed the weighting coefficients between the portfolio instruments for the indicated period (Depth), however, a synthetic dynamics chart in the past is still not available.

To load historical data on the chart, you need to add an auxiliary script SCR_RecycleHistory2. The script has only one parameter - from what date to load the history. If the story is already loaded, the synthetic chart will appear instantly (red line). This line reflects the dynamics of our synthetic instrument.

It is worth considering that the specificity of the algorithm makes it easy to find direct relationships between instruments - the screen shows the equal distribution of capital between EURUSD, GBPUSD and EURGBP. Due to the fact that there is a direct relationship between the three instruments, that is, the course of any of them can be easily calculated from the other two (for example: EURGBP = EURUSD / GBPUSD), the capital was evenly distributed between the pairs of the triangle, leaving nothing to the rest.

That is why it makes no sense to indicate cross-rates as tools, since they are easy to calculate from major pairs. That is, a portfolio of two majors and their cross-country will be the narrowest of the possible ones, but this is the topic of classical arbitration, and not statistical dependence.

So, having received the perfect flat portfolio at the testing stage, our work does not end there. In order for the portfolio to maintain cointegration, that is, the ability to return to zero, it must be periodically re-optimized.

In other words, it is necessary to periodically recount the shares of instruments in the portfolio, again bringing the synthetics chart to a “channel” form. Of course, for this you need to adjust the existing position in the market. That is, if the share of the instrument decreased from 0.5 to 0.1 lots, to bring the synthetics to balance it is necessary to close 0.4 lots of the current position.

But, again, frequent adjustment of the overall position is extremely undesirable, since the trading costs of opening and closing orders can eat up all the profit from, directly, arbitrage operations.

It turns out that we need to find a portfolio whose elements, firstly, have a high degree of dependence, and secondly, the dependencies themselves remain valid for a long period of time. To do this, try to build a portfolio of different groups of tools, checking the stability of the scales over a relatively long section of history.

How to trade

Recycle. To repeat the chart of the resulting portfolio, just open the positions of the specified size (in the RecycleProfit window) for all instruments. Equity of received positions will correspond to the schedule of our synthetic instrument. Such an operation would be equivalent to buying an instrument. For the sale of synthetics, the position must be turned over.

For example, we pointed to the entry of 3 instruments: EURUSD, GBPUSD and AUDUSD. According to the calculation results, AUDUSD has the least impact in the portfolio - it accounts for the least amount of capital. To buy the synthetics we need to sell 0.34 lots at EURUSD, 0.18 lots at AUDUSD and buy 0.35 lots at GBPUSD. The main thing here is to maintain proportions; in fact, the number of lots can be any.

Since we initially set the task of creating the maximum flat portfolio, the essence of trade is extremely simple - we buy cheap, we sell expensive. That is, a strategy similar to trading from the borders of the channel. Beyond the boundaries of the channel, you can take the size of the standard deviation (blue lines on the Recycle chart) or Bollinger Bands.

In addition to Recycle, there are other works that solve similar problems. Therefore, further briefly consider similar projects from other authors.

PCA Synthetics. In essence, this is an attempt to port the Recycle indicator for the MT5 terminal called PCA Synthetics. The indicator solves a similar problem - the creation of a new synthetic tool based on time series data with the smallest total dispersion, that is, the creation of a co-integrated portfolio.

In the upper right corner of the indicator, the tools are sorted by weight. To buy synthetics, we buy currency with a positive coefficient and sell it with a negative one. For sale - vice versa.

Indicator Parameters:

  • InpVector - takes values ​​from 0 to N-1 (N = number of characters). The larger the value, the smaller the variance of the portfolio;
  • InpFrame - size of a floating window for calculating synthetics;
  • InpDepth - history depth for calculation;
  • InpForward - forward period for checking stability of optimized coefficients;
  • InpMaPeriod - smoothing period;
  • InpTimePeriod - source timeframe;
  • InpSynthetics - drawing each pair in a separate line;
  • InpPrices - a way to normalize values;
  • InpSymbols - tools for a co-integrated portfolio;
  • InpMagic - indicator name to simplify identification on the chart.

Portfolio Modeller. The indicator solves a problem similar to Recycle, allowing you to build a co-integrated portfolio of tools. To build a portfolio, run Portfolio Modeller and the list of tools is indicated in the Basis_Formula field (separated by a space).

The size of positions to open is displayed in the upper left corner of the indicator window.

The indicator is paired with the Portfolio Manager Expert Advisor. Run the adviser and specify the desired portfolio name in the Portfolio_Name column. Buttons for trading will appear in the upper right corner of the indicator. The BUY and SELL buttons simultaneously open positions of the required size for all instruments, and CLOSE closes the portfolio position. In this case, the opening of the portfolio position occurs in a semi-automatic mode.


Despite the great potential of the technique, the search for stable statistical dependencies on popular forex tools is unlikely to succeed. Nevertheless, a sufficiently stable synthetics can be created from instruments of different markets, for example, stocks, traditional currencies and cryptocurrencies. Many market dependencies remain unknown and this is a big topic for independent research.

Download Recycle Kit

Instructions for installing indicators in MT4
Instructions for installing indicators in MT5

Watch the video: How can I use correlation to benefit my portfolio? (February 2020).

Leave Your Comment