Blog

Algorithmic Trading: A Quantitative Approach to Developing an Automated Trading System

Written by: Luqman-nul Hakim B M Lukman, Justin Yeo Shui Ming

Abstract: In “Flash Boys: A Wall Street Revolt”, Lewis wrote “The market is rigged” by HFT traders who front run orders placed by investors. Indeed, if makers cannot win by getting a good price, they will win by speed. In this paper, we focus on the foreign exchange market. Although they are OTC markets where each brokers managed their inventory separately and as such each quoting a slightly different bid-ask spread, an emerging trend is that more brokers are providing ECN accounts for retail investors. Users of ECN accounts receive their pricing from a pool of large liquidity providers and hence there are smaller price discrepancies. That said, we are not just trading with other retail traders but also dealers from banks who provide these liquidity. They make a market with an advantage of being fast and access to the market depth of their clients. Building a trading bot will increase the speed and accuracy of our trade execution and hence, enhance our chance of survival in the competitive world of trading.

See the full report here.

 0

Sector Relative Strength in Trading

As mentioned always, Technical Analysis is a method of probabilities, not certainties. Therefore, it is always better to add another form of analysis on top of it. This post serves to introduce the concept of Sector Relative Strength in improving trading profitability.

Relative Strength compares the performance of a stock, exchanged traded fund or mutual fund to the overall market. This comparison is use to identify counters that are outperforming or underperforming the market to make buy or sell decisions respectively. Some common markets use for references are the Dow Jones, Standard and Poor 500 and the Nasdaq Indices. Therefore what is Sector Relative Strength? It is the comparison of a particular sector to the market, represented by the S&P 500 Index. For example, figure 1 shows the performance of the Information Technology (IT) sector relative to the market. It can be seen that the IT Sector has been outperforming the S&P 500 index for the past few months. With this information in mind, more focus shall be put into screening bullish counters in this sector. Via my screener, a potential trade has been scanned out on Yahoo. On figure 2, Yahoo has recently formed a hammer candlestick pattern, confluence with previous resistance turned support at 41.38.

In summary, it is always good to adopt a top down approach in trading. This allows you to have a macroeconomic view of sector performances in identifying high probability trades in the right places.

Figure 1. Relative Strength of IT Sector with S&P 500 Index

 

Figure 2. Yahoo Chart

 0

Non-Farm Payroll and Straddle Trading

If you are into FX trading, you should have heard of the non-farm payroll (NFP) report. This report is released on the first Friday of every month and it presents statistics indicating the total number of paid employees in US except those working in farms, government, private households or non-profit organizations. As such, the NFP report is seen as a direct reflection of the US economy as well as a forecast for future consumer spending since the buying power of people is directly linked to their earning ability. With such significance, the NFP report release often sets off huge movement in the FX market as the strength of greenbacks is directly related to the performance of the US economy.

The 2015 January NFP report was released one week ago on 6 Feb (Friday) at 9.30 pm Singapore time. After reviewing the price movement data on previous NFP data, I realized that the news release can set off a strong movement of up to 100 pips in one direction. As such, I decided to use a straddle trade strategy to capture this movement on the USDJPY pair. Using a 5-min chart (Figure 1 shows a 3-min chart to better display the price movements), I identified a resistance level at 117.37 region and a support level at 117.20 region. Next, I placed a buy stop order and a sell stop order simultaneously at 117.62 and 116.95 respectively, 25 pips above and below the support and resistance level identified. The stop loss was set at 15 pips below/above the pending orders as seen in Figure 1. Upon release of NFP report, the price broke out upwards by as much as 93 pips within a short 3-minute time period as seen in the long bullish candle below as US economy performed better in January 2015 as it added more jobs than expected. However, as I set my risk-to-reward ratio at 1:2, the order was closed at 117.90.

However, I do realize the risk of straddle trading as there are always chances of pending orders being wrongly triggered by whipsaws. That is why I set my pending orders as far as 25 pips away from the current support and resistance to reduce this risk.

 

 0

Technical Outlook – Wilmar International

To begin with, let’s review technical analysis on Wilmar International Ltd that I shared during a Saturday session (18 Oct 2014). I remember the market to be rather bearish and I was on the lookout for any potential opportunity for a trend reversal. As you can see from the chart, the price made lower low around $3 while RSI displayed a higher low, which suggests a potential trend reversal. I entered the market at $3.05 and exited the market at $3.22 in the box.

The analysis by fundamentalist further supported technical analysis by reiterating that Wilmar is undervalued. A few factors highlighted include the fact that it is involved in a well-diversified agri-business with a strong foothold in China and India. The company was also expected to make quarter-on-quarter recovery in its sugar and soybean-crushing operations. I would say that most of the time I use a combination of both technical and fundamental analysis in my trading philosophy.

wil

My personal view on UOL Group Ltd is with hope for a market correction following a highly bullish season. Weekly MACD is bullish over the past few months and prices have soared tremendously. With overbought indication as evident in stochastic, I will take a wait and see approach with this in my watch list.

 

 0

Fundamental Analysis – Sembcorp Industries (buy)

Sembcorp SS

This week, our Fundamental Analysis Department presents to you our equity research reports on Sembcorp Industries Limited (buy) by Team Industries.

Click here to find out more on their investment thesis and analysis!

 0

Equity Investment Strategies: A Quantitative Look into Changing Strategy Preferences in Emerging Markets

Written by: Cai Jun Tao, Janice Chen Pei Lun, Tseng Shih Ying

Abstract: Strategies on investing and trading in equities are diverse in both fundamentals and methodologies. Modern equity investment strategies can be separated into three main categories: Value investing, growth investing and dividend investing. This report identifies the key sets of stocks in the MSCI Emerging Markets Index (MXEF) that would fit into each type of investment philosophy and examines their price movements in the last decade in an attempt to identify the shifts in investment trends in equities over the years.

See the full report here.

 0

Fundamental Analysis – Cordlife (buy) and Libra Group (buy)

This week, our Fundamental Analysis Department presents to you our equity research reports on Cordlife (Buy) by Team Healthcare and Libra Group (Buy) covered by Team Manufacturing!

Download our reports here:

Libra Group Equity Research Report 080215
Cordlife Equity Research Report 080215

 0

9th – 13th February Technical Outlook

Last Friday NFP data were positive, sending the dollar further up north. The 95.00 to 95.20 level currently serves as a resistance. We do have a potential Bat pattern setting up around that region too. For traders who wish to look for shorting opportunity on the Dollar Index, keep an eye on the 95.00 – 95.20 region.

download

Looking at the most traded pair – EURUSD, we do have a potential setup this coming week too.

Price has completed a double top divergence setup. We can wait for a 2618 setup around the 1.4120 level to ride on a trend continuation trade.

download (1)

On GBPUSD, we have two ways of potentially trading it. Price has currently found support at the level with RSI oversold. Trading looking for a trend continuation setup can potentially wait for a completed double bottom divergence to buy into the market.

For counter-trend trader, there is a completed double top divergence. Wait for a 2618 setup around the 1.5295 level to short on the market.

download (2)

 0

Gold Plunges on Strong NFP

Gold tumbled on Friday on positive Non-Farm Employment numbers. An encouraging U.S jobs reports provided strong support for the dollar when data indicated the U.S adding 257K new jobs in January, far exceeding estimates at 236K, causing the gold to decline more than 3% on Friday. The positive jobs number has led to speculation that strong U.S data can increase the possibility of a rate hike when the Fed convenes in June which could further discourage investors from putting their money on the ‘safe-haven’ asset.

Untitled

From the above daily chart, as of Friday’s closing the price now sits nicely on at a resistance turned support level (1232.76) and is further supported at the Fibonacci Retracement 61.7% levels.

However, Chinese had registered a record trade surplus in January with imports falling 19.9% which was the most in five years following a fall in commodity prices and weak domestic demand. Exports had slide 3.3%, leading to a net trade surplus of $60 Billion. Given that the trade balance is the largest buyer of gold, this could lead to a price rebound in the short term and provide some lift for Gold.

 0

Back-testing of Moving Average Crossover Strategy

Written by: Heng Rui Yan Ryan, Stephen, Zhang Yaquan

Description: The strategy presents buying (selling) opportunities when the fast Moving Average (MA) crosses above (below) the slow MA. As the fast MA is more reactive than the slow MA, a MA crossover usually indicates an increase in bullish/bearish momentum.

The basic trading strategy of MA crossover is predicated on the following rules:

Entry trigger: Buy (sell) when the fast MA crosses above (below) the slow MA.

Take profit/stop loss trigger: Close a long (short) position when fast MA crosses below (above) the slow MA.

Parameters of back-testing

During our back-testing, we fixed the following few parameters:

  1. Timeframe: Daily
  2. Currency Pair: AUD/USD, EUR/USD, USD/JPY (chosen because they are three of the most traded currency pairs)
  3. MA Type: Simple
  4. Volume: 100,000 (1 lot)
  5. Starting capital: 40,000 USD
  6. Spread: 1 pip
  7. Back-testing period: 01/01/2012 to 31/01/2015

On the other hand, we varied the periods of fast and slow MA to compare the performance of various combinations and identify the most profitable combination.

Results

Table 1: AUD/USD

Fast MA Slow MA Initial Balance Profit/Loss Ending Balance % Return Sharpe Ratio % Max Drawdown
5 10 40,000.00 -10,985.00 29,015.00 -27.46 -0.08 32.84
5 20 40,000.00 9,315.00 49,315.00 23.29 0.07 22.04
10 20 40,000.00 6,018.00 46,018.00 15.05 0.05 19.38
10 50 40,000.00 12,975.00 52,975.00 32.44 0.27 18.27
20 50 40,000.00 12,637.00 52,637.00 31.59 0.32 13.05
20 100 40,000.00 1,438.00 41,438.00 3.60 0.04 22.2
50 100 40,000.00 -14,238.00 25,762.00 -35.60 -0.47 36.49
60 100 40,000.00 -16,554.00 23,446.00 -41.39 -0.52 41.98
50 200 40,000.00 5,135.00 45,135.00 12.84 0.21 12.08
100 200 40,000.00 1,824.00 41,824.00 4.56 0.07 15.75

Table 2: EUR/USD

Fast MA Slow MA Initial Balance Profit/Loss Ending Balance % Return Sharpe Ratio % Max Drawdown
5 10 40,000.00 -2,261.00 37,739.00 -5.65 -0.02 37.13
5 20 40,000.00 -27,843.00 12,157.00 -69.61 -0.25 71.89
10 20 40,000.00 10,209.00 50,209.00 25.52 0.13 16.36
10 50 40,000.00 -5,792.00 34,208.00 -14.48 -0.16 31.05
20 50 40,000.00 -5,138.00 34,862.00 -12.85 -0.12 33.26
20 100 40,000.00 -6,876.00 33,124.00 -17.19 -0.37 25.87
50 100 40,000.00 -7,546.00 32,454.00 -18.87 -0.32 38.45
60 100 40,000.00 -4,908.00 35,092.00 -12.27 -0.21 33.47
50 200 40,000.00 -8,587.00 31,413.00 -21.47 -0.48 33.68
100 200 40,000.00 -2,570.00 37,430.00 -6.43 -0.43 12.98

Table 3: USD/JPY

Fast MA Slow MA Initial Balance Profit/Loss Ending Balance % Return Sharpe Ratio % Max Drawdown
5 10 40,000.00 12,657.00 52,657.00 31.64 0.08 24.02
5 20 40,000.00 17,722.00 57,722.00 44.31 0.15 14.56
10 20 40,000.00 9,264.46 49,264.46 23.16 0.08 28.3
10 50 40,000.00 17,190.57 57,190.57 42.98 0.18 21.45
20 50 40,000.00 8,058.00 48,058.00 20.15 0.1 31.62
20 100 40,000.00 7,970.07 47,970.07 19.93 0.19 14.09
50 100 40,000.00 12,310.62 52,310.62 30.78 0.29 6.14
60 100 40,000.00 13,592.00 53,592.00 33.98 0.34 5.07
50 200 40,000.00 10,276.47 50,276.47 25.69 0.3 9.44
100 200 40,000.00 3,596.55 43,596.55 8.99 0.1 13.98

 

Analysis

After a careful analysis of the back-testing results, we identified that the MA crossover strategy works well during the periods when the market is trending, but performs poorly when the market is ranging (see Figures 1 and 2 for examples).

1-fig1a
Figure 1a: 5/20 MA USD/JPY Price
1-fig2b
Figure 1b: USD/JPY Balance and Equity

1-fig2a
Figure 2a: 5/20 MA AUD/USD Price
1-fig1b
Figure 2b: AUD/USD Balance and Equity

MA+RSI

Hence, in order to improve the performance of our strategy, we incorporated the use of Relative Strength Indicator (RSI) to identify whether the market is trending or ranging. We also fix the RSI period as 21. The enhanced trading strategy, which will be called MA+RSI strategy in this article, is as follows:

Entry trigger: Buy (sell) when the fast MA crosses above (below) the slow MA and the RSI is above 55 (below 45).

Take profit/stop-loss trigger: Close a long (short) position if either one of the three conditions is satisfied:

  1. Fast MA crosses below (above) the slow MA.
  2. RSI is above 80
  3. RSI is below 20

Results

Back-testing the enhanced strategy over the same MA periods as the basic MA crossover strategy, we obtained the following results:

Table 4: AUD/USD

Fast MA Slow MA Initial Balance Profit/Loss Ending Balance % Return Sharpe Ratio % Max Drawdown
5 10 40,000.00 11,976.00 51,976.00 29.94 0.26 7.16
5 20 40,000.00 9,435.00 49,435.00 23.59 0.15 10.92
10 20 40,000.00 12,704.00 52,704.00 31.76 0.19 17.88
10 50 40,000.00 12,041.00 52,041.00 30.10 0.29 16.36
20 50 40,000.00 11,677.00 51,677.00 29.19 0.37 11.21
20 100 40,000.00 3,689.00 43,689.00 9.22 0.12 15.64
50 100 40,000.00 -12,536.00 27,464.00 -31.34 -0.44 32.23
60 100 40,000.00 -15,879.00 24,121.00 -39.70 -0.59 40.3
50 200 40,000.00 -6,224.00 33,776.00 -15.56 -1.25 18.99
100 200 40,000.00 1,929.00 41,929.00 4.82 0.08 15.72

Table 5: EUR/USD

Fast MA Slow MA Initial Balance Profit/Loss Ending Balance % Return Sharpe Ratio % Max Drawdown
5 10 40,000.00 15219 55,219.00 38.05 0.2 16.96
5 20 40,000.00 516 40,516.00 1.29 0.01 32.33
10 20 40,000.00 17871 57,871.00 44.68 0.29 16.52
10 50 40,000.00 547 40,547.00 1.37 0.01 32.05
20 50 40,000.00 2555 42,555.00 6.39 0.06 30.12
20 100 40,000.00 2379 42,379.00 5.95 0.09 23.81
50 100 40,000.00 -4650 35,350.00 -11.63 -0.19 35.83
60 100 40,000.00 3980 43,980.00 9.95 0.26 15.96
50 200 40,000.00 -1291 38,709.00 -3.23 -0.05 32.12
100 200 40,000.00 1172 41,172.00 2.93 0.1 12.91

Table 6: USD/JPY

Fast MA Slow MA Initial Balance Profit/Loss Ending Balance % Return Sharpe Ratio % Max Drawdown
5 10 40,000.00 6,761.30 46,761.30 16.90 0.09 23.94
5 20 40,000.00 7,717.21 47,717.21 19.29 0.14 15.66
10 20 40,000.00 899.51 40,899.51 2.25 0.02 26.52
10 50 40,000.00 1,723.87 41,723.87 4.31 0.05 21.4
20 50 40,000.00 -9,001.11 30,998.89 -22.50 -0.3 29.5
20 100 40,000.00 4,885.40 44,885.40 12.21 0.22 13.14
50 100 40,000.00 8,439.89 48,439.89 21.10 0.85 5.69
60 100 40,000.00 8,221.21 48,221.21 20.55 0.77 5.22
50 200 40,000.00 1,760.59 41,760.59 4.40 0.17 9.44
100 200 40,000.00 -1,542.82 38,457.18 -3.86 -0.07 6.6

 

Conclusion

Comparing the performance of the two strategies by taking the difference between the percentage return of our enhanced strategy and the basic crossover strategy, we have the following table.

Table 7: Overall Performance of MA Strategies

Fast MA Slow MA % Return Difference (MA+RSI- Basic Strategy)
AUD/USD EUR/USD USD/JPY
5 10 57.4025 43.56 -14.996325
5 20 0.3 70.7925 -25.2208
10 20 16.715 19.075 -21.003225
10 50 -2.335 15.8475 -38.71115
20 50 -2.4 19.2325 -42.416325
20 100 5.6275 23.1375 -7.837325
50 100 4.255 7.24 -9.8939
60 100 11.045 22.22 -13.6575
50 200 -28.3975 18.215 -21.34765
100 200 0.2625 9.34 -14.203825

 

In summary, the basic strategy produces outstanding performance in strongly trending markets, as evidenced by its high return in USD/JPY due to the strong bullish trend in the currency in 2014. However, in ranging markets, the basic strategy often produces poor performance and hence, the enhanced strategy (MA+RSI) acts as a filter to improve the performance of the basic strategy. This is evidenced by the higher return of the enhanced strategy in AUD/USD and EUR/USD.Interested readers could explore further possible ways to improve the performance of the strategy, such as adding more indicators in the strategy and varying other parameters, such as the periods of the crossover, timeframes, and currency pairs.

 0