So I´m wondering how I can calculate the average correlation among stocks whose correlations are between 20% (LB) and 70% (UB).
I'm supposed to use this VBA function AvgRhoBounded(Ret, LB, UB)
LB stands for Lower bound and UB stands for upper bound. Ret is the return data I already have. So far this is what I've done and I'm not sure if it right..
THE CODE:
Function AvgRhoBounded(RET, LB, UB)
' get number of assets
n = data.Columns.Count
' add up all returns
total_rho = 0
n_rho = 0
For i = 1 To n
For j = i + 1 To n
rho_ij = Application.WorksheetFunction.Correl(data.Columns(i), data.Columns(j))
total_rho = total_rho + rho_ij
n_rho = n_rho + 1
Next j
Next i
' return average correlations
AvgRho = total_rho / n_rho
'calculating the average correlation between stocks whose correlation are between 20% and 70%
Dim LB As String
Dim Lowerbound As String
Dim RET As String
Dim UB As String
Dim Upperbound As String
If LB = 20 Then
Lowerbound = 20
ElseIf UB = 70 Then
Upperbound = 70
End If
End Function