Skip to main contentMercury Labs

Metals Daily

Archie Norman
Archie Norman
Metals Daily brings together the latest global metal markets news, data and analysis, in a single platform. Mercury Labs worked specifically on a commodities trading algorithm.

Bringing together the latest global metal markets news, data and analysis. Metals Daily is the largest and fastest source of precious metals research and prices available. From real-time market data and news to in-depth analysis, Metals Daily has everything necessary to make informed decisions about the global metal markets.

Mercury Labs and Metals Daily built a commodities trading algorithm employs a variety of strategies to make reliable profits on the commodities exchange. Strategies are devised through the extensive technical analysis of historical data. This analysis can reveal opportunities to make profits that could work in the future.

The algorithm is dynamic and responds based on current market conditions and stimuli. By performing technical analysis using indicators on the recent and historical market movements, the algorithm can generate signals, which are triggers for action; an action such as buy, sell, or hold. The algorithm will determine how long to hold based on a mix of time and price factors.

Both the strategy chosen to fit the market conditions and its parameters are heavily optimised based on the data to return the most reliable profit, based on deviation from a linear equity. The algorithm runs entirely without human intervention and will make decisions faster than a human ever could. With the removal of human judgement and the implementation of well-devised and complex quantitative strategies, the algorithm returns considerable and reliable returns on investment.

Here we show a few example strategies. To evaluate reliability, the algorithm measures the deviation of the strategies from a linear equity increase.

The Moving Average Convergence/Divergence indicator makes use of two exponential moving averages (EMAs). EMAs are the same as moving averages but they value price points exponentially based on time, therefore newer price points are more significant in the average calculation, and older price points lose significance exponentially as they get older. The result is a moving average which adjusts to changes in price much faster than a regular moving average. This helps to stop lag in a volatile environment. The two EMAs used vary in their periods (the time window used in the calculation). The first is usually a period of 26 days and the second is usually a 12 day period. However, the parameters are left to the discretion of the trader. In between these two different lines, which can be thought of as the upper and lower bound, a 9 day EMA is plotted, which acts as the signal line (the period of this EMA is also modifiable). When the price crosses this signal line, it gives the signal to buy or sell the asset.

Bollinger Bands attempt to measure the volatility of an asset price by placing an upper and lower bound over a simple moving average (SMA), which typically has a 20-day period. The upper bound is 2 standard deviations above the SMA, and the lower bound is 2 standard deviations below, by default. Using standard deviations helps to recognise the magnitude of recent price changes and thus the volatility of an asset. By using Double Bollinger Bands, where the inner bands have standard deviations of 1, by default, rather than 2, helps to create buy and sell indicators for the algorithm when the SMA enters the area between the upper or lower bands.

SAR, or Parabolic SAR, is short for Stop-and-Reverse. This technical indicator highlights the direction an asset is moving, and the strength of that trend. The SAR strategy waits for a trend to ‘stop and reverse’ upon which buy or sell signals are generated to capitalise on this opportunity. It’s also an excellent mechanism for generating stop-loss orders.

Hilbert-Trendline Moving Averages are an advanced trend-detecting indicator. It makes use of the Hilbert-Transform mathematical operator. The aim is to remove lag and estimate real-time trending power. Price values are split into their complex number components of real (inPhase) and imaginary (quadrature) parts. These can be used, in turn, to calculate the period of the dominant cycle. The instantaneous trendline is then calculated and used to generate the signals.

The TradingStrategyPicker and SlidingWindow now analyses these strategies based on their deviation from a linear equity, aiming to choose the most reliable in terms of returns.

We developed a Trading Strategy Picker which analyses the trading strategies against historical data and returns the best strategy with optimised parameters. The picker uses two methods and the strategy returned depends on this. The first method is pick_le() which picks a strategy based on linear inequality. In this method, the data points are plotted with a simple linear regression. The R2 coefficient of determination is then calculated as a means of measuring the average deviation from the curve. A R2 close to 1 means there is little deviation, and an R2 closer to 0 means there is more deviation. Only a strategy that returns a high R2 value is considered viable in this method. This is a way of filtering out strategies that produce good returns, but only through chance/circumstances, and instead choosing a strategy that produces more reliable results based on the underlying quantitative analysis. On the other hand, pick_roi() picks the greatest return on investment without evaluating the linear regression.

We next developed a system that takes a list of strategies as parameters, a training window size, and a testing window size. With these parameters and the help of Trading Strategy Picker, it is able to emulate real-time trading. It begins by using a data set equivalent to the size of the training window. It calls Trading Strategy Picker on this dataset to find the best performing strategy out of the list it took as parameters. Once the strategy picker returns this ideal strategy, the Sliding Window Player simulates real-time trading with this strategy over a period of time equivalent to the testing window size parameter. When it reaches the end of the training window period, it calls the Trading Strategy picker again to re-evaluate the strategies based on the performance of the strategy in simulated live trading. This class allows the trading strategy picker to be adaptable to market conditions.