TradersEdgeSystems.com

Consulting | Custom Trading Systems
Built-In Indicators | Custom Indicators

April 2015 Stocks and Commodities Traders Tips


Basket Trading Using a Directed Acyclic Graph

AIQ Version:

Original article by Dave Cline
AIQ Code by Richard Denning

The code provided will compute the Pearson correlation or “r” between two pairs of stocks for up to 20 stocks at a time. The EDS reports can be exported to Excel for further analysis. I used the AIQ Matchmaker module which uses Spearman Rank correlation to find highly correlated stocks from within the NASDAQ 100. I then created a list of these 20 symbols and set the EDS file to run only on this list. I then typed in the list in the same alphabetic order as they are in the list. I then set the report date to 1/6/2014 which is about one year prior to when I was writing this for the Traders Tips. The correlations are set to look back 250 days based on the input “Len”. Once we have decided how we will trade the basket created by the correlation analysis, we would forward test using data not used to correlate the stocks or from 1/7/2014 to 1/8/2015.

Figure 1 shows a portion of the resulting report. The cells with a 1.00 value are the result of correlating the stock with itself. Since the column headings use a variable name, the cells with the 1.00 value identify the stock in that column. This matrix can be used to create the correlated baskets described by the author. I also created a report for Pearson’s “r” squared but this is not used by the author in the article.

Captions:
Figure 1 –A portion of the correlation matrix report that is created from the EDS code for 20 of the NASDAQ 100 stock..

EDS Code:
Pearsons R Multi100.EDS
(right click and choose Save As)


 

Traders Studio Version :

Original article by Dave Cline
Traders Studio Code by Richard Denning

The following code files are contained in the download from the websites:

  • System: BASKET - a long only system that uses daily data and buys all stocks that are set up in the session data list. There are no exits as this is used solely for getting the complete set of correlation values for each pair.

The purpose of the very simple code provided is to get the Eq Correlation report to run on the entire period based on the start/end dates input in the session back test for the entire list of stocks in the session. Note that the correlation report is based on a proprietary correlation formula that is similar to Pearson’s “r”.

Figure 1 shows a portion of the EQ Correlation report that I ran on the NASDAQ 100 stocks for the period from 1/6/2013 to 1/6/2014. The cells with a “1” value are the result of correlating the stock with itself. Since the column headings use a variable name, the cells with the “1” value identify the stock in that column. This matrix can be used to create the correlated baskets described by the author. The report can be saved to an Excel file for further analysis of the pairs.

Captions:
Figure 1 – A portion of the EQ Correlation report that I ran on the NASDAQ 100 stocks for the period from 1/6/2013 to 1/6/2014.

Traders Studio Code:
BASKET_TSZ.zip
(right click and choose Save As)

 

 

 

 

 

 

 

 

 

 

 

 

 

Disclaimer | Privacy Policy | Contact Us | Spam Blocker | ©2013 Traders Edge Systems