Build Technical Indicators in Python
|June 16th, 2016, 07:12 AM||#1 (permalink)|
Futures Experience: None
Favorite Futures: currency futures
Posts: 1 since Jun 2016
Thanks: 1 given, 1 received
Build Technical Indicators in Python
Technical Indicator is essentially a mathematical representation based on data sets such as price (high, low, open, close, etc.) or volume of a security to forecast price trends. There are several kinds of technical indicators that are used to analyse and detect the direction of movement of the price. Traders use them to study the short-term price movement, since they do not prove very useful for long-term investors. They are employed to primarily to predict the future price levels.
Technical Indicators do not follow a general pattern, meaning, they behave differently with every security. What can be a good indicator for a particular security, might not hold the case for the other. Thus, using a technical indicator requires jurisprudence coupled with good experience.
In the following post, I will highlight a technical indicators that are popularly used in the markets to study the price movement.
As these analyses can be done in python, a snippet of code is also inserted along with the description of the indicators. Sample charts with examples are also appended for clarity.
Commodity Channel Index (CCI)
The commodity channel index (CCI) is an oscillator which was originally introduced by Donald Lambert in 1980. CCI can be used to identify cyclical turns across asset classes, be it commodities, indices, stocks, or ETFs. CCI is also used by traders to identify overbought/oversold levels for securities.
The CCI looks at the relationship between price and a moving average. Steps involved in the estimation of CCI include:
Computing the typical price for the security. Typical price is obtained by the averaging the high, low and the close price for the day.
Finding the moving average for the chosen number of days based on the typical price.
Computing the standard deviation for the same period as that used for the MA.
The formula for CCI is given by:
CCI can be used to determine overbought and oversold levels. Readings above +100 can imply an overbought condition, while readings below −100 can imply an oversold condition. However, one should be a careful because a security can continue moving higher after the CCI indicator becomes overbought. Likewise, securities can continue moving lower after the indicator becomes oversold.
Whenever the security is in overbought/oversold levels as indicated by the CCI, there is a good chance that the price will see corrections. Hence a trader can use such overbought/oversold levels to enter in short/long positions.
Traders can also look for divergence signals to take suitable positions using CCI. A bullish divergence occurs when the underlying security makes a lower low and the CCI forms a higher low, which shows less downside momentum. Similarly, a bearish divergence is formed when the security records a higher high and the CCI forms a lower high, which shows less upside momentum.
Python code for computing the Commodity Channel Index
In the code below we use the Series, rolling_mean, rolling_std, and the join functions to compute the Commodity Channel Index. The Series function is used to form a series which is a one dimensional array-like object containing an array of data. The rolling_mean function takes a time series or a data frame along with the number of periods and computes the mean. The rolling_std function computes the standard deviation based on the price provided. The join function joins a given series with a specified series/dataframe.