Forum Discussion
Jensen's Alpha
I'm trying to run a Jensen's Regression and my code is not working. The debugger says my offcol = UBound(result, 1) is a type mismatch. Below is the code I have wrote. Any help would be great.
Sub regCAPM(xrange, yrange) 'jensen regression
Dim result
Dim pval As Single, tstat As Single, alpha As Single
Dim offcol As Integer, offst As Integer
result = Application.LinEst(Range(yrange).Value, Range(xrange).Value, 1, 1)
offcol = UBound(result, 2) 'why???????????
If offcol = 2 Then
offst = 0
ElseIf offcol = 4 Then
offst = 1
Else
offst = 2
End If
tstat = Abs(result(1, offcol) / result(2, offcol))
pval = Application.WorksheetFunction.T_Dist_2T(tstat, result(4, 2))
alpha = result(1, offcol)
Range("'effport'!q18").offset(0, offst).Value = alpha
Range("'effport'!q18").offset(1, offst).Value = pval
End Sub
Sub demosortino()
Dim lrow As Integer, frow As Integer
Dim avgret As Single, lpstdev As Single, sortino As Single, rf
Worksheets("effport").Activate
avgret = Range("'effport'!J17").Value
frow = 2
lrow = 169
lpstdev = lpsd(frow, lrow, avgret)
rf = Range("'effport'!b14").Value
'wont work?????
sortino = (avgret - rf) / lpstdev
Range("'effport'!j21").Value = sortino
End Sub
1 Reply
- Matt MickleBronze Contributor
Hey Trevor, hope you're doing well. Typically a type mismatch error occurs when you try to assign a variable a value that is not consistent with the declaration. Can you add a line to tell you what the value of result is? It would be beneficial to have a small non-sensitive mockup to help test the code if possible.
result = Application.LinEst(Range(yrange).Value, Range(xrange).Value, 1, 1)
msgBox result
What does the msgbox return?