teatimecrumpet
Active Member
- Joined
- Jun 23, 2010
- Messages
- 307
Hi,
I'm trying to build out a function that looks at two lists of numbers.
the two columns are numbers like prices. It then would go through and take the returns of one column taking a step at a time. If it is positive then I wanted to take the geomean of just those positive returns...but to avoid negative returns that would mess up the geometric mean it adds 1.
The below is what I have so far. I was trying to take the geometric mean in a roundabout way. But I can't get it working. For sums I usually use the red highlighted when I want to keep adding each step. But for multiplying it fails...because I think the first number starts as zero.
any help is appreciated!
I'm trying to build out a function that looks at two lists of numbers.
the two columns are numbers like prices. It then would go through and take the returns of one column taking a step at a time. If it is positive then I wanted to take the geomean of just those positive returns...but to avoid negative returns that would mess up the geometric mean it adds 1.
The below is what I have so far. I was trying to take the geometric mean in a roundabout way. But I can't get it working. For sums I usually use the red highlighted when I want to keep adding each step. But for multiplying it fails...because I think the first number starts as zero.
any help is appreciated!
Function geotest(r As Range, q As Range) As Double
Application.Volatile
Dim LR() As Double
RWS = r.Rows.Count
ReDim LJ(1 To (RWS - 1)) As Double
ReDim LR(1 To (RWS - 1)) As Double
For j = 2 To RWS And observ = 0
LJ(j - 1) = (r.Cells(j, 1).Value) / (r.Cells(j - 1, 1).Value) - 1
LR(j - 1) = (q.Cells(j, 1).Value) / (q.Cells(j - 1, 1).Value) - 1
If LJ(j - 1) > 0 _
Then bench = bench * (LJ(j - 1) + 1)
If LJ(j - 1) > 0 _
Then fund = fund * (LR(j - 1) + 1)
If LJ(j - 1) > 0 _
Then observ = observ + 1
Next j
benchgeo = bench ^ (1 / observ) - 1
fundgeo = fund ^ (1 / observ) - 1
geotest = fundgeo / benchgeo
End Function
Last edited: