Skip to content

Instantly share code, notes, and snippets.

@yuyueugene84
Last active August 12, 2020 02:20
Show Gist options
  • Save yuyueugene84/96b37b8605d3ea6de09708ff14ef1b3e to your computer and use it in GitHub Desktop.
Save yuyueugene84/96b37b8605d3ea6de09708ff14ef1b3e to your computer and use it in GitHub Desktop.
Sub CalculateCorr4()
Dim corrSheet As Worksheet
Set corrSheet = Worksheets("相關性分析")
Dim portSheet As Worksheet
Set portSheet = Worksheets("投資組合報酬分析")
Dim corr As Double
Dim i As Integer
Dim j as Integer
For j = 2 To 13
For i = 2 To 13
corr = Application.WorksheetFunction.Correl( _
portSheet.Range( _
portSheet.Cells(2, j), _
portSheet.Cells(95, j) _
).Value, _
portSheet.Range( _
portSheet.Cells(2, i), _
portSheet.Cells(95, i) _
).Value _
)
Debug.Print corr
corrSheet.Cells(i, j).Value = corr
Next i
Next j
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment