WL code to find highest correlated period in underlying security to recent history
Author: Shourui
Creation Date: 11/11/2010 1:42 AM
profile picture

Shourui

#1
any help will be appreciated.
profile picture

Eugene

#2
profile picture

Shourui

#3
I tried to use the Correlation Inidicator, but the problem is the Correlation indicator doesn't have a Correlation.Value() function, it can only get DataSeries (Correlation.Series). Is there any practical or easy way to check the rolling correlation of Securiters to its own historical data within a For Loop?
profile picture

Sammy_G

#4
Calculate the correlation series and get its value at a bar like you would do for any other series inside the bar loop e.g. CorrelationSeries[bar].

Post back if you have any more questions.
profile picture

Shourui

#5
Here is the code. It was fine when checking 10-year SPX, but I got "System.outofMemoeryExpection" when it was running on the whole history of SPX since 1928. I got 4G RAM and the highest level memory usage was 70% when the strategy was running. Thanks for any help.

CODE:
Please log in to see this code.
profile picture

Eugene

#6
Re: 4Gb RAM - do you have a 64-bit CPU? a 64-bit operating system? with 64-bit WLP6 running?
profile picture

Sammy_G

#7
Shourui,

Not sure what you are trying to do in that code. But one thing's evident - you are calculating series inside the bar loop which probably accounts for your memory issues.

If I understand your code correctly, you are trying to correlate the price to 1-year ago price. The following code will do the same, and plot all series so you get a good grasp of everything:
CODE:
Please log in to see this code.


Lastly, search for correlation and auto-correlation (which is what you seem to be doing) in the WL4 forums; there's a ton of wisdom there.
profile picture

Shourui

#8
Eugene.
No. Everything is 32-bit in my coputer.

Sammy_G,
What I really want to do is finding the highest correlated periods in the history to the most recent Data (such as Last 6 Months/12 months). For example, 2/2/1955 to 8/3/1955 is the highest correlated period to the recent 6 months (5/12/2010 - 11/12/2010).
Your code is calcualting correlation to 12 months ago at any historical data point, which is different than what I need.
To make it simple and straightfoward, Can you help me plot the correlation of recent 12 month data to any historical 12-month data on SPX Index? I hope my explanation is clear this time. Thanks.

profile picture

Eugene

#9
Just a general advice: consider upgrading to everything 64-bit if you're into any high memory consumption stuff. 4Gb in a 32-bit and 64-bit system aren't quite the same thing.
profile picture

Sammy_G

#10
I think I understand now what you are trying to do - namely, what historical time period was most similar to current period in terms of price action, right?
profile picture

Sammy_G

#11
Shourui,

If you want to move forward with this thread, I would like you to answer my previous question; if the answer to that is yes, I have a solution.

Because I really don't know what you meant by "...plot the correlation of recent 12 month data to any historical 12-month data on SPX Index".