#VALUE! being returned from a UDF usually means there's an error in the function's code.
Try putting a breakpoint on the first line of the code with F9, then enter a formula using the function in a cell.
VBA should then allow you to step through the code to see what's happening.
Unfortunately if there is an error you won't get an error message, the code will just stop.
Actually I've just tried that and I don't even get to debug which kind of indicates the problem is the function header where you've used Double instead of Variant.
When I change the first 2 arguments back to variant the code works fine, it also works fine when I use Range and adjust the code a little.
Function myLogCAPM(index As Range, stock As Range, rf As Double, Rm As Double) As Double
Dim var As Double
Dim covar As Double
Dim beta As Double
Dim indexLog() As Double
Dim stockLog() As Double
Dim n As Byte
Dim i As Byte
n = index.Rows.Count
n = n - 1
ReDim indexLog(n) As Double
ReDim stockLog(n) As Double
For i = 1 To n
indexLog(i) = Log(index.Cells(i, 1) / index.Cells(i + 1, 1))
stockLog(i) = Log(stock.Cells(i, 1) / stock.Cells(i + 1, 1))
Next i
var = WorksheetFunction.var(indexLog)
covar = WorksheetFunction.covar(indexLog, stockLog)
beta = covar / var
myLogCAPM = rf + beta * (Rm - rf)
End Function
PS You can't print out entire arrays with Debug.Print.
Bookmarks