StockFetcher Forums · Filter Exchange · Correlation search in SF (paired trading)<< >>Post Follow-up
glgene
534 posts
msg #97864
Ignore glgene
12/6/2010 11:54:59 PM

This may seem like a far-out question, but is there any way to build a SF script that would search for non-correlated sectors?
Kevin wrote a script a few days back where he showed a SF-produced correlation table of 10 ETFs. It was great! For example, if you compare MOO to UUP, it produces a negative correlation of -0.83.

Correlation, overall, ranges from -1.00 to +1.00. For paired investing, you ideally would want to seek (in my opinion) negative correlation so you can switch from Investment A to Investment B at key indicator times, and reap the benefit of being in the right investment (A or B) at the most advantageous time (at least in theory).

I ran MOO vs. UUP in an investment software I use sometimes. Indicator: Buy MOO when its 15-day EMA crosses above its 60-day EMA. Sell MOO and buy UUP when MOO's 15-day EMA crosses below its 60-day EMA. Note: 15- and 60-day periods were arbitrary. This setting doesn't work universally (what does?). The software I used showed a MOO-to-UUP correlation of -85.65% (very close to Kevin's reported SF number of -0.83 . Wish I could have tested over a longer period of time, but MOO didn't hit the streets until 9/05/2007; UUP on 2/22/2007.


3-year results, ending 12-6-2010 [incl. dividends]
--------------------------------------------------------------------------------------

a) Buy/hold MOO [ag ETF] ............................. -1.41% total return

b) Buy/hold UUP [long dollar ETF].................. -2.27% total return

c) Switching between MOO & UUP,
using MOO 15- and 60-day crossovers ...... +88.28% total return
Involves just 1.67 round-trip switches
per year (over past 3 yrs).
In MOO 70% of time; in UUP 30% of time.


So how did it do during the infamous 2008 period?

a) Buy/hold MOO ............................................. -51.01% total return

b) Buy/hold UUP ............................................... +4.89% total return

c) Switching between MOO & UUP,
using MOO 15- and 60-day crossovers ...... +10.49% total return
Start the year in MOO. Only one switch
from MOO to UUP during the year.
In MOO 52% of time; in UUP 48% of time.


Now, I'm wondering if paired investing (non-correlation) searches can be found with SF scripting. Either sector searches, or ETF searches. I have no idea how to accomplish that (if it's doable).

Many thanks, Kevin, for your beacon of light with your correlation table (maybe you want to repost it here). It lit my light bulb (changed it from 60w to 200w). Non-correlated investing puts the P into Paired trading. Now if I could just graduate from SF 101 to a higher level as many posters here exhibit. A searchable, non-correlated SF filter ?

Gene


duke56468
683 posts
msg #97866
Ignore duke56468
modified
12/7/2010 8:42:04 AM

This is SF negative correlation filter, just change the stock you want to check. Not sure if this is what you are looking for.

Fetcher[
market is ETF
close is above 3.00
and average volume(30) is above 250000
and corr(uup,20,CCI(14)) is below -0.50
and add column corr(uup,20,CCI(14))
and draw CCI(14)
and draw IND(uup,CCI(14)) on plot CCI(14)
sort on column 5 ascending
]



glgene
534 posts
msg #97867
Ignore glgene
12/7/2010 9:08:32 AM

Here's a starter search I came up with. Not sure about ETF volume, and output column from 3 mos. ago (computation looks suspicious). Comments:


Fetcher[

stock is etf

show stocks where close is above 10
and average volume(30) is above 10000
and volume is above 10000
and corr(^UUP,65,Close) is below -0.6
add column separator
and add column corr(^UUP,65,Close){corr to UUP(65)}
and add column corr(^UUP,65,Close) 1 week ago{corr to UUP(65), 1 wk ago}
and add column corr(^UUP,65,Close) 2 weeks ago{2 wks}
and add column corr(^UUP,65,Close) 3 weeks ago{3 wks}
and add column corr(^UUP,65,Close) 4 weeks ago{4 wks}
and add column corr(^UUP,65,Close) 3 months ago{3 mos}
]




glgene
534 posts
msg #97869
Ignore glgene
12/7/2010 10:02:30 AM

Thanks, Duke. I will review your suggestion. Probably better than mine, since this is my first attempt with a Correlation indicator. I'm learning. Not sure about the look-back period.

Kevin_in_GA
4,542 posts
msg #97878
Ignore Kevin_in_GA
12/7/2010 3:36:15 PM

Normally, pairs trading is defined as having a simultaneous long and short trade, usually with two stocks in the same market sector. Often they trade in a well defined range that for some reason has been moved from its usual equilibrium, and the long-short play predicts that each stock will revert to back to the mean.

Here's a quick example of what i mean. In this filter each of the standard sector ETFs for the S&P 500 is compared to its normal relationship with the SPY. If any of the ETFs trade more than 2 standard deviations from the 20 day average of the pair, it is a good trade for short-term mean reversion. One could simply go long the ETF with the lowest Z-score, and short the one with the highest Z-score, expecting both to revert to the mean.

Fetcher[

symlist(XLB,XLE,XLF,XLI,XLK,XLU,XLP,XLV,XLY,SPY)

draw MA(200)

/*FIRST DETERMINE HISTORICAL RATIO OF SECTOR ETF TO THE SPY*/
SET{PRICERATIO, CLOSE / IND(SPY,CLOSE)}
SET{RATIOMA, CMA(PRICERATIO,13)}
SET{RATIOSTD13, CSTDDEV(PRICERATIO,13)}
SET{DIFF13, PRICERATIO - RATIOMA}
SET{ZSCORE13, DIFF13 / RATIOSTD13}
SET{THRESHOLD, RATIOSTD13 * 2}

SET{tt, DIFF13 / RATIOMA}
set{ttt, -1 * tt}
SET{PROFIT_TARGET, ttt * 100}

/*NEXT, SET CRITERIA NECESSARY TO TRIGGER A PAIR TRADE*/
SET{UPPERBAND, RATIOMA + THRESHOLD}
SET{LOWERBAND, RATIOMA - THRESHOLD}
DRAW LOWERBAND ON PLOT PRICERATIO
DRAW UPPERBAND ON PLOT PRICERATIO

ADD COLUMN PRICERATIO
ADD COLUMN ZSCORE13
and add column corr(SPY,100,Close)
and add column corr(SPY,13,Close)

add column PROFIT_TARGET {reversion profit (%)}

DRAW ZSCORE13 LINE AT 2
DRAW ZSCORE13 LINE AT -2
DRAW ZSCORE13 LINE AT 0

SORT ON COLUMN 6 DESCENDING
CHART-TIME IS 3 MONTHS
]




What you are describing is more like an asset rotation system (similar to what I use), but rather than being based on a measure of momentum such as RSI or TSI, you are using a moving average crossover for MOO as the trigger. You are, in essence, simply moving in and out of a long position in MOO and using UUP as the ETF equivalent of cash, right?

drew9
171 posts
msg #97887
Ignore drew9
modified
12/7/2010 8:50:13 PM

Have you considered the inverse ETF's. Not sure if there is one for these but if you want negative correlation that would certainly be the ticket.

four
3,998 posts
msg #97888
Ignore four
modified
12/7/2010 9:49:41 PM

Fetcher[
symlist(soxl,soxs)
draw ma(10)
draw ema(5)
chart-length is 7 months
]



www.3xetf.com

glgene
534 posts
msg #97900
Ignore glgene
12/8/2010 5:26:08 PM

Duke, Kevin, Four and Drew....

Again, many thanks for your contributions here. Each one has its merits. That's what I needed. Kevin's is WAY out of my league. I'm just wearing a "freshman beenie" on my head. But I'm going to try and figure it out....that's what a good student does. Let's just say I'm a late bloomer 60+

Kevin....I appreciate your technical remarks on"paired trading." You're right about my example of MOO vs. UUP rotation as not being TRUE paired trading. But using those pair of ETFs (at least for the past 3 years) has done quite well. By the way, I'm not saying MOO is a good, broad-based barometer. I was just trying to show the relevance of switching between two ETFs based on their negative correlation. A lot of ETFs have negative correlation with the dollar (UUP). You showed that, for example, in your table of ETFs and their related correlations.

If you look back at my 3-year testing, you'll see that using the pair of ETFs (MOO and UUP), did quite well. It worked out to be about 21% a year return (annualized). I would take that. I would also take a 10% return in 2008 (looking back). How many investors lost 30% to 50% in 2008 ?!

"Investing Isn't Easy."

Gene



mahkoh
891 posts
msg #97904
Ignore mahkoh
modified
12/9/2010 2:30:22 PM

Kevin_in_GA
msg #97878
- Ignore Kevin_in_GA 12/7/2010 3:36:15 PM

Normally, pairs trading is defined as having a simultaneous long and short trade, usually with two stocks in the same market sector. Often they trade in a well defined range that for some reason has been moved from its usual equilibrium, and the long-short play predicts that each stock will revert to back to the mean.

Here's a quick example of what i mean. In this filter each of the standard sector ETFs for the S&P 500 is compared to its normal relationship with the SPY. If any of the ETFs trade more than 2 standard deviations from the 20 day average of the pair, it is a good trade for short-term mean reversion. One could simply go long the ETF with the lowest Z-score, and short the one with the highest Z-score, expecting both to revert to the mean.


Fetcher[

symlist(XLB,XLE,XLF,XLI,XLK,XLU,XLP,XLV,XLY,SPY)

draw MA(200)

/*FIRST DETERMINE HISTORICAL RATIO OF SECTOR ETF TO THE SPY*/
SET{PRICERATIO, CLOSE / IND(SPY,CLOSE)}
SET{RATIOMA, CMA(PRICERATIO,13)}
SET{RATIOSTD13, CSTDDEV(PRICERATIO,13)}
SET{DIFF13, PRICERATIO - RATIOMA}
SET{ZSCORE13, DIFF13 / RATIOSTD13}
SET{THRESHOLD, RATIOSTD13 * 2}

SET{tt, DIFF13 / RATIOMA}
set{ttt, -1 * tt}
SET{PROFIT_TARGET, ttt * 100}

/*NEXT, SET CRITERIA NECESSARY TO TRIGGER A PAIR TRADE*/
SET{UPPERBAND, RATIOMA + THRESHOLD}
SET{LOWERBAND, RATIOMA - THRESHOLD}
DRAW LOWERBAND ON PLOT PRICERATIO
DRAW UPPERBAND ON PLOT PRICERATIO

ADD COLUMN PRICERATIO
ADD COLUMN ZSCORE13
and add column corr(SPY,100,Close)
and add column corr(SPY,13,Close)

add column PROFIT_TARGET {reversion profit (%)}

DRAW ZSCORE13 LINE AT 2
DRAW ZSCORE13 LINE AT -2
DRAW ZSCORE13 LINE AT 0

SORT ON COLUMN 6 DESCENDING
CHART-TIME IS 3 MONTHS
]



Has anyone tried backtesting this filter/strategy?

Kevin_in_GA
4,542 posts
msg #97908
Ignore Kevin_in_GA
12/9/2010 4:21:07 PM

Not easy to do, since it requires being long and short on simultaneous trades. SF cannot do this type of backtesting.

StockFetcher Forums · Filter Exchange · Correlation search in SF (paired trading)<< >>Post Follow-up

*** Disclaimer *** StockFetcher.com does not endorse or suggest any of the securities which are returned in any of the searches or filters. They are provided purely for informational and research purposes. StockFetcher.com does not recommend particular securities. StockFetcher.com, Vestyl Software, L.L.C. and involved content providers shall not be liable for any errors or delays in the content, or for any actions taken based on the content.


Copyright 2016 - Vestyl Software L.L.C.Terms of Service | License | Questions or comments? Contact Us
EOD Data sources: DDFPlus & CSI Data Quotes delayed during active market hours. Delay times are at least 15 mins for NASDAQ, 20 mins for NYSE and Amex. Delayed intraday data provided by DDFPlus