Diversify your portfolio by investing in stocks from various industries

Updated on 2011-12-22

What do you need to have a well-diversified portfolio?

This post shows you a way to diversify your portfolio by investing in stocks from various industries.

By diversifying your portfolio, you can minimize your risk and achieve your long-term financial goals. Diversification is very important in today's volatile markets.

Trading System Entry & Exit Rules

- Consider only the top 2 performing stocks in each industry
- Buy the 5 stocks that have the highest correlation with the S&P 500 Index
- Sell all positions after a month and repeat the process

Diversify your portfolio by getting the top performing stocks in each industry

To create a short list of the best performing stocks in each industry, we need only two functions:

Perf: Calculates the performance of a security during the last N-Bars

a1 = perf(close, 25); // One-month return

Comp: Creates a composite or ranks assets based on a specified indicator (depends on the calculation method passed to the function)

a2 = comp(a1, "rank", industry(), close > 2) <= 2;

Parameter 1 & 2: Returns the rank of each stock based on the monthly return. Example: Stock that have the highest return will get a rank of 1

Param 3: Performs ranking separately for each industry. This means that we can get several stocks with a rank of 1.

Use the screener to get a clear view of how the grouping parameter of the composite function works. Refer to the formula in "Note 2" below.

Param 4: Ignores stocks that do not meet the filter criteria specified here. This means that low priced stocks will never get the lowest ranks.

Before moving to the next buy rule, I want to add an additional condition that prevents the simulator/portfolio from buying stocks whose industry field is not specified. "Note 1" below will show you how to fill the industry field of each U.S. Stock.

a2 = a2 and StringLength(Industry()) > 0;

Correlation with the S&P 500 Index

How to get the S&P 500 Index:

Depending on the downloader you are using, the symbol name of the S&P 500 Index may vary. The default downloader (Historical Stock Market Data) uses "^GSPC" to reference this index.

sp500 = GetSeries('^GSPC', Close);

The "GetSeries" function allows you to reference an external series. In the above example, we will obtain the close price series of the S&P 500.

How to calculate the correlation between the current stock and the S&P 500 Index:

The "correl" technical analysis function calculates the correlation between two time-series for the past N-bars.

a3 = correl(perf(close, 1), perf(sp500, 1), 25);

The above function returns the correlation, during the previous month, between the daily return of each analyzed stock and the daily return of the "^GSPC" index.

How to get those stocks that have the highest correlation:

Again, the "comp" function will come to the rescue here. Instead of the monthly return, the correlation time-series should be passed to the composite function.

Trading financial instruments, including foreign exchange on margin, carries a high level of risk and is not suitable for all investors. The high degree of leverage can work against you as well as for you. Before deciding to invest in financial instruments or foreign exchange you should carefully consider your investment objectives, level of experience, and risk appetite. The possibility exists that you could sustain a loss of some or all of your initial investment and therefore you should not invest money that you cannot afford to lose. You should be aware of all the risks associated with trading and seek advice from an independent financial advisor if you have any doubts.