Sub CovMatrix()
'
' CovMatrix Macro
' Fixed, Relative References is not used
'
Range("B2").Select
ActiveCell.FormulaR1C1 = "Covariance Matrix given Prices"
'Prices
Range("B4").Select
ActiveCell.FormulaR1C1 = "1. Get the Prices"
Range("B6").Select
Sheets("Sheet1").Select
Range("K100").Select
ActiveWindow.SmallScroll Down:=-24
ActiveWindow.ScrollRow = 46
ActiveWindow.ScrollRow = 45
ActiveWindow.ScrollRow = 43
ActiveWindow.ScrollRow = 41
ActiveWindow.ScrollRow = 39
ActiveWindow.ScrollRow = 38
ActiveWindow.ScrollRow = 36
ActiveWindow.ScrollRow = 34
ActiveWindow.ScrollRow = 32
ActiveWindow.ScrollRow = 30
ActiveWindow.ScrollRow = 28
ActiveWindow.ScrollRow = 25
ActiveWindow.ScrollRow = 23
ActiveWindow.ScrollRow = 21
ActiveWindow.ScrollRow = 18
ActiveWindow.ScrollRow = 16
ActiveWindow.ScrollRow = 14
ActiveWindow.ScrollRow = 12
ActiveWindow.ScrollRow = 10
ActiveWindow.ScrollRow = 7
ActiveWindow.ScrollRow = 6
ActiveWindow.ScrollRow = 4
ActiveWindow.ScrollRow = 2
ActiveWindow.ScrollRow = 1
Range("B2").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Sheets("VBA").Select
ActiveSheet.Paste
Range("N4").Select
Application.CutCopyMode = False
'Returns
ActiveCell.FormulaR1C1 = "2. Change it into Returns"
Range("N7").Select
ActiveCell.FormulaR1C1 = "=RC[-12]/R[-1]C[-12]-1"
Range("N7").Select
Selection.Copy
Range("N8:W104").Select
ActiveSheet.Paste
Range("O7:W7").Select
ActiveSheet.Paste
Application.CutCopyMode = False
'Averages
Range("Y4").Select
ActiveCell.FormulaR1C1 = "3.Get the Averages"
Range("Y7").Select
ActiveCell.FormulaR1C1 = "=AVERAGE(RC[-11]:R[97]C[-11])"
Range("Y7").Select
Selection.Copy
Range("Z7:AH7").Select
ActiveSheet.Paste
Range("Y7:AH7").Select
Application.CutCopyMode = False
'Mean adjusted Return
Range("AJ4").Select
ActiveCell.FormulaR1C1 = "4.Mean Adjusted Returns"
Range("AJ7").Select
ActiveCell.FormulaR1C1 = "=RC[-22]-R7C[-11]"
Range("AJ7").Select
Selection.Copy
Range("AJ8:AJ104").Select
ActiveSheet.Paste
Range("AK7:AS104").Select
ActiveSheet.Paste
Range("AU5").Select
Application.CutCopyMode = False
'covariance Matrix
Range("AU4").Select
ActiveCell.FormulaR1C1 = "5. Get the Covariance matrix"
Range("AU7:BD16").Select
Selection.FormulaArray = _
"=MMULT(TRANSPOSE(RC[-11]:R[97]C[-2]),RC[-11]:R[97]C[-2])/(COUNT(RC[-11]:R[97]C[-11])-1)"
ActiveWindow.ScrollRow = 75
ActiveWindow.ScrollRow = 74
ActiveWindow.ScrollRow = 73
ActiveWindow.ScrollRow = 72
ActiveWindow.ScrollRow = 71
ActiveWindow.ScrollRow = 70
ActiveWindow.ScrollRow = 69
ActiveWindow.ScrollRow = 67
ActiveWindow.ScrollRow = 66
ActiveWindow.ScrollRow = 65
ActiveWindow.ScrollRow = 64
ActiveWindow.ScrollRow = 62
ActiveWindow.ScrollRow = 60
ActiveWindow.ScrollRow = 58
ActiveWindow.ScrollRow = 57
ActiveWindow.ScrollRow = 55
ActiveWindow.ScrollRow = 54
ActiveWindow.ScrollRow = 53
ActiveWindow.ScrollRow = 52
ActiveWindow.ScrollRow = 50
ActiveWindow.ScrollRow = 49
ActiveWindow.ScrollRow = 48
ActiveWindow.ScrollRow = 47
ActiveWindow.ScrollRow = 46
ActiveWindow.ScrollRow = 45
ActiveWindow.ScrollRow = 44
ActiveWindow.ScrollRow = 43
ActiveWindow.ScrollRow = 42
ActiveWindow.ScrollRow = 41
ActiveWindow.ScrollRow = 40
ActiveWindow.ScrollRow = 38
ActiveWindow.ScrollRow = 37
ActiveWindow.ScrollRow = 35
ActiveWindow.ScrollRow = 33
ActiveWindow.ScrollRow = 32
ActiveWindow.ScrollRow = 30
ActiveWindow.ScrollRow = 28
ActiveWindow.ScrollRow = 26
ActiveWindow.ScrollRow = 25
ActiveWindow.ScrollRow = 23
ActiveWindow.ScrollRow = 21
ActiveWindow.ScrollRow = 19
ActiveWindow.ScrollRow = 17
ActiveWindow.ScrollRow = 15
ActiveWindow.ScrollRow = 14
ActiveWindow.ScrollRow = 12
ActiveWindow.ScrollRow = 11
ActiveWindow.ScrollRow = 10
ActiveWindow.ScrollRow = 9
ActiveWindow.ScrollRow = 8
ActiveWindow.ScrollRow = 7
ActiveWindow.ScrollRow = 6
ActiveWindow.ScrollRow = 5
ActiveWindow.ScrollRow = 4
ActiveWindow.ScrollRow = 3
ActiveWindow.ScrollRow = 2
ActiveWindow.ScrollRow = 1
ActiveWindow.LargeScroll ToRight:=-1
ActiveWindow.ScrollColumn = 12
ActiveWindow.ScrollColumn = 14
ActiveWindow.ScrollColumn = 15
ActiveWindow.ScrollColumn = 16
ActiveWindow.ScrollColumn = 17
ActiveWindow.ScrollColumn = 18
ActiveWindow.ScrollColumn = 19
ActiveWindow.ScrollColumn = 20
ActiveWindow.ScrollColumn = 21
End Sub
Thinking of a dynamic way to program this Covariance. Somehow copy and paste seems to be the easier way. Though when reading the code by itself and applying it using relative references, it doesn't make sense. So I have to go back to arrays and matrices.
No comments:
Post a Comment