Hello all,
I recorded a macro that correlates a price series against an ascending sequence of numbers. The key steps are:
1) populate the adjacent column with ascending numbers i.e. 1,2,3,4,5...
2) Use the correl function to find the correlation between the price and the ascending numbers. A rolling interval of 5 rows was used in this case.
3) Use the data analysis toolpak to plot a histogram showing the % frequency of each bin in the correlation range of -1 to +1.
Unfortunately this macro will not work on any price series that has fewer rows than the original one. I probably need a sort of loop function that continues the process until the price data runs out. Could anyone please provide some guidance on how to implement this loop?
I recorded a macro that correlates a price series against an ascending sequence of numbers. The key steps are:
1) populate the adjacent column with ascending numbers i.e. 1,2,3,4,5...
2) Use the correl function to find the correlation between the price and the ascending numbers. A rolling interval of 5 rows was used in this case.
3) Use the data analysis toolpak to plot a histogram showing the % frequency of each bin in the correlation range of -1 to +1.
Unfortunately this macro will not work on any price series that has fewer rows than the original one. I probably need a sort of loop function that continues the process until the price data runs out. Could anyone please provide some guidance on how to implement this loop?
Code:
Sub correlation()'
' correlation Macro
'
'
ActiveCell.FormulaR1C1 = "1"
Range("C3").Select
ActiveCell.FormulaR1C1 = "2"
Range("C4").Select
ActiveCell.FormulaR1C1 = "3"
Range("C2:C4").Select
Selection.AutoFill Destination:=Range("C2:C101"), Type:=xlFillDefault
Range("C2:C101").Select
ActiveWindow.SmallScroll Down:=-87
Range("D6").Select
ActiveCell.FormulaR1C1 = "=CORREL(R[-4]C[-2]:RC[-2],R[-4]C[-1]:RC[-1])"
Range("D6").Select
Selection.AutoFill Destination:=Range("D6:D101"), Type:=xlFillDefault
Range("D6:D101").Select
ActiveWindow.SmallScroll Down:=-102
Range("F2").Select
ActiveCell.FormulaR1C1 = "-1"
Range("F3").Select
ActiveCell.FormulaR1C1 = "-0.95"
Range("F4").Select
ActiveCell.FormulaR1C1 = "-0.9"
Range("F2:F4").Select
Selection.AutoFill Destination:=Range("F2:F43"), Type:=xlFillDefault
Range("F2:F43").Select
ActiveWindow.SmallScroll Down:=-57
Range("H2").Select
Application.Run "ATPVBAEN.XLAM!Histogram", ActiveSheet.Range("$D$6:$D$101") _
, ActiveSheet.Range("$H$2"), ActiveSheet.Range("$F$2:$F$43"), False, False _
, True, False
ActiveSheet.Shapes(1).ScaleWidth 2.6614583333, msoFalse, _
msoScaleFromTopLeft
ActiveSheet.Shapes(1).ScaleHeight 2.705, msoFalse, msoScaleFromTopLeft
Range("I3").Select
ActiveWindow.SmallScroll Down:=21
Range("H45").Select
Selection.ClearContents
Range("I45").Select
Selection.ClearContents
Range("I46").Select
ActiveCell.FormulaR1C1 = "=SUM(R[-43]C:R[-2]C)"
Range("I47").Select
ActiveWindow.SmallScroll Down:=-39
Range("J3").Select
ActiveCell.FormulaR1C1 = "=RC[-1]/R46C9*100"
Range("J3").Select
Selection.AutoFill Destination:=Range("J3:J44"), Type:=xlFillDefault
Range("J3:J44").Select
ActiveWindow.SmallScroll Down:=-30
ActiveSheet.ChartObjects(1).Activate
ActiveChart.PlotArea.Select
Application.CutCopyMode = False
Application.CutCopyMode = False
ActiveChart.FullSeriesCollection(1).Values = "=Sheet1!$J$3:$J$44"
ActiveChart.Axes(xlCategory).Select
ActiveChart.Axes(xlCategory).AxisBetweenCategories = False
Application.CommandBars("Format Object").Visible = False
Range("Q38").Select
ActiveWindow.SmallScroll Down:=-6
Range("L32").Select
ActiveCell.FormulaR1C1 = "0.7"
Range("L33").Select
ActiveCell.FormulaR1C1 = "-0.7"
Range("L32:M33").Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 65535
.TintAndShade = 0
.PatternTintAndShade = 0
End With
Selection.Font.Bold = True
Range("M32").Select
ActiveWindow.SmallScroll Down:=-9
ActiveCell.FormulaR1C1 = "=SUM(R[-28]C[-3]:R[-23]C[-3])"
Range("M33").Select
ActiveWindow.SmallScroll Down:=12
ActiveCell.FormulaR1C1 = "=SUM(R[5]C[-3]:R[10]C[-3])"
Range("M34").Select
ActiveWindow.SmallScroll Down:=-51
End Sub