Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. Sub testCov()
  2. Rng2 = Sheets("20 Asset Model").Range("b3:f48")
  3. Dim covMatrix() As Variant
  4. ReDim covMatrix(1 To Rng2.Columns.Count, 1 To Rng2.Columns.Count)
  5. Call constructCovMatrix(Rng2, covMatrix)
  6. MsgBox (covMatrix)
  7. End Sub
  8.  
  9. Sub constructCovMatrix(rng, ByRef covMatrix)
  10. '@rng The Range of the return series.
  11.  
  12. Dim i As Integer
  13. Dim j As Integer
  14. For i = 1 To rng.Columns.Count
  15. For j = 1 To rng.Columns.Count
  16. covMatrix(i, j) = Application.WorksheetFunction.Covar(rng.Columns(i), rng.Columns(j))
  17. Next
  18. Next
  19. End Sub
  20.  
  21. Sub testCov()
  22.  
  23. Dim Rng2 As Range '- Declare variable
  24. Set Rng2 = Sheets("20 Asset Model").Range("b3:f48") '-Set range
  25. Dim covMatrix() As Variant
  26. ReDim covMatrix(1 To Rng2.Columns.Count, 1 To Rng2.Columns.Count)
  27. Call constructCovMatrix(Rng2, covMatrix)
  28. MsgBox (covMatrix)
  29.  
  30. Set Rng2 = Nothing '- Cleanup anytime 'Set' is used
  31. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement