Recently, I’ve been following how a stock interacts with the overall sector they are in and if other stocks in the same sector behave similarly on the same day. Nothing scientific yet, but obviously, when you see all the shippers make a run on the same day, there has to be correlation going on. I was curious if it was possible to write a StockFetcher code to calculate the relationship between a stock and it’s sector – utilizing Yngvai’s code at Welcome to the Gutter converting RJ/JV’s Correlation Calculator application into a StockFetcher filter.

However, StockFetcher states that while you can filter by sector/industry, you can’t incorporate aggregate / performance information of the sector/industry into the equation. Here’s a handy StockFetcher list dividing stocks into sector/industry. So, the closest thing to a sector correlation calculator may be using a sector based ETF as an approximation. Here’s a list of NASDAQ Sector-Based Exchange Traded Funds.

For example, I’ve had a theory that when oil goes up, the solar stocks go down, or vice versa. Well, not necessarily when comparing ESLR to the oil ETF – USO. ESLR actually goes up 55% and down 63% of the time when USO does – so they sorta move in tandem in the same direction. I also compared F to GM, not a sector, but a closely connected industry stock – and F falls 85% of time that GM does, so don’t long F on a GM red day.

I doubt I will be writing many SF scans/screeners because my brain doesn’t work very well with the code, but this may be a good tweak to the calculator code put together by Yngavi at his site (link above). All you have to do is in the first line put your base stock in the parenthesis after symlist and replace DJI in the second and third lines with the ETF/stock you want to calculate a correlation.

set{close_ind, ind(uso, close)}
set{open_ind, ind(uso, open)}

This seems to work, let me know if I’m missing something. The ETFs don’t necessarily replicate what a sector does, and some of the ETFs are thinly traded, so you have to be careful not to jump to conclusions.