StockFetcher Forums · Filter Exchange · pairs trading filter<< 1 2 >>Post Follow-up
joda
4 posts
msg #93643
Ignore joda
6/8/2010 2:25:10 PM

does anyone have a filter for trading pairs?

I'd like to run a backtest on SF of trading pairs

parameters: correlation between the 2 stocks >85%; long if the pair spread reaches 2 standard deviations of mean..
close position when standard dev returns to < 1

a cool filter for that could benefit us all

thx

Kevin_in_GA
4,553 posts
msg #93646
Ignore Kevin_in_GA
6/8/2010 4:28:56 PM

Unfortunately, SF does not have a function that allows for the correlation of any two stocks or indices. It has an "R-Squared" function, but all it does is determine how linear a stocks recent movement has been.

I would suggest going to www.assetcorrelation.com to get the correlation for the stocks under consideration.

Alternatively, you can get software that will do this (e.g., pairtradefinder.com).

The other approach is to look at the ratio of the two stocks and see when it moves outside of its "normal" range:

Here is a filter I wrote a while back to do this using the sector ETFs versus SPY:

Fetcher[

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

/*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{UPPERBAND, RATIOMA + THRESHOLD}
SET{LOWERBAND, RATIOMA - THRESHOLD}
DRAW LOWERBAND ON PLOT PRICERATIO
DRAW UPPERBAND ON PLOT PRICERATIO

ADD COLUMN PRICERATIO
ADD COLUMN ZSCORE13

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

]



Note that I used a 13 day moving average here, but it can be set for whatever timeframe you prefer. The shorter timeframe is better suited for mean reversion.

Using this approach, one would short XLU and go long XLI (based on close data for today). You can also look at the zscore graph at the bottom to see how other trades might have played out.

Kevin

Kevin_in_GA
4,553 posts
msg #93763
Ignore Kevin_in_GA
6/12/2010 5:25:01 PM

Not sure if anyone looked at this. As of the close Friday had you gone long on XLI and shorted XLU at the close on 6/8 as suggested, you would have lost 2% on the short trade but gained 4.2% on the long trade. A net gain of 1% in three days on a hedged pair trade - not too bad.

Kevin_in_GA
4,553 posts
msg #93886
Ignore Kevin_in_GA
6/15/2010 7:36:22 PM

Another update - Long XLI would have netted you 7.25% in five days. Shorting XLU would have cost you 4.54%.

Net on this pair trade = (7.25 - 4.54)/2 or 1.35%. Not a lot, given that the SPY has gained 5% over the same period. However, the annualized volatility for this pair trade was only 6.6% versus 24.2% for the SPY.


joda
4 posts
msg #94083
Ignore joda
6/20/2010 10:03:03 AM

thx for your input,Kevin!

interesting. is pairtradefinder worth the 500bucks? do they have a decent backtest function of a pairtrading portfolio?

I'd like to seriously backtest pairstrading for the last 10 years before I get into trading it for real

thx
J

Kevin_in_GA
4,553 posts
msg #94085
Ignore Kevin_in_GA
6/20/2010 11:29:02 AM

I think they let you try it out for 30 days first, and they offered it at 199 after I downloaded the software.

No harm in trying it out.

Kevin_in_GA
4,553 posts
msg #94154
Ignore Kevin_in_GA
6/22/2010 9:48:32 AM

Based on this filter, one would go long XLY and short XLE today at the open.

Let's see how it plays out over the next few days:

XLE short at the open price of $55.45

XLY long at the open price of $32.21

Kevin

joda
4 posts
msg #94171
Ignore joda
6/22/2010 2:08:48 PM

yes indeed , I saw that!

Kevin, I like your filter and my gut feeling/experience tells me that this should consistently be profitable year-on-year, but how about backtested results? did you manage to backtest your strategy over a couple of years on any platform/excel?

J

Kevin_in_GA
4,553 posts
msg #94175
Ignore Kevin_in_GA
6/22/2010 3:22:19 PM

This is not easily backtested - you need to take the highest and lowest zscore ETF and pit them against each other. SF does not really let you do long/short combos in their backtesting.

Also, you need to determine what your specific exit criteria is, and it should be the same exit time for both trades, even if only one is signaled. Not easy to do with the tools on hand.

At 3:20 PM the long XLY/short XLE trade looks like this:

Short XLE - open at 55.45, now at 54.01(a gain of 2.7%)

Long XLY - open at 32.22, now at 31.68, for a loss of 1.7%

Net so far today = (2.7 - 1.7) / 2 = +0.5 % while the S&P is down 1% so far today.

Kevin_in_GA
4,553 posts
msg #94179
Ignore Kevin_in_GA
6/22/2010 4:05:18 PM

I would be out of XLE at end of today - it has gone from a zscore of 1.13 this morning to -0.3 right now. Good reason to end the trade:

1. cover XLE short at 53.87 (a gain of 2.9%).
2. hold XLY at 31.48 (still the lowest ranked by zscore at -2.00, a loss of 2.3% on the day).
3. short new top zscore (XLF at +2.00) - initiate new short position at 14.57.


Net gain for the day of +0.3% with new position taken for tomorrow.

For comparison, the S&P 500 was down 1.6% today.

StockFetcher Forums · Filter Exchange · pairs trading filter<< 1 2 >>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