Which Is The Best Moving Average For Nepali Stock Market?

Arun Lama

Email: mrarunlama@gmail.com

CMT Level II

We usually select moving averages arbitrarily by manually looking at the charts but it lacks statistical edge and rather it is just a guess work. Fortunately, there is a proper way to select certain moving averages which are likely to perform better than the other. Optimal moving averages can be found by optimizing the various lengths of moving averages across different stocks.

While there are different kinds of moving averages, the scope of this study revolves around simple moving average only. A simple moving average is simply an arithmetic mean which is calculated by adding recent closing prices and divided by the number of the closing prices taken. For example: - A 20-day simple moving average is calculated by adding the last 20 day’s closing prices divided by 20. This 20-day’s time duration is called the “length” or “period” of a moving average. The greater the length of a moving average the smoother it becomes and vice versa. When you trade with longer moving average you will get fewer signals and your holding time will be longer as well. Longer moving averages are slower to react to the trend which is a benefit as well as a disadvantage. Reacting slower to the trend will help you to stay out of the short term noises and give you a confirmation only when there is one but at the same time it will also reduce your significant profits when the trend changes. You will also suffer big losses when you have to get out of the losing trades. On the other hand, shorter moving averages generate signals too frequently which results in whipsaws. In other words, shorter moving averages give trend signals too early because they catch very short trends. Hence selecting the right length of a moving average can be a challenge. In this study, a sincere effort has been made to figure out the optimal moving average that can perform well in the overall Nepali stock market.

Moving average is used in stock trading for the trend following purpose. It is widely used by traders worldwide. It is a very simple yet very powerful technical indicator. There are different ways to use moving average to trade the market. A very basic strategy will be used here. The basic moving average rule which will be used here is – “buy when closing price crosses above moving average and sell when closing price crosses below moving average” as shown in above picture.

Optimization

Optimization is finding the best moving average length which maximizes the profits and minimizes the losses. While searching for the best length, if you discover that a particular moving average has produced a superior profit based on the historical price of a stock then don’t be so happy because it’s simply a curve fitting. That is curve fitting because it was fitted very well to the past data which means it does not guarantee any future returns as it did in the past because the future is not like the past. A single evidence of a superior profit in a stock is not enough to label the strategy as a “robust strategy”. A strategy is said to be robust if it can generate consistent results over wide range of markets. 21 stocks and a banking index have been tested here.

Variables used in Optimization

Trading rules           : Buy when the closing price crosses above moving average and sell when the closing price falls below the moving average.

Price history            : 2011 July -2019 June 11 (with few exceptions)

Number of stocks          : 22 (including a banking index)

Initial investment          : Rs. 1,00,000

Moving average lengths tested : 5, 10, 15, 20, 25, 30, 35, 40, 50, 60, 70, 80, 90, 100, 150, and 200

System evaluation measures    : Net profit, number of trades, maximum drawdown (%), % of winning trades, % of losing trades, profit factor, payoff ratio, Sortino ratio, Sharpe ratio, Treynor ratio, Calmar ratio, efficiency factor, ROI, and CAGR. 

If a buy signal occurs today based on today’s close then the trade is executed at today’s closing price assuming that we are buying at tomorrow’s open. Due to additional complexities, the broker commissions and capital gain taxes are not included. Back adjusted price was used in testing process. After the test was run on each of the lengths of a moving average i.e. from 5 to 200, the one with the most profit was chosen for optimization. The overall summary of the test is shown below.

Trend Following System Profile

Trend following strategies will have many small losses and few large profits. Trend following strategies profit from the fat tail distributions of the returns. Stock prices are not normally distributed but have fat tail on the right side indicating large upside runs occasionally. It happens because the stock market is biased upside in the long run. On an average it is believed that the most trend following systems will be profitable only 30% of the time but those 30% wins can easily offset the losses of 70% trades. This notion is also supported by the above test where the average of percentage of winning trade is only 26% but the system is still profitable.   

Optimization Result Interpretations

NLIC generated the most profit with 10-day simple moving average which returned Rs, 49,55,980 in an investment of Rs 1 lakh over the time horizon of 8 years. BPCL had the least profit of Rs. 23,212 during the same period. But the result of a single moving average on a single stock is not our concern. The whole point of the optimization to look at the average result of many stocks rather than the individual company. Statisticians say that the best estimate of the future is the mean. As you can see the moving average performance fluctuated largely across various stocks, the optimal moving average is the average of all the moving averages which is 35. Which means if you want to use a single moving average to trade all the stocks of Nepse, then 35-day moving average will give you the average result i.e. annual return of 26%. With the average length of 35 you will neither get superior result like that of NLIC nor will you get the worst result like of BPCL, you will get the average result.

As 35 is the optimal moving average, the performance metrics generated by it are likely to be the estimate of the future performance of the 35-day simple moving average strategy. Which means if you trade using a 35-day SMA, you are likely to win 26% of the time, your are likely to face -5% drawdown, and so on. The real definition of the maximum drawdown is the largest distance from the equity line peak to the equity line bottom but here, the drawdown refers to % below the initial capital of Rs. 1,00,000. With 35-SMA strategy you can expect to hold your trades on an average of 35 days. The profit factor, which measures gross profit to gross loss of the system is 3 which indicates gross profit is 3 times more than the gross loss. The payoff ratio, which is the average winning trades to average losing trades, is 7 which shows average winning trades are 7 times the average losing trades. Sortino ratio which measures excess returns to the standard deviations of negative returns stands at 14 indicating a decent figure. The Sharpe ratio, calculated using excess return divided by standard deviations of returns is at 8 suggesting an excess return of 8 per unit of risk. Treynor ratio, which measures the excess return adjusted to systematic risk is 0.39 which means the strategy can earn excess return after adjusting to undiversifiable risk. The efficiency factor which is net profit divided by gross profit is 54% which is good because, generally, successful systems have efficiency ratio in the range of 38% to 69%.  The ROI shows the return on investment (Rs 1 lakhs) over 8 years. Compounded annual growth rate stands at 26%. And the average holding period is 35-days. These metrics suggest that a 35-day moving average strategy is indeed a profitable strategy.

Optimization By Industry

During the optimization process all the major industry of Nepse were covered and the optimal moving average was 35. Moreover, the optimization can be taken into another level by optimizing the moving averages based on the industry. Based on the above data and other tests it was found that the optimal moving average length tend to cluster around the same range within the same industry but varied across the different industry. In that case it will be more appropriate to use different moving average lengths for different sectors. It is observed that commercial banks do well with 10-Day, development banks with 50-Day, hotels with 90-Day, and hydro with 30-Day lengths. Due to the lack of enough data, other sectors were not tested.

Back testing the Optimized 35-day Simple Moving Average

Through the optimization a 35-day moving average was found to be an optimal length to trade the overall stocks in Nepse. But how will it perform on untested market? Let’s try to back test this strategy on those stocks which were not included in the optimization process.

The back testing result shows that the 35-day SMA is actually consistent with the prior test which means if you use 35-day moving average you are likely to get above results on average in the long term. However, it is suggested to test your strategy in an out-of-sample data before you decide the final parameter of the system. One strong conclusion we can draw from this study is that moving average is profitable in Nepali stock market.

Disclaimer: This study was solely done for the educational purpose and it is not intended to recommend any trading strategy. Because the optimization and back testing was done on the whole sample data (out-of-sample not used), the real performance of the strategy may vary from the back-testing results. Additionally, back adjusted data were used to test the strategy which means the strategy executes the positions at prices which are actually different from the real data. Hence the author will not be liable for any damage caused by the implementation of the strategy.

 

Appreciation note: ShareSansar acknowledges Mr. Lama's consistent effort on helping our readers understand the technical aspect of the market. We thank you for your several articles on our platform. Dear readers, if you have articles that will be benefitial to the current investors, please feel free to send us your articles. The final decision to publish the article or not will lie in the hands of the media team.