Based on a historical stock prices table I need to calculate the correlation matrix for a define date range:
Sheets("Raw data"):
A B C D
Date stock1 stock2 stock 3
02/01/2012 0.934752772 0.991533951 0.698445112
03/01/2012 0.519385963 0.878316925 0.924111967
04/01/2012 0.285286565 0.35351676 0.79461415
05/01/2012 0.632288941 0.88841507 0.329613832
Sheets("Raw data").Select
Dim rng_input As Range
Set rng_input = Range([B1], [B1].End(xlDown).End(xlToRight))
Sheets("CorrMatrix").Select
Application.Run "ATPVBAEN.XLAM!Mcorrel", rng_input, _
ActiveSheet.Range("$A$10"), "C", True
the above code worked well but not sure how to properly adjust the range to be between 2 dates.
For example how do you generate correlation matrix based on the red data between 03/01/12 - 04/01/12?
i tried to find out the start and end date row numbers as well as the end column:
r1 = Application.Match(Sheets("CorrMatrix").Range("A2"), Sheets("Raw data").Range("A:A"), 0)
r2 = Application.Match(Sheets("CorrMatrix").Range("A3"), Sheets("Raw data").Range("A:A"), 0)
Dim rLastCell As Range
Set rLastCell = Cells.Find(What:="*", After:=Cells(1, 1), LookIn:=xlFormulas, LookAt:= _
xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlPrevious, MatchCase:=False)
LastCol = rLastCell.Column
Sheets("Raw data").Select
Set rng_input =ActiveSheet.Range(Cells(r1, 2), Cells(r2, LastCol))
then Application.Run "ATPVBAEN.XLAM!Mcorrel", rng_input, _
ActiveSheet.Range("$A$10"), "C", True
but not working...
Can anyone please kindly help out? thank you!
Bookmarks