After introducing the "Count" and "Sum" calculation methods and how to use them in order to create market indicators (Market Indicators), we will continue our presentation with a new type in the composite function.
The "Avg" calculation method calculates the average number of the different values of the provided time series or indicator. Internally, this method simply calculates the sum of the time series values that occurred on the same date and also keeps track of the number of these values. At the end, the function divides the sum that was calculated first by the number of values.
The "Avg" function is very powerful and it can be used in different ways to calculate composites and indices. Almost any kind of market indices can be created by applying the composite function with the "Avg" calculation method; this includes capitalization-weighted indices (such as the S&P 500 or Russell 2000), equal-weighted indices, fundamental-weighted indices and volume-weighted indices.
Here are some market indicator examples:
This trading indicator calculates the average RSI or relative strength index value of all stocks or securities included in the analysis. You can then compare this composite to the oversold or overbought threshold levels and determine whether the market is bullish or bearish based on the relative strength index interpretation.
The above indicator returns the average 30-bar simple moving average of all your stocks. This can be used for example by calculating another composite that returns the average 60-Bar simple moving average and then comparing both values. The signal the market generates is bullish if the first moving average is higher than the second one -> Comp(sma(30), "avg") > Comp(sma(60), "avg")
Comp(close > ref(close, 1), "avg")
Used with the "sum" function, this formula would have returned the number of advancing stocks. However, with the "avg" function, the formula returns the percentage of advancing stocks or the proportion of stocks that are advancing among stocks included in the analysis (Backtesting, Screening, Rules analyzing...)
The next trading indicator assumes you have a fundamental database that contains the market capitalization data for all of your stocks. Note that you can also use this function if you only have the number of outstanding shares data; this is because the market capitalization of a stock is equal to its share price multiplied by the number of outstanding shares.
Comp(GetData("fund", "mkcap") * close, "avg")
Here is how to create a capitalization-weighted market index. Take the time-series that corresponds to the market capitalization data of your stock and then multiply that value with the close price. Applying the composite's average method to this formula produces our custom capitalization-weighted index.
In composite calculations, the "Avg" function is one of the most powerful tools to create different and various market indices or composites. The composite plug-in still has many other calculation methods; we will see that in a future post.