Feature engineering is one of the fun, creative, and essential steps in machine learning. It transforms raw data into a form that very meaningful information for a model to forecast the future. The predictability of a model relies on good features, which in turn relies on your domain knowledge.

Many experienced stock market traders who evaluate trading rules or charts have already engaged in some forms of feature engineering — whether they realized it or not. For example, a moving average is a feature that characterizes the movement of a stock price. All the technical indicators (RSI, MACD, stochastic oscillators, Bollinger Bands, etc.) are some forms of features too. These features can be fed into a machine learning model, or used as trading signals. There can be hundreds, if not thousands, of trading strategies to capture the market anomalies or predict future trends.

In this post I will walk you gently to build your algorithmic trading code in R. R has several powerful quantitative finance libraries because of its long development history including QuantmodTTRPerformanceAnalytics. If you are new to algorithmic trading, you will be ready to start your algorithmic trading. The code github is made available in the end for download.

(0) The Four-Decade Debates on Market Efficiency

_As we discuss the efficacy of algorithmic trading or technical rules, the iconic debates on the “efficiency market hypothesis” (EMH) always come to our minds. Although this article does not plan to address the debate, it is worthwhile to mention it here. It is believed that prices should already fully reflect all available information. There is no way to “beat the market” to obtain abnormal returns. This is the famous “”. According to EMH, prices already reflect at least all past publicly available information — so-called the weak form; or prices change __instantly _to reflect all publicly available information — so-called the semi-strong form; or prices have also reflected any hidden insider information — so-called the strong form. Eugene Fama, the 2013 Nobel Prize winner, believes anomalies are consistent with rational pricing.

Do all traders subscribe to the EMH? Not really. Many traders believe there exist opportunities that prices are mis-priced and they can obtain abnormal returns. An “anomaly” is the situation that a price does not fully reflect all the public information, thus provides a trading opportunity. Although “beating the market” is something many novice or experienced traders try to do, few actually succeed. Robert Shiller –also a 2013 Nobel Prize winner — believes that markets are irrational and subject to behavioral biases in investors’ expectations. If that is the case, investment performance can be improved by advanced predictive models that are always in place or yet to come. Readers who are interested in the philosophical debates and empirical verifications, please see my post “Stock Market Anomalies” and “Stock Market Anomaly Detection” Are Two Different Things.

Okey. Now is time to enjoy the coding for algorithmic trading.

#stock-market #technical-analysis #algorithmic-trading #data-analysis

Algorithmic Trading with Technical Indicators in R
2.50 GEEK